use proper return codes and handle failure cases

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2016-10-11 12:07:20 +02:00
parent 2507e7459d
commit 485d6d6577
No known key found for this signature in database
GPG key ID: 9CE5ED29E7FCD38A
3 changed files with 21 additions and 7 deletions

View file

@ -567,7 +567,8 @@ class UsersController extends Controller {
'data' => array( 'data' => array(
'message' => (string)$this->l10n->t('Error while disabling user.') 'message' => (string)$this->l10n->t('Error while disabling user.')
) )
) ),
Http::STATUS_FORBIDDEN
); );
} }
} }
@ -624,7 +625,8 @@ class UsersController extends Controller {
'data' => array( 'data' => array(
'message' => (string)$this->l10n->t('Error while enabling user.') 'message' => (string)$this->l10n->t('Error while enabling user.')
) )
) ),
Http::STATUS_FORBIDDEN
); );
} }
} }

View file

@ -949,7 +949,15 @@ $(document).ready(function () {
OC.dialogs.alert(result.data.message, t('settings', 'Error while changing status of {user}', {user: uid})); OC.dialogs.alert(result.data.message, t('settings', 'Error while changing status of {user}', {user: uid}));
} }
} }
); ).fail(function(result){
var message = 'Unknown error';
if( result.responseJSON &&
result.responseJSON.data &&
result.responseJSON.data.message) {
message = result.responseJSON.data.message;
}
OC.dialogs.alert(message, t('settings', 'Error while changing status of {user}', {user: uid}));
});
}); });
// init the quota field select box after it is shown the first time // init the quota field select box after it is shown the first time

View file

@ -2532,7 +2532,8 @@ class UsersControllerTest extends \Test\TestCase {
'data' => [ 'data' => [
'message' => 'Error while disabling user.', 'message' => 'Error while disabling user.',
], ],
] ],
Http::STATUS_FORBIDDEN
); );
$response = $this->getController(true)->disable('abc'); $response = $this->getController(true)->disable('abc');
$this->assertEquals($expectedResponse, $response); $this->assertEquals($expectedResponse, $response);
@ -2569,7 +2570,8 @@ class UsersControllerTest extends \Test\TestCase {
'data' => [ 'data' => [
'message' => 'Error while disabling user.', 'message' => 'Error while disabling user.',
], ],
] ],
Http::STATUS_FORBIDDEN
); );
$response = $this->getController(false)->disable('abc'); $response = $this->getController(false)->disable('abc');
$this->assertEquals($expectedResponse, $response); $this->assertEquals($expectedResponse, $response);
@ -2746,7 +2748,8 @@ class UsersControllerTest extends \Test\TestCase {
'data' => [ 'data' => [
'message' => 'Error while enabling user.', 'message' => 'Error while enabling user.',
], ],
] ],
Http::STATUS_FORBIDDEN
); );
$response = $this->getController(true)->enable('abc'); $response = $this->getController(true)->enable('abc');
$this->assertEquals($expectedResponse, $response); $this->assertEquals($expectedResponse, $response);
@ -2783,7 +2786,8 @@ class UsersControllerTest extends \Test\TestCase {
'data' => [ 'data' => [
'message' => 'Error while enabling user.', 'message' => 'Error while enabling user.',
], ],
] ],
Http::STATUS_FORBIDDEN
); );
$response = $this->getController(false)->enable('abc'); $response = $this->getController(false)->enable('abc');
$this->assertEquals($expectedResponse, $response); $this->assertEquals($expectedResponse, $response);