summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/user/user.php9
-rw-r--r--lib/public/iuser.php7
-rw-r--r--settings/controller/userscontroller.php50
-rw-r--r--settings/js/users/users.js53
-rw-r--r--tests/lib/user/user.php7
-rw-r--r--tests/settings/controller/userscontrollertest.php115
6 files changed, 152 insertions, 89 deletions
diff --git a/lib/private/user/user.php b/lib/private/user/user.php
index ad85337f628..05374c52b98 100644
--- a/lib/private/user/user.php
+++ b/lib/private/user/user.php
@@ -218,6 +218,15 @@ class User implements IUser {
}
/**
+ * Get the name of the backend class the user is connected with
+ *
+ * @return string
+ */
+ public function getBackendClassName() {
+ return get_class($this->backend);
+ }
+
+ /**
* check if the backend allows the user to change his avatar on Personal page
*
* @return bool
diff --git a/lib/public/iuser.php b/lib/public/iuser.php
index c15edcd14dd..b288c61df5e 100644
--- a/lib/public/iuser.php
+++ b/lib/public/iuser.php
@@ -69,6 +69,13 @@ interface IUser {
public function getHome();
/**
+ * Get the name of the backend class the user is connected with
+ *
+ * @return string
+ */
+ public function getBackendClassName();
+
+ /**
* check if the backend allows the user to change his avatar on Personal page
*
* @return bool
diff --git a/settings/controller/userscontroller.php b/settings/controller/userscontroller.php
index 5bd4b555106..589b0a888cb 100644
--- a/settings/controller/userscontroller.php
+++ b/settings/controller/userscontroller.php
@@ -18,6 +18,7 @@ use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
+use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
@@ -66,8 +67,26 @@ class UsersController extends Controller {
}
/**
+ * @param IUser $user
+ * @param array $userGroups
+ * @return array
+ */
+ private function formatUserForIndex(IUser $user, array $userGroups = null) {
+ return array(
+ 'name' => $user->getUID(),
+ 'displayname' => $user->getDisplayName(),
+ 'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups,
+ 'subadmin' => \OC_SubAdmin::getSubAdminsGroups($user->getUID()),
+ 'quota' => $this->config->getUserValue($user->getUID(), 'files', 'quota', 'default'),
+ 'storageLocation' => $user->getHome(),
+ 'lastLogin' => $user->getLastLogin(),
+ 'backend' => $user->getBackendClassName()
+ );
+ }
+
+ /**
* @NoAdminRequired
- * @NoCSRFRequired
+ *
* @param int $offset
* @param int $limit
* @param string $gid
@@ -91,16 +110,7 @@ class UsersController extends Controller {
}
foreach ($batch as $uid => $displayname) {
- $user = $this->userManager->get($uid);
- $users[] = array(
- 'name' => $uid,
- 'displayname' => $displayname,
- 'groups' => $this->groupManager->getUserGroupIds($user),
- 'subadmin' => \OC_SubAdmin::getSubAdminsGroups($uid),
- 'quota' => $this->config->getUserValue($uid, 'files', 'quota', 'default'),
- 'storageLocation' => $user->getHome(),
- 'lastLogin' => $user->getLastLogin(),
- );
+ $users[] = $this->formatUserForIndex($this->userManager->get($uid));
}
} else {
$groups = \OC_SubAdmin::getSubAdminsGroups($this->userSession->getUser()->getUID());
@@ -115,20 +125,13 @@ class UsersController extends Controller {
$user = $this->userManager->get($uid);
// Only add the groups, this user is a subadmin of
- $userGroups = array_intersect($this->groupManager->getUserGroupIds($user), \OC_SubAdmin::getSubAdminsGroups($this->userSession->getUser()->getUID()));
- $users[] = array(
- 'name' => $uid,
- 'displayname' => $user->getDisplayName(),
- 'groups' => $userGroups,
- 'quota' => $this->config->getUserValue($uid, 'files', 'quota', 'default'),
- 'storageLocation' => $user->getHome(),
- 'lastLogin' => $user->getLastLogin(),
- );
+ $userGroups = array_intersect($this->groupManager->getUserGroupIds($user),
+ \OC_SubAdmin::getSubAdminsGroups($this->userSession->getUser()->getUID()));
+ $users[] = $this->formatUserForIndex($user, $userGroups);
}
}
- // FIXME: That assignment on "data" is uneeded here - JS should be adjusted
- return new DataResponse(array('data' => $users, 'status' => 'success'));
+ return new DataResponse($users);
}
/**
@@ -142,7 +145,7 @@ class UsersController extends Controller {
* TODO: Tidy up and write unit tests - code is mainly static method calls
*/
public function create($username, $password, array $groups) {
-
+
if (!$this->isAdmin) {
if (!empty($groups)) {
foreach ($groups as $key => $group) {
@@ -247,7 +250,6 @@ class UsersController extends Controller {
),
Http::STATUS_FORBIDDEN
);
-
}
}
diff --git a/settings/js/users/users.js b/settings/js/users/users.js
index 1bca6d06b33..9c48da32c5a 100644
--- a/settings/js/users/users.js
+++ b/settings/js/users/users.js
@@ -331,35 +331,34 @@ var UserList = {
function (result) {
var loadedUsers = 0;
var trs = [];
- if (result.status === 'success') {
- //The offset does not mirror the amount of users available,
- //because it is backend-dependent. For correct retrieval,
- //always the limit(requested amount of users) needs to be added.
- $.each(result.data, function (index, user) {
- if(UserList.has(user.name)) {
- return true;
- }
- var $tr = UserList.add(user.name, user.displayname, user.groups, user.subadmin, user.quota, user.storageLocation, user.lastLogin, false);
- $tr.addClass('appear transparent');
- trs.push($tr);
- loadedUsers++;
- });
- if (result.data.length > 0) {
- UserList.doSort();
- $userList.siblings('.loading').css('visibility', 'hidden');
- }
- else {
- UserList.noMoreEntries = true;
- $userList.siblings('.loading').remove();
+ //The offset does not mirror the amount of users available,
+ //because it is backend-dependent. For correct retrieval,
+ //always the limit(requested amount of users) needs to be added.
+ $.each(result, function (index, user) {
+ if(UserList.has(user.name)) {
+ return true;
}
- UserList.offset += loadedUsers;
- // animate
- setTimeout(function() {
- for (var i = 0; i < trs.length; i++) {
- trs[i].removeClass('transparent');
- }
- }, 0);
+ var $tr = UserList.add(user.name, user.displayname, user.groups, user.subadmin, user.quota, user.storageLocation, user.lastLogin, false);
+ $tr.addClass('appear transparent');
+ trs.push($tr);
+ loadedUsers++;
+ });
+ if (result.length > 0) {
+ UserList.doSort();
+ $userList.siblings('.loading').css('visibility', 'hidden');
}
+ else {
+ UserList.noMoreEntries = true;
+ $userList.siblings('.loading').remove();
+ }
+ UserList.offset += loadedUsers;
+ // animate
+ setTimeout(function() {
+ for (var i = 0; i < trs.length; i++) {
+ trs[i].removeClass('transparent');
+ }
+ }, 0);
+ }).always(function() {
UserList.updating = false;
});
},
diff --git a/tests/lib/user/user.php b/tests/lib/user/user.php
index 6aa7243a75a..b54677f10af 100644
--- a/tests/lib/user/user.php
+++ b/tests/lib/user/user.php
@@ -216,6 +216,13 @@ class User extends \Test\TestCase {
$this->assertEquals('/home/foo', $user->getHome());
}
+ public function testGetBackendClassName() {
+ $user = new \OC\User\User('foo', new \OC_User_Dummy());
+ $this->assertEquals('OC_User_Dummy', $user->getBackendClassName());
+ $user = new \OC\User\User('foo', new \OC_User_Database());
+ $this->assertEquals('OC_User_Database', $user->getBackendClassName());
+ }
+
public function testGetHomeNotSupported() {
/**
* @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php
index 4b0683b6dae..eb48babadc8 100644
--- a/tests/settings/controller/userscontrollertest.php
+++ b/tests/settings/controller/userscontrollertest.php
@@ -54,30 +54,68 @@ class UsersControllerTest extends \Test\TestCase {
* to test for subadmins. Thus the test always assumes you have admin permissions...
*/
public function testIndex() {
- $admin = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
- $admin
- ->method('getLastLogin')
- ->will($this->returnValue(12));
- $admin
- ->method('getHome')
- ->will($this->returnValue('/home/admin'));
$foo = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$foo
+ ->expects($this->exactly(3))
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+ $foo
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->will($this->returnValue('M. Foo'));
+ $foo
->method('getLastLogin')
->will($this->returnValue(500));
$foo
->method('getHome')
->will($this->returnValue('/home/foo'));
+ $foo
+ ->expects($this->once())
+ ->method('getBackendClassName')
+ ->will($this->returnValue('OC_User_Database'));
+ $admin = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $admin
+ ->expects($this->exactly(3))
+ ->method('getUID')
+ ->will($this->returnValue('admin'));
+ $admin
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->will($this->returnValue('S. Admin'));
+ $admin
+ ->expects($this->once())
+ ->method('getLastLogin')
+ ->will($this->returnValue(12));
+ $admin
+ ->expects($this->once())
+ ->method('getHome')
+ ->will($this->returnValue('/home/admin'));
+ $admin
+ ->expects($this->once())
+ ->method('getBackendClassName')
+ ->will($this->returnValue('OC_User_Dummy'));
$bar = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$bar
+ ->expects($this->exactly(3))
+ ->method('getUID')
+ ->will($this->returnValue('bar'));
+ $bar
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->will($this->returnValue('B. Ar'));
+ $bar
->method('getLastLogin')
->will($this->returnValue(3999));
$bar
->method('getHome')
->will($this->returnValue('/home/bar'));
+ $bar
+ ->expects($this->once())
+ ->method('getBackendClassName')
+ ->will($this->returnValue('OC_User_Dummy'));
$this->container['GroupManager']
->expects($this->once())
@@ -98,36 +136,36 @@ class UsersControllerTest extends \Test\TestCase {
$expectedResponse = new DataResponse(
array(
- 'status' => 'success',
- 'data' => array(
- 0 => array(
- 'name' => 'foo',
- 'displayname' => 'M. Foo',
- 'groups' => array('Users', 'Support'),
- 'subadmin' => array(),
- 'quota' => 1024,
- 'storageLocation' => '/home/foo',
- 'lastLogin' => 500
- ),
- 1 => array(
- 'name' => 'admin',
- 'displayname' => 'S. Admin',
- 'groups' => array('admins', 'Support'),
- 'subadmin' => array(),
- 'quota' => 404,
- 'storageLocation' => '/home/admin',
- 'lastLogin' => 12
- ),
- 2 => array(
- 'name' => 'bar',
- 'displayname' => 'B. Ar',
- 'groups' => array('External Users'),
- 'subadmin' => array(),
- 'quota' => 2323,
- 'storageLocation' => '/home/bar',
- 'lastLogin' => 3999
- ),
- )
+ 0 => array(
+ 'name' => 'foo',
+ 'displayname' => 'M. Foo',
+ 'groups' => array('Users', 'Support'),
+ 'subadmin' => array(),
+ 'quota' => 1024,
+ 'storageLocation' => '/home/foo',
+ 'lastLogin' => 500,
+ 'backend' => 'OC_User_Database'
+ ),
+ 1 => array(
+ 'name' => 'admin',
+ 'displayname' => 'S. Admin',
+ 'groups' => array('admins', 'Support'),
+ 'subadmin' => array(),
+ 'quota' => 404,
+ 'storageLocation' => '/home/admin',
+ 'lastLogin' => 12,
+ 'backend' => 'OC_User_Dummy'
+ ),
+ 2 => array(
+ 'name' => 'bar',
+ 'displayname' => 'B. Ar',
+ 'groups' => array('External Users'),
+ 'subadmin' => array(),
+ 'quota' => 2323,
+ 'storageLocation' => '/home/bar',
+ 'lastLogin' => 3999,
+ 'backend' => 'OC_User_Dummy'
+ ),
)
);
$response = $this->usersController->index(0, 10, 'pattern');
@@ -341,4 +379,5 @@ class UsersControllerTest extends \Test\TestCase {
$response = $this->usersController->destroy('UserToDelete');
$this->assertEquals($expectedResponse, $response);
}
+
}