React on other statuscodes than 200

This commit is contained in:
Lukas Reschke 2014-12-08 16:35:13 +01:00
parent 5f43809ace
commit c23957811d
6 changed files with 54 additions and 89 deletions

View File

@ -82,10 +82,7 @@ class GroupsController extends Controller {
if($this->groupManager->groupExists($id)) { if($this->groupManager->groupExists($id)) {
return new DataResponse( return new DataResponse(
array( array(
'status' => 'error', 'message' => (string)$this->l10n->t('Group already exists.')
'data' => array(
'message' => (string)$this->l10n->t('Group already exists.')
)
), ),
Http::STATUS_CONFLICT Http::STATUS_CONFLICT
); );
@ -93,10 +90,7 @@ class GroupsController extends Controller {
if($this->groupManager->createGroup($id)) { if($this->groupManager->createGroup($id)) {
return new DataResponse( return new DataResponse(
array( array(
'status' => 'success', 'groupname' => $id
'data' => array(
'groupname' => $id
)
), ),
Http::STATUS_CREATED Http::STATUS_CREATED
); );

View File

@ -161,10 +161,7 @@ class UsersController extends Controller {
} catch (\Exception $exception) { } catch (\Exception $exception) {
return new DataResponse( return new DataResponse(
array( array(
'status' => 'error', 'message' => (string)$this->l10n->t('Unable to create user.')
'data' => array(
'message' => (string)$this->l10n->t('Unable to create user.')
)
), ),
Http::STATUS_FORBIDDEN Http::STATUS_FORBIDDEN
); );
@ -183,12 +180,9 @@ class UsersController extends Controller {
return new DataResponse( return new DataResponse(
array( array(
'status' => 'success', 'username' => $username,
'data' => array( 'groups' => $this->groupManager->getUserGroupIds($user),
'username' => $username, 'storageLocation' => $user->getHome()
'groups' => $this->groupManager->getUserGroupIds($user),
'storageLocation' => $user->getHome()
)
), ),
Http::STATUS_CREATED Http::STATUS_CREATED
); );

View File

@ -89,24 +89,19 @@ GroupList = {
id: groupname id: groupname
}, },
function (result) { function (result) {
if (result.status !== 'success') { if (result.groupname) {
OC.dialogs.alert(result.data.message, var addedGroup = result.groupname;
t('settings', 'Error creating group')); UserList.availableGroups = $.unique($.merge(UserList.availableGroups, [addedGroup]));
} GroupList.addGroup(result.groupname);
else {
if (result.data.groupname) {
var addedGroup = result.data.groupname;
UserList.availableGroups = $.unique($.merge(UserList.availableGroups, [addedGroup]));
GroupList.addGroup(result.data.groupname);
$('.groupsselect, .subadminsselect') $('.groupsselect, .subadminsselect')
.append($('<option>', { value: result.data.groupname }) .append($('<option>', { value: result.groupname })
.text(result.data.groupname)); .text(result.groupname));
}
GroupList.toggleAddGroup();
} }
} GroupList.toggleAddGroup();
); }).fail(function(result, textStatus, errorThrown) {
OC.dialogs.alert(result.responseJSON.message, t('settings', 'Error creating group'));
});
}, },
update: function () { update: function () {

View File

@ -674,42 +674,37 @@ $(document).ready(function () {
groups: groups groups: groups
}, },
function (result) { function (result) {
if (result.status !== 'success') { if (result.groups) {
OC.dialogs.alert(result.data.message, for (var i in result.groups) {
t('settings', 'Error creating user')); var gid = result.groups[i];
} else { if(UserList.availableGroups.indexOf(gid) === -1) {
if (result.data.groups) { UserList.availableGroups.push(gid);
var addedGroups = result.data.groups;
for (var i in result.data.groups) {
var gid = result.data.groups[i];
if(UserList.availableGroups.indexOf(gid) === -1) {
UserList.availableGroups.push(gid);
}
$li = GroupList.getGroupLI(gid);
userCount = GroupList.getUserCount($li);
GroupList.setUserCount($li, userCount + 1);
} }
$li = GroupList.getGroupLI(gid);
userCount = GroupList.getUserCount($li);
GroupList.setUserCount($li, userCount + 1);
} }
if (result.data.homeExists){
OC.Notification.hide();
OC.Notification.show(t('settings', 'Warning: Home directory for user "{user}" already exists', {user: result.data.username}));
if (UserList.notificationTimeout){
window.clearTimeout(UserList.notificationTimeout);
}
UserList.notificationTimeout = window.setTimeout(
function(){
OC.Notification.hide();
UserList.notificationTimeout = null;
}, 10000);
}
if(!UserList.has(username)) {
UserList.add(username, username, result.data.groups, null, 'default', result.data.storageLocation, 0, true);
}
$('#newusername').focus();
GroupList.incEveryoneCount();
} }
} if (result.homeExists){
); OC.Notification.hide();
OC.Notification.show(t('settings', 'Warning: Home directory for user "{user}" already exists', {user: result.username}));
if (UserList.notificationTimeout){
window.clearTimeout(UserList.notificationTimeout);
}
UserList.notificationTimeout = window.setTimeout(
function(){
OC.Notification.hide();
UserList.notificationTimeout = null;
}, 10000);
}
if(!UserList.has(username)) {
UserList.add(username, username, result.groups, null, 'default', result.storageLocation, 0, true);
}
$('#newusername').focus();
GroupList.incEveryoneCount();
}).fail(function(result, textStatus, errorThrown) {
OC.dialogs.alert(result.responseJSON.message, t('settings', 'Error creating user'));
});
}); });
// Option to display/hide the "Storage location" column // Option to display/hide the "Storage location" column

View File

@ -148,10 +148,7 @@ class GroupsControllerTest extends \Test\TestCase {
$expectedResponse = new DataResponse( $expectedResponse = new DataResponse(
array( array(
'status' => 'error', 'message' => 'Group already exists.'
'data' => array(
'message' => 'Group already exists.'
)
), ),
Http::STATUS_CONFLICT Http::STATUS_CONFLICT
); );
@ -173,8 +170,7 @@ class GroupsControllerTest extends \Test\TestCase {
$expectedResponse = new DataResponse( $expectedResponse = new DataResponse(
array( array(
'status' => 'success', 'groupname' => 'NewGroup'
'data' => array('groupname' => 'NewGroup')
), ),
Http::STATUS_CREATED Http::STATUS_CREATED
); );

View File

@ -153,12 +153,9 @@ class UsersControllerTest extends \Test\TestCase {
$expectedResponse = new DataResponse( $expectedResponse = new DataResponse(
array( array(
'status' => 'success', 'username' => 'foo',
'data' => array( 'groups' => null,
'username' => 'foo', 'storageLocation' => '/home/user'
'groups' => null,
'storageLocation' => '/home/user'
)
), ),
Http::STATUS_CREATED Http::STATUS_CREATED
); );
@ -213,12 +210,9 @@ class UsersControllerTest extends \Test\TestCase {
$expectedResponse = new DataResponse( $expectedResponse = new DataResponse(
array( array(
'status' => 'success', 'username' => 'foo',
'data' => array( 'groups' => array('NewGroup', 'ExistingGroup'),
'username' => 'foo', 'storageLocation' => '/home/user'
'groups' => array('NewGroup', 'ExistingGroup'),
'storageLocation' => '/home/user'
)
), ),
Http::STATUS_CREATED Http::STATUS_CREATED
); );
@ -237,10 +231,7 @@ class UsersControllerTest extends \Test\TestCase {
$expectedResponse = new DataResponse( $expectedResponse = new DataResponse(
array( array(
'status' => 'error', 'message' => 'Unable to create user.'
'data' => array(
'message' => 'Unable to create user.'
)
), ),
Http::STATUS_FORBIDDEN Http::STATUS_FORBIDDEN
); );