]> source.dussan.org Git - nextcloud-server.git/commitdiff
React on other statuscodes than 200
authorLukas Reschke <lukas@owncloud.com>
Mon, 8 Dec 2014 15:35:13 +0000 (16:35 +0100)
committerLukas Reschke <lukas@owncloud.com>
Mon, 8 Dec 2014 15:35:13 +0000 (16:35 +0100)
settings/controller/groupscontroller.php
settings/controller/userscontroller.php
settings/js/users/groups.js
settings/js/users/users.js
tests/settings/controller/groupscontrollertest.php
tests/settings/controller/userscontrollertest.php

index 8236d5507f47c7306925a16894fa7623dda6e2d1..82e72821c3d19c36c3c20ed2e792cf88e41c0dc8 100644 (file)
@@ -82,10 +82,7 @@ class GroupsController extends Controller {
                if($this->groupManager->groupExists($id)) {
                        return new DataResponse(
                                array(
-                                       'status' => 'error',
-                                       'data' => array(
-                                                       'message' => (string)$this->l10n->t('Group already exists.')
-                                               )
+                                       'message' => (string)$this->l10n->t('Group already exists.')
                                ),
                                Http::STATUS_CONFLICT
                        );
@@ -93,10 +90,7 @@ class GroupsController extends Controller {
                if($this->groupManager->createGroup($id)) {
                        return new DataResponse(
                                array(
-                                       'status' => 'success',
-                                       'data' => array(
-                                               'groupname' => $id
-                                       )
+                                       'groupname' => $id
                                ),
                                Http::STATUS_CREATED
                        );
index aa16574221ed0eca6ba9b5faa251462fcfb734c7..5bd4b5551068be9cad176c325f329a4118d50b25 100644 (file)
@@ -161,10 +161,7 @@ class UsersController extends Controller {
                } catch (\Exception $exception) {
                        return new DataResponse(
                                array(
-                                       'status' => 'error',
-                                       'data' => array(
-                                               'message' => (string)$this->l10n->t('Unable to create user.')
-                                       )
+                                       'message' => (string)$this->l10n->t('Unable to create user.')
                                ),
                                Http::STATUS_FORBIDDEN
                        );
@@ -183,12 +180,9 @@ class UsersController extends Controller {
 
                return new DataResponse(
                        array(
-                               'status' => 'success',
-                               'data' => array(
-                                       'username' => $username,
-                                       'groups' => $this->groupManager->getUserGroupIds($user),
-                                       'storageLocation' => $user->getHome()
-                               )
+                               'username' => $username,
+                               'groups' => $this->groupManager->getUserGroupIds($user),
+                               'storageLocation' => $user->getHome()
                        ),
                        Http::STATUS_CREATED
                );
index 40872785e301d657e3d6df9f495a43891c900c6c..c06bc5ff14be8dc035087bb664ceb118e479d530 100644 (file)
@@ -89,24 +89,19 @@ GroupList = {
                                id: groupname
                        },
                        function (result) {
-                               if (result.status !== 'success') {
-                                       OC.dialogs.alert(result.data.message,
-                                               t('settings', 'Error creating group'));
+                               if (result.groupname) {
+                                       var addedGroup = result.groupname;
+                                       UserList.availableGroups = $.unique($.merge(UserList.availableGroups, [addedGroup]));
+                                       GroupList.addGroup(result.groupname);
+
+                                       $('.groupsselect, .subadminsselect')
+                                               .append($('<option>', { value: result.groupname })
+                                                       .text(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')
-                                                       .append($('<option>', { value: result.data.groupname })
-                                                               .text(result.data.groupname));
-                                       }
-                                       GroupList.toggleAddGroup();
-                               }
-                       }
-               );
+                               GroupList.toggleAddGroup();
+                       }).fail(function(result, textStatus, errorThrown) {
+                               OC.dialogs.alert(result.responseJSON.message, t('settings', 'Error creating group'));
+                       });
        },
 
        update: function () {
index 6de8b7029ed1a5568d4592e81f50a938436d13ba..1bca6d06b33719230c4c03af59754b72c0584d4f 100644 (file)
@@ -674,42 +674,37 @@ $(document).ready(function () {
                                groups: groups
                        },
                        function (result) {
-                               if (result.status !== 'success') {
-                                       OC.dialogs.alert(result.data.message,
-                                               t('settings', 'Error creating user'));
-                               } else {
-                                       if (result.data.groups) {
-                                               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);
+                               if (result.groups) {
+                                       for (var i in result.groups) {
+                                               var gid = result.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);
                                        }
-                                       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);
+                               }
+                               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);
                                        }
-                                       $('#newusername').focus();
-                                       GroupList.incEveryoneCount();
+                                       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
index 003fb70b8116302fb59217e91c90cdb27887f805..4b6c9d02566b311bbb99f85a9f38d6519bf4abba 100644 (file)
@@ -148,10 +148,7 @@ class GroupsControllerTest extends \Test\TestCase {
 
                $expectedResponse = new DataResponse(
                        array(
-                               'status' => 'error',
-                               'data' => array(
-                                       'message' => 'Group already exists.'
-                               )
+                               'message' => 'Group already exists.'
                        ),
                        Http::STATUS_CONFLICT
                );
@@ -173,8 +170,7 @@ class GroupsControllerTest extends \Test\TestCase {
 
                $expectedResponse = new DataResponse(
                        array(
-                               'status' => 'success',
-                               'data' => array('groupname' => 'NewGroup')
+                               'groupname' => 'NewGroup'
                        ),
                        Http::STATUS_CREATED
                );
index 0f1dfb4e6853f17bc5a0cad3ef7a2dc79d56871a..4b0683b6dae619740b05b6134a5ab8483c2e53cc 100644 (file)
@@ -153,12 +153,9 @@ class UsersControllerTest extends \Test\TestCase {
 
                $expectedResponse = new DataResponse(
                        array(
-                               'status' => 'success',
-                               'data' => array(
-                                       'username' => 'foo',
-                                       'groups' => null,
-                                       'storageLocation' => '/home/user'
-                               )
+                               'username' => 'foo',
+                               'groups' => null,
+                               'storageLocation' => '/home/user'
                        ),
                        Http::STATUS_CREATED
                );
@@ -213,12 +210,9 @@ class UsersControllerTest extends \Test\TestCase {
 
                $expectedResponse = new DataResponse(
                        array(
-                               'status' => 'success',
-                               'data' => array(
-                                       'username' => 'foo',
-                                       'groups' => array('NewGroup', 'ExistingGroup'),
-                                       'storageLocation' => '/home/user'
-                               )
+                               'username' => 'foo',
+                               'groups' => array('NewGroup', 'ExistingGroup'),
+                               'storageLocation' => '/home/user'
                        ),
                        Http::STATUS_CREATED
                );
@@ -237,10 +231,7 @@ class UsersControllerTest extends \Test\TestCase {
 
                $expectedResponse = new DataResponse(
                        array(
-                               'status' => 'error',
-                               'data' => array(
-                                       'message' => 'Unable to create user.'
-                               )
+                               'message' => 'Unable to create user.'
                        ),
                        Http::STATUS_FORBIDDEN
                );