Add new API call to remove users

This commit is contained in:
Frederic Guillot 2017-01-02 17:40:53 -05:00
parent bac841aa78
commit 83608c050a
3 changed files with 50 additions and 0 deletions

View File

@ -132,6 +132,36 @@ Response example:
}
```
### removeUser
- Purpose: **Remove a user** (accessible only by administrators)
- Parameters:
- **user_id** (integer)
- Result on success: **true**
- Result on failure: **false**
Request example:
```json
{
"jsonrpc": "2.0",
"method": "removeUser",
"id": 2109613284,
"params": [
3
]
}
```
Response example:
```json
{
"jsonrpc": "2.0",
"result": true,
"id": 2109613284
}
```
### getUserByUsername

View File

@ -63,6 +63,15 @@ $procedureHandler->withCallback('getUserByUsername', function ($username) {
return Model\User\get_user_by_username($username);
});
// Remove user
$procedureHandler->withCallback('removeUser', function ($user_id) {
if (! SessionStorage::getInstance()->isAdmin()) {
throw new AccessDeniedException('Reserved to administrators');
}
return Model\User\remove_user($user_id);
});
// Get all feeds
$procedureHandler->withCallback('getFeeds', function () {
$user_id = SessionStorage::getInstance()->getUserId();

View File

@ -45,6 +45,17 @@ class ApiTest extends BaseApiTest
$this->getApiClient($user)->getUserByUsername('admin');
}
public function testRemoveUser()
{
$userId = $this->getApiClient()->createUser(array(
'username' => 'api_test2',
'password' => 'test123',
));
$this->assertNotFalse($userId);
$this->assertTrue($this->getApiClient()->removeUser($userId));
}
public function testCreateFeed()
{
$this->assertNotFalse($this->getApiClient()->createFeed(array(