Skip to content

Commit 9decacd

Browse files
author
Phil Sturgeon
committed
Converted to new $this->methods = array('foo_get' => array('limit' = X) instead of $this->rest_permissions = array('foo_get' => X);
1 parent 5da2df3 commit 9decacd

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

application/controllers/api/keys.php

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
class Keys extends REST_Controller
1919
{
20-
protected $rest_permissions = array(
21-
'index_put' => 10,
22-
'index_delete' => 10,
23-
'level_post' => 10,
24-
'regenerate_post' => 10,
20+
protected $methods = array(
21+
'index_put' => array('level' => 10),
22+
'index_delete' => array('level' => 10),
23+
'level_post' => array('level' => 10),
24+
'regenerate_post' => array('level' => 10),
2525
);
2626

2727
/**
@@ -94,7 +94,7 @@ public function level_post()
9494
{
9595
$key = $this->post('key');
9696
$new_level = $this->post('level');
97-
97+
9898
// Does this key even exist?
9999
if ( ! self::_key_exists($key))
100100
{
@@ -105,7 +105,7 @@ public function level_post()
105105
// Update the key level
106106
if (self::_update_key($key, array('level' => $new_level)))
107107
{
108-
$this->response(array('status' => 1, 'success' => 'Key was updated.'), 200); // 201 = Created
108+
$this->response(array('status' => 1, 'success' => 'Key was updated.'), 200); // 200 = OK
109109
}
110110

111111
else
@@ -116,6 +116,39 @@ public function level_post()
116116

117117
// --------------------------------------------------------------------
118118

119+
/**
120+
* Update Key
121+
*
122+
* Change the level
123+
*
124+
* @access public
125+
* @return void
126+
*/
127+
public function suspend_post()
128+
{
129+
$key = $this->post('key');
130+
131+
// Does this key even exist?
132+
if ( ! self::_key_exists($key))
133+
{
134+
// NOOOOOOOOO!
135+
$this->response(array('error' => 'Invalid API Key.'), 400);
136+
}
137+
138+
// Update the key level
139+
if (self::_update_key($key, array('level' => 0)))
140+
{
141+
$this->response(array('status' => 1, 'success' => 'Key was suspended.'), 200); // 200 = OK
142+
}
143+
144+
else
145+
{
146+
$this->response(array('status' => 0, 'error' => 'Could not suspend the user.'), 500); // 500 = Internal Server Error
147+
}
148+
}
149+
150+
// --------------------------------------------------------------------
151+
119152
/**
120153
* Regenerate Key
121154
*

application/libraries/REST_Controller.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
class REST_Controller extends Controller
44
{
55
protected $rest_format = NULL; // Set this in a controller to use a default format
6-
protected $rest_permissions = NULL; // Set this in a controller to use a default format
6+
7+
protected $methods = array(); // contains a list of method properties such as limit, log and level
78

89
protected $request = NULL; // Stores accept, language, body, headers, etc
910
protected $rest = NULL; // Stores DB, keys, key level, etc
@@ -117,7 +118,7 @@ function _remap($object_called)
117118
}
118119

119120
// Their key might not be shit, but is it good enough?
120-
$authorized = ! (isset($this->rest_permissions[$controller_method]) AND $this->rest_permissions[$controller_method] > $this->rest->level);
121+
$authorized = ! (isset($this->methods[$controller_method]['level']) AND $this->methods[$controller_method]['level'] > $this->rest->level);
121122

122123
// IM TELLIN!
123124
if (config_item('rest_enable_logging'))

0 commit comments

Comments
 (0)