Merge pull request #8255 from nextcloud/bugfix/noid/group-display-name

Full implement group display names
This commit is contained in:
blizzz 2018-03-15 12:07:30 +01:00 committed by GitHub
commit 208e38e84e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 466 additions and 266 deletions

View File

@ -26,6 +26,8 @@ namespace OCA\DAV\CalDAV\Activity\Provider;
use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\CalDavBackend;
use OCP\Activity\IEvent; use OCP\Activity\IEvent;
use OCP\Activity\IProvider; use OCP\Activity\IProvider;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N; use OCP\IL10N;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
@ -35,14 +37,22 @@ abstract class Base implements IProvider {
/** @var IUserManager */ /** @var IUserManager */
protected $userManager; protected $userManager;
/** @var string[] cached displayNames - key is the UID and value the displayname */ /** @var string[] */
protected $displayNames = []; protected $userDisplayNames = [];
/** @var IGroupManager */
protected $groupManager;
/** @var string[] */
protected $groupDisplayNames = [];
/** /**
* @param IUserManager $userManager * @param IUserManager $userManager
* @param IGroupManager $groupManager
*/ */
public function __construct(IUserManager $userManager) { public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
$this->userManager = $userManager; $this->userManager = $userManager;
$this->groupManager = $groupManager;
} }
/** /**
@ -112,31 +122,19 @@ abstract class Base implements IProvider {
]; ];
} }
/**
* @param string $id
* @return array
*/
protected function generateGroupParameter($id) {
return [
'type' => 'group',
'id' => $id,
'name' => $id,
];
}
/** /**
* @param string $uid * @param string $uid
* @return array * @return array
*/ */
protected function generateUserParameter($uid) { protected function generateUserParameter($uid) {
if (!isset($this->displayNames[$uid])) { if (!isset($this->userDisplayNames[$uid])) {
$this->displayNames[$uid] = $this->getDisplayName($uid); $this->userDisplayNames[$uid] = $this->getUserDisplayName($uid);
} }
return [ return [
'type' => 'user', 'type' => 'user',
'id' => $uid, 'id' => $uid,
'name' => $this->displayNames[$uid], 'name' => $this->userDisplayNames[$uid],
]; ];
} }
@ -144,12 +142,39 @@ abstract class Base implements IProvider {
* @param string $uid * @param string $uid
* @return string * @return string
*/ */
protected function getDisplayName($uid) { protected function getUserDisplayName($uid) {
$user = $this->userManager->get($uid); $user = $this->userManager->get($uid);
if ($user instanceof IUser) { if ($user instanceof IUser) {
return $user->getDisplayName(); return $user->getDisplayName();
} else {
return $uid;
} }
return $uid;
}
/**
* @param string $gid
* @return array
*/
protected function generateGroupParameter($gid) {
if (!isset($this->groupDisplayNames[$gid])) {
$this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid);
}
return [
'type' => 'group',
'id' => $gid,
'name' => $this->groupDisplayNames[$gid],
];
}
/**
* @param string $gid
* @return string
*/
protected function getGroupDisplayName($gid) {
$group = $this->groupManager->get($gid);
if ($group instanceof IGroup) {
return $group->getDisplayName();
}
return $gid;
} }
} }

View File

@ -26,6 +26,7 @@ namespace OCA\DAV\CalDAV\Activity\Provider;
use OCP\Activity\IEvent; use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger; use OCP\Activity\IEventMerger;
use OCP\Activity\IManager; use OCP\Activity\IManager;
use OCP\IGroupManager;
use OCP\IL10N; use OCP\IL10N;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUserManager; use OCP\IUserManager;
@ -63,10 +64,11 @@ class Calendar extends Base {
* @param IURLGenerator $url * @param IURLGenerator $url
* @param IManager $activityManager * @param IManager $activityManager
* @param IUserManager $userManager * @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IEventMerger $eventMerger * @param IEventMerger $eventMerger
*/ */
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) { public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
parent::__construct($userManager); parent::__construct($userManager, $groupManager);
$this->languageFactory = $languageFactory; $this->languageFactory = $languageFactory;
$this->url = $url; $this->url = $url;
$this->activityManager = $activityManager; $this->activityManager = $activityManager;

View File

@ -26,6 +26,7 @@ namespace OCA\DAV\CalDAV\Activity\Provider;
use OCP\Activity\IEvent; use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger; use OCP\Activity\IEventMerger;
use OCP\Activity\IManager; use OCP\Activity\IManager;
use OCP\IGroupManager;
use OCP\IL10N; use OCP\IL10N;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUserManager; use OCP\IUserManager;
@ -57,10 +58,11 @@ class Event extends Base {
* @param IURLGenerator $url * @param IURLGenerator $url
* @param IManager $activityManager * @param IManager $activityManager
* @param IUserManager $userManager * @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IEventMerger $eventMerger * @param IEventMerger $eventMerger
*/ */
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) { public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
parent::__construct($userManager); parent::__construct($userManager, $groupManager);
$this->languageFactory = $languageFactory; $this->languageFactory = $languageFactory;
$this->url = $url; $this->url = $url;
$this->activityManager = $activityManager; $this->activityManager = $activityManager;

View File

@ -29,6 +29,7 @@ use OCP\Activity\IProvider;
use OCP\IL10N; use OCP\IL10N;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IGroupManager;
use Test\TestCase; use Test\TestCase;
class BaseTest extends TestCase { class BaseTest extends TestCase {
@ -36,15 +37,20 @@ class BaseTest extends TestCase {
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
protected $userManager; protected $userManager;
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
protected $groupManager;
/** @var IProvider|Base|\PHPUnit_Framework_MockObject_MockObject */ /** @var IProvider|Base|\PHPUnit_Framework_MockObject_MockObject */
protected $provider; protected $provider;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->userManager = $this->createMock(IUserManager::class); $this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->provider = $this->getMockBuilder(Base::class) $this->provider = $this->getMockBuilder(Base::class)
->setConstructorArgs([ ->setConstructorArgs([
$this->userManager $this->userManager,
$this->groupManager
]) ])
->setMethods(['parse']) ->setMethods(['parse'])
->getMock(); ->getMock();

View File

@ -24,6 +24,12 @@
namespace OCA\Files_Sharing\Activity\Providers; namespace OCA\Files_Sharing\Activity\Providers;
use OCP\Activity\IEvent; use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
class Groups extends Base { class Groups extends Base {
@ -32,6 +38,24 @@ class Groups extends Base {
const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self'; const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by'; const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by';
/** @var IGroupManager */
protected $groupManager;
/** @var string[] */
protected $groupDisplayNames = [];
/**
* @param IFactory $languageFactory
* @param IURLGenerator $url
* @param IManager $activityManager
* @param IUserManager $userManager
* @param IGroupManager $groupManager
*/
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager) {
parent::__construct($languageFactory, $url, $activityManager, $userManager);
$this->groupManager = $groupManager;
}
/** /**
* @param IEvent $event * @param IEvent $event
* @return IEvent * @return IEvent
@ -103,24 +127,44 @@ class Groups extends Base {
case self::SUBJECT_UNSHARED_GROUP_BY: case self::SUBJECT_UNSHARED_GROUP_BY:
return [ return [
'file' => $this->getFile($parameters[0], $event), 'file' => $this->getFile($parameters[0], $event),
'group' => [ 'group' => $this->generateGroupParameter($parameters[2]),
'type' => 'group',
'id' => $parameters[2],
'name' => $parameters[2],
],
'actor' => $this->getUser($parameters[1]), 'actor' => $this->getUser($parameters[1]),
]; ];
case self::SUBJECT_SHARED_GROUP_SELF: case self::SUBJECT_SHARED_GROUP_SELF:
case self::SUBJECT_UNSHARED_GROUP_SELF: case self::SUBJECT_UNSHARED_GROUP_SELF:
return [ return [
'file' => $this->getFile($parameters[0], $event), 'file' => $this->getFile($parameters[0], $event),
'group' => [ 'group' => $this->generateGroupParameter($parameters[1]),
'type' => 'group',
'id' => $parameters[1],
'name' => $parameters[1],
],
]; ];
} }
return []; return [];
} }
/**
* @param string $gid
* @return array
*/
protected function generateGroupParameter($gid) {
if (!isset($this->groupDisplayNames[$gid])) {
$this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid);
}
return [
'type' => 'group',
'id' => $gid,
'name' => $this->groupDisplayNames[$gid],
];
}
/**
* @param string $gid
* @return string
*/
protected function getGroupDisplayName($gid) {
$group = $this->groupManager->get($gid);
if ($group instanceof IGroup) {
return $group->getDisplayName();
}
return $gid;
}
} }

View File

@ -790,9 +790,10 @@ class UsersController extends OCSController {
} }
// Get the subadmin groups // Get the subadmin groups
$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
foreach ($groups as $key => $group) { $groups = [];
$groups[$key] = $group->getGID(); foreach ($subAdminGroups as $key => $group) {
$groups[] = $group->getGID();
} }
if(!$groups) { if(!$groups) {

View File

@ -149,6 +149,7 @@
message: '', message: '',
errorMessage: '', errorMessage: '',
saving: false, saving: false,
groups: [],
initialize: function() { initialize: function() {
// this creates a new copy of the object to definitely have a new reference and being able to reset the model // this creates a new copy of the object to definitely have a new reference and being able to reset the model
this.originalModel = JSON.parse(JSON.stringify(this.model)); this.originalModel = JSON.parse(JSON.stringify(this.model));
@ -161,6 +162,25 @@
if (this.model.get('id') === undefined) { if (this.model.get('id') === undefined) {
this.hasChanged = true; this.hasChanged = true;
} }
var self = this;
$.ajax({
url: OC.generateUrl('settings/users/groups'),
dataType: 'json',
quietMillis: 100,
}).success(function(response) {
// add admin groups
$.each(response.data.adminGroups, function(id, group) {
self.groups.push({ id: group.id, displayname: group.name });
});
// add groups
$.each(response.data.groups, function(id, group) {
self.groups.push({ id: group.id, displayname: group.name });
});
self.render();
}).error(function(data) {
OC.Notification.error(t('workflowengine', 'Unable to retrieve the group list'), {type: 'error'});
console.log(data);
});
}, },
delete: function() { delete: function() {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
@ -304,10 +324,11 @@
id = $element.data('id'), id = $element.data('id'),
check = checks[id], check = checks[id],
valueElement = $element.find('.check-value').first(); valueElement = $element.find('.check-value').first();
var self = this;
_.each(OCA.WorkflowEngine.availablePlugins, function(plugin) { _.each(OCA.WorkflowEngine.availablePlugins, function(plugin) {
if (_.isFunction(plugin.render)) { if (_.isFunction(plugin.render)) {
plugin.render(valueElement, check); plugin.render(valueElement, check, self.groups);
} }
}); });
}, this); }, this);

View File

@ -34,7 +34,7 @@
] ]
}; };
}, },
render: function(element, check) { render: function(element, check, groups) {
if (check['class'] !== 'OCA\\WorkflowEngine\\Check\\UserGroupMembership') { if (check['class'] !== 'OCA\\WorkflowEngine\\Check\\UserGroupMembership') {
return; return;
} }
@ -42,50 +42,30 @@
$(element).css('width', '400px'); $(element).css('width', '400px');
$(element).select2({ $(element).select2({
ajax: { data: { results: groups, text: 'displayname' },
url: OC.generateUrl('settings/users/groups'), initSelection: function (element, callback) {
dataType: 'json', var groupId = element.val();
quietMillis: 100, if (groupId && groups.length > 0) {
data: function (term) { callback({
return { id: groupId,
pattern: term, //search term displayname: groups.find(function (group) {
filterGroups: true, return group.id === groupId;
sortGroups: 2 // by groupname }).displayname
};
},
results: function (response) {
// TODO improve error case
if (response.data === undefined) {
console.error('Failure happened', response);
return;
}
var results = [];
// add admin groups
$.each(response.data.adminGroups, function(id, group) {
results.push({ id: group.id });
}); });
// add groups } else if (groupId) {
$.each(response.data.groups, function(id, group) { callback({
results.push({ id: group.id }); id: groupId,
displayname: groupId
}); });
} else {
// TODO once limit and offset is implemented for groups we should paginate the search results callback();
return {
results: results,
more: false
};
} }
}, },
initSelection: function (element, callback) {
callback({id: element.val()});
},
formatResult: function (element) { formatResult: function (element) {
return '<span>' + escapeHTML(element.id) + '</span>'; return '<span>' + escapeHTML(element.displayname) + '</span>';
}, },
formatSelection: function (element) { formatSelection: function (element) {
return '<span title="'+escapeHTML(element.id)+'">'+escapeHTML(element.id)+'</span>'; return '<span title="'+escapeHTML(element.id)+'">'+escapeHTML(element.displayname)+'</span>';
} }
}); });
} }

View File

@ -329,6 +329,17 @@ class Manager extends PublicEmitter implements IGroupManager {
}, array_keys($this->getUserGroups($user))); }, array_keys($this->getUserGroups($user)));
} }
/**
* get an array of groupid and displayName for a user
* @param IUser $user
* @return array ['displayName' => displayname]
*/
public function getUserGroupNames(IUser $user) {
return array_map(function($group) {
return array('displayName' => $group->getDisplayName());
}, $this->getUserGroups($user));
}
/** /**
* get a list of all display names in a group * get a list of all display names in a group
* @param string $gid * @param string $gid

View File

@ -160,7 +160,7 @@ class MetaData {
private function generateGroupMetaData(\OCP\IGroup $group, $userSearch) { private function generateGroupMetaData(\OCP\IGroup $group, $userSearch) {
return array( return array(
'id' => $group->getGID(), 'id' => $group->getGID(),
'name' => $group->getGID(), 'name' => $group->getDisplayName(),
'usercount' => $this->sorting === self::SORT_USERCOUNT ? $group->count($userSearch) : 0, 'usercount' => $this->sorting === self::SORT_USERCOUNT ? $group->count($userSearch) : 0,
); );
} }

View File

@ -174,7 +174,7 @@ class PersonalInfo implements ISettings {
private function getGroups(IUser $user) { private function getGroups(IUser $user) {
$groups = array_map( $groups = array_map(
function(IGroup $group) { function(IGroup $group) {
return $group->getGID(); return $group->getDisplayName();
}, },
$this->groupManager->getUserGroups($user) $this->groupManager->getUserGroups($user)
); );

View File

@ -62,7 +62,7 @@ class SubAdmin extends PublicEmitter {
$this->post_deleteUser($user); $this->post_deleteUser($user);
}); });
$this->groupManager->listen('\OC\Group', 'postDelete', function($group) { $this->groupManager->listen('\OC\Group', 'postDelete', function($group) {
$this->post_deleteGroup($group); $this->post_deleteGroup($group);
}); });
} }
@ -123,7 +123,7 @@ class SubAdmin extends PublicEmitter {
while($row = $result->fetch()) { while($row = $result->fetch()) {
$group = $this->groupManager->get($row['gid']); $group = $this->groupManager->get($row['gid']);
if(!is_null($group)) { if(!is_null($group)) {
$groups[] = $group; $groups[$group->getGID()] = $group;
} }
} }
$result->closeCursor(); $result->closeCursor();
@ -131,6 +131,17 @@ class SubAdmin extends PublicEmitter {
return $groups; return $groups;
} }
/**
* get an array of groupid and displayName for a user
* @param IUser $user
* @return array ['displayName' => displayname]
*/
public function getSubAdminsGroupsName(IUser $user) {
return array_map(function($group) {
return array('displayName' => $group->getDisplayName());
}, $this->getSubAdminsGroups($user));
}
/** /**
* get SubAdmins of a group * get SubAdmins of a group
* @param IGroup $group the group * @param IGroup $group the group
@ -185,7 +196,7 @@ class SubAdmin extends PublicEmitter {
/** /**
* checks if a user is a SubAdmin of a group * checks if a user is a SubAdmin of a group
* @param IUser $user * @param IUser $user
* @param IGroup $group * @param IGroup $group
* @return bool * @return bool
*/ */
@ -210,7 +221,7 @@ class SubAdmin extends PublicEmitter {
/** /**
* checks if a user is a SubAdmin * checks if a user is a SubAdmin
* @param IUser $user * @param IUser $user
* @return bool * @return bool
*/ */
public function isSubAdmin(IUser $user) { public function isSubAdmin(IUser $user) {

View File

@ -28,6 +28,7 @@ use OC\AppFramework\Http;
use OC\Group\MetaData; use OC\Group\MetaData;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\IGroup;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IL10N; use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;
@ -108,13 +109,9 @@ class GroupsController extends Controller {
Http::STATUS_CONFLICT Http::STATUS_CONFLICT
); );
} }
if($this->groupManager->createGroup($id)) { $group = $this->groupManager->createGroup($id);
return new DataResponse( if($group instanceof IGroup) {
array( return new DataResponse(['groupname' => $group->getDisplayName()], Http::STATUS_CREATED);
'groupname' => $id
),
Http::STATUS_CREATED
);
} }
return new DataResponse( return new DataResponse(
@ -140,9 +137,7 @@ class GroupsController extends Controller {
return new DataResponse( return new DataResponse(
array( array(
'status' => 'success', 'status' => 'success',
'data' => array( 'data' => ['groupname' => $group->getDisplayName()]
'groupname' => $id
)
), ),
Http::STATUS_NO_CONTENT Http::STATUS_NO_CONTENT
); );

View File

@ -203,10 +203,7 @@ class UsersController extends Controller {
$restorePossible = true; $restorePossible = true;
} }
$subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroupsName($user);
foreach ($subAdminGroups as $key => $subAdminGroup) {
$subAdminGroups[$key] = $subAdminGroup->getGID();
}
$displayName = $user->getEMailAddress(); $displayName = $user->getEMailAddress();
if (is_null($displayName)) { if (is_null($displayName)) {
@ -223,7 +220,7 @@ class UsersController extends Controller {
return [ return [
'name' => $user->getUID(), 'name' => $user->getUID(),
'displayname' => $user->getDisplayName(), 'displayname' => $user->getDisplayName(),
'groups' => empty($userGroups) ? $this->groupManager->getUserGroupIds($user) : $userGroups, 'groups' => empty($userGroups) ? $this->groupManager->getUserGroupNames($user) : $userGroups,
'subadmin' => $subAdminGroups, 'subadmin' => $subAdminGroups,
'quota' => $user->getQuota(), 'quota' => $user->getQuota(),
'quota_bytes' => Util::computerFileSize($user->getQuota()), 'quota_bytes' => Util::computerFileSize($user->getQuota()),
@ -464,7 +461,7 @@ class UsersController extends Controller {
} }
} }
// fetch users groups // fetch users groups
$userGroups = $this->groupManager->getUserGroupIds($user); $userGroups = $this->groupManager->getUserGroupNames($user);
return new DataResponse( return new DataResponse(
$this->formatUserForIndex($user, $userGroups), $this->formatUserForIndex($user, $userGroups),

View File

@ -641,14 +641,13 @@ OC.Settings.Apps = OC.Settings.Apps || {
$('#navigation li[data-id=' + previousEntry.id + ']').after(li); $('#navigation li[data-id=' + previousEntry.id + ']').after(li);
// draw attention to the newly added app entry // draw attention to the newly added app entry
// by flashing it twice // by flashing twice the more apps menu
if(addedApps[entry.id]) { if(addedApps[entry.id]) {
$('#header .menutoggle') $('#header #more-apps')
.animate({opacity: 0.5}) .animate({opacity: 0.5})
.animate({opacity: 1}) .animate({opacity: 1})
.animate({opacity: 0.5}) .animate({opacity: 0.5})
.animate({opacity: 1}) .animate({opacity: 1});
.animate({opacity: 0.75});
} }
} }

View File

@ -24,77 +24,68 @@ OC.Settings = _.extend(OC.Settings, {
var self = this; var self = this;
options = options || {}; options = options || {};
if ($elements.length > 0) { if ($elements.length > 0) {
// note: settings are saved through a "change" event registered // Let's load the data and THEN init our select
// on all input fields $.ajax({
$elements.select2(_.extend({ url: OC.generateUrl('/settings/users/groups'),
placeholder: t('core', 'Groups'), dataType: 'json',
allowClear: true, success: function(data) {
multiple: true, var results = [];
toggleSelect: true,
separator: '|',
query: _.debounce(function(query) {
var queryData = {};
if (self._cachedGroups && query.term === '') {
query.callback({results: self._cachedGroups});
return;
}
if (query.term !== '') {
queryData = {
pattern: query.term,
filterGroups: 1
};
}
$.ajax({
url: OC.generateUrl('/settings/users/groups'),
data: queryData,
dataType: 'json',
success: function(data) {
var results = [];
// add groups // add groups
if (!options.excludeAdmins) { if (!options.excludeAdmins) {
$.each(data.data.adminGroups, function(i, group) { $.each(data.data.adminGroups, function(i, group) {
results.push({id:group.id, displayname:group.name}); results.push({id:group.id, displayname:group.name});
});
}
$.each(data.data.groups, function(i, group) {
results.push({id:group.id, displayname:group.name});
});
// note: settings are saved through a "change" event registered
// on all input fields
$elements.select2(_.extend({
placeholder: t('core', 'Groups'),
allowClear: true,
multiple: true,
toggleSelect: true,
separator: '|',
data: { results: results, text: 'displayname' },
initSelection: function(element, callback) {
var groups = $(element).val();
var selection;
if (groups && results.length > 0) {
selection = _.map((groups || []).split('|').sort(), function(groupId) {
return {
id: groupId,
displayname: results.find(group =>group.id === groupId).displayname
};
});
} else if (groups) {
selection = _.map((groups || []).split('|').sort(), function(groupId) {
return {
id: groupId,
displayname: groupId
};
}); });
} }
$.each(data.data.groups, function(i, group) { callback(selection);
results.push({id:group.id, displayname:group.name}); },
}); formatResult: function (element) {
return escapeHTML(element.displayname);
if (query.term === '') { },
// cache full list formatSelection: function (element) {
self._cachedGroups = results; return escapeHTML(element.displayname);
} },
query.callback({results: results}); escapeMarkup: function(m) {
// prevent double markup escape
return m;
} }
}); }, extraOptions || {}));
}, 100, true),
id: function(element) {
return element.id;
}, },
initSelection: function(element, callback) { error : function(data) {
var selection = OC.Notification.show(t('settings', 'Unable to retrieve the group list'), {type: 'error'});
_.map(($(element).val() || []).split('|').sort(), console.log(data);
function(groupName) {
return {
id: groupName,
displayname: groupName
};
});
callback(selection);
},
formatResult: function (element) {
return escapeHTML(element.displayname);
},
formatSelection: function (element) {
return escapeHTML(element.displayname);
},
escapeMarkup: function(m) {
// prevent double markup escape
return m;
} }
}, extraOptions || {})); });
} }
} }
}); });

View File

@ -17,11 +17,14 @@ GroupList = {
filter: '', filter: '',
filterGroups: false, filterGroups: false,
addGroup: function (gid, usercount) { addGroup: function (gid, displayName, usercount) {
if (_.isUndefined(displayName)) {
displayName = gid;
}
var $li = $userGroupList.find('.isgroup:last-child').clone(); var $li = $userGroupList.find('.isgroup:last-child').clone();
$li $li
.data('gid', gid) .data('gid', gid)
.find('.groupname').text(gid); .find('.groupname').text(displayName);
GroupList.setUserCount($li, usercount); GroupList.setUserCount($li, usercount);
$li.appendTo($userGroupList); $li.appendTo($userGroupList);
@ -128,22 +131,22 @@ GroupList = {
} }
}, },
createGroup: function (groupname) { createGroup: function (groupid) {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.createGroup, this, groupname)); OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.createGroup, this, groupid));
return; return;
} }
$.post( $.post(
OC.generateUrl('/settings/users/groups'), OC.generateUrl('/settings/users/groups'),
{ {
id: groupname id: groupid
}, },
function (result) { function (result) {
if (result.groupname) { if (result.groupname) {
var addedGroup = result.groupname; var addedGroup = result.groupname;
UserList.availableGroups = $.unique($.merge(UserList.availableGroups, [addedGroup])); UserList.availableGroups[groupid] = {displayName: result.groupname};
GroupList.addGroup(result.groupname); GroupList.addGroup(groupid, result.groupname);
} }
GroupList.toggleAddGroup(); GroupList.toggleAddGroup();
}).fail(function(result) { }).fail(function(result) {
@ -173,7 +176,7 @@ GroupList = {
GroupList.setUserCount(GroupList.getGroupLI(group.name).first(), group.usercount); GroupList.setUserCount(GroupList.getGroupLI(group.name).first(), group.usercount);
} }
else { else {
var $li = GroupList.addGroup(group.name, group.usercount); var $li = GroupList.addGroup(group.id, group.name, group.usercount);
$li.addClass('appear transparent'); $li.addClass('appear transparent');
lis.push($li); lis.push($li);

View File

@ -52,8 +52,8 @@ var UserList = {
* { * {
* 'name': 'username', * 'name': 'username',
* 'displayname': 'Users display name', * 'displayname': 'Users display name',
* 'groups': ['group1', 'group2'], * 'groups': {group1: {displayName: 'Group 1'}, group2: {displayName: 'Group 2'}}
* 'subadmin': ['group4', 'group5'], * 'subadmin': {group5: {displayName: 'Group 5'}, group6: {displayName: 'Group 6'}}
* 'quota': '10 GB', * 'quota': '10 GB',
* 'quota_bytes': '10737418240', * 'quota_bytes': '10737418240',
* 'storageLocation': '/srv/www/owncloud/data/username', * 'storageLocation': '/srv/www/owncloud/data/username',
@ -66,7 +66,7 @@ var UserList = {
* } * }
*/ */
add: function (user) { add: function (user) {
if (this.currentGid && this.currentGid !== '_everyone' && this.currentGid !== '_disabledUsers' && _.indexOf(user.groups, this.currentGid) < 0) { if (this.currentGid && this.currentGid !== '_everyone' && this.currentGid !== '_disabledUsers' && Object.keys(user.groups).indexOf(this.currentGid) < 0) {
return false; return false;
} }
@ -454,11 +454,10 @@ var UserList = {
if (!OC.isUserAdmin() && checked.length === 1 && checked[0] === group) { if (!OC.isUserAdmin() && checked.length === 1 && checked[0] === group) {
return false; return false;
} }
if (add && OC.isUserAdmin() && _.isUndefined(UserList.availableGroups[group])) {
if (add && OC.isUserAdmin() && UserList.availableGroups.indexOf(group) === -1) {
GroupList.createGroup(group); GroupList.createGroup(group);
if (UserList.availableGroups.indexOf(group) === -1) { if (_.isUndefined(UserList.availableGroups[group])) {
UserList.availableGroups.push(group); UserList.availableGroups[group] = {displayName: group};
} }
} }
@ -473,8 +472,8 @@ var UserList = {
}, },
success: function () { success: function () {
GroupList.update(); GroupList.update();
if (add && UserList.availableGroups.indexOf(group) === -1) { if (add && _.isUndefined(UserList.availableGroups[group])) {
UserList.availableGroups.push(group); UserList.availableGroups[group] = {displayName: group};
} }
if (add) { if (add) {
@ -647,11 +646,12 @@ var UserList = {
* Creates a temporary jquery.multiselect selector on the given group field * Creates a temporary jquery.multiselect selector on the given group field
*/ */
_triggerGroupEdit: function ($td, isSubadminSelect) { _triggerGroupEdit: function ($td, isSubadminSelect) {
var self = this;
var $groupsListContainer = $td.find('.groupsListContainer'); var $groupsListContainer = $td.find('.groupsListContainer');
var placeholder = $groupsListContainer.attr('data-placeholder') || t('settings', 'no group'); var placeholder = $groupsListContainer.data('placeholder') || t('settings', 'no group');
var user = UserList.getUID($td); var user = UserList.getUID($td);
var checked = $td.data('groups') || []; var checked = $td.data('groups') || {};
var extraGroups = [].concat(checked); var extraGroups = Object.assign({}, checked);
$td.find('.multiselectoptions').remove(); $td.find('.multiselectoptions').remove();
@ -663,22 +663,21 @@ var UserList = {
$groupsSelect = $('<select multiple="multiple" class="subadminsselect multiselect button" title="' + placeholder + '"></select>') $groupsSelect = $('<select multiple="multiple" class="subadminsselect multiselect button" title="' + placeholder + '"></select>')
} }
function createItem (group) { function createItem (gid, group) {
if (isSubadminSelect && group === 'admin') { if (isSubadminSelect && group.displayName === 'admin') {
// can't become subadmin of "admin" group // can't become subadmin of "admin" group
return; return;
} }
$groupsSelect.append($('<option value="' + escapeHTML(group) + '">' + escapeHTML(group) + '</option>')); $groupsSelect.append($('<option value="' + escapeHTML(gid) + '">' + escapeHTML(group.displayName) + '</option>'));
} }
$.each(this.availableGroups, function (i, group) { $.each(this.availableGroups, function (gid, group) {
// some new groups might be selected but not in the available groups list yet // some new groups might be selected but not in the available groups list yet
var extraIndex = extraGroups.indexOf(group); if (extraGroups[gid] !== undefined) {
if (extraIndex >= 0) {
// remove extra group as it was found // remove extra group as it was found
extraGroups.splice(extraIndex, 1); delete extraGroups[gid];
} }
createItem(group); createItem(gid, group);
}); });
$.each(extraGroups, function (i, group) { $.each(extraGroups, function (i, group) {
createItem(group); createItem(group);
@ -686,10 +685,13 @@ var UserList = {
$td.append($groupsSelect); $td.append($groupsSelect);
var checkedIds = Object.keys(checked).map(function(group, gid) {
return checked[group].displayName;
});
if (isSubadminSelect) { if (isSubadminSelect) {
UserList.applySubadminSelect($groupsSelect, user, checked); UserList.applySubadminSelect($groupsSelect, user, checkedIds);
} else { } else {
UserList.applyGroupSelect($groupsSelect, user, checked); UserList.applyGroupSelect($groupsSelect, user, checkedIds);
} }
$groupsListContainer.addClass('hidden'); $groupsListContainer.addClass('hidden');
@ -699,7 +701,15 @@ var UserList = {
$td.find('.multiselect:not(.groupsListContainer)').parent().remove(); $td.find('.multiselect:not(.groupsListContainer)').parent().remove();
$td.find('.multiselectoptions').remove(); $td.find('.multiselectoptions').remove();
$groupsListContainer.removeClass('hidden'); $groupsListContainer.removeClass('hidden');
UserList._updateGroupListLabel($td, e.checked); // Pull all checked groups from this.availableGroups
var checked = Object.keys(self.availableGroups).reduce(function (previous, key) {
if(e.checked.indexOf(key) >= 0) {
return Object.assign(previous, {[key]:self.availableGroups[key]});
} else {
return previous;
}
}, {});
UserList._updateGroupListLabel($td, checked);
}); });
}, },
@ -707,9 +717,12 @@ var UserList = {
* Updates the groups list td with the given groups selection * Updates the groups list td with the given groups selection
*/ */
_updateGroupListLabel: function ($td, groups) { _updateGroupListLabel: function ($td, groups) {
var placeholder = $td.find('.groupsListContainer').attr('data-placeholder'); var placeholder = $td.find('.groupsListContainer').data('placeholder');
var $groupsEl = $td.find('.groupsList'); var $groupsEl = $td.find('.groupsList');
$groupsEl.text(groups.join(', ') || placeholder || t('settings', 'no group')); var grouptext = Object.keys(groups).map(function(group, gid) {
return groups[group].displayName;
});
$groupsEl.text(grouptext.join(', ') || placeholder || t('settings', 'no group'));
$td.data('groups', groups); $td.data('groups', groups);
} }
}; };
@ -1029,7 +1042,7 @@ $(document).ready(function () {
OC.Search.clear(); OC.Search.clear();
}); });
UserList._updateGroupListLabel($('#newuser .groups'), []); UserList._updateGroupListLabel($('#newuser .groups'), {});
var _submitNewUserForm = function (event) { var _submitNewUserForm = function (event) {
event.preventDefault(); event.preventDefault();
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
@ -1057,7 +1070,8 @@ $(document).ready(function () {
} }
promise.then(function () { promise.then(function () {
var groups = $('#newuser .groups').data('groups') || []; var groups = $('#newuser .groups').data('groups') || {};
groups = Object.keys(groups);
$.post( $.post(
OC.generateUrl('/settings/users/users'), OC.generateUrl('/settings/users/users'),
{ {
@ -1070,8 +1084,8 @@ $(document).ready(function () {
if (result.groups) { if (result.groups) {
for (var i in result.groups) { for (var i in result.groups) {
var gid = result.groups[i]; var gid = result.groups[i];
if (UserList.availableGroups.indexOf(gid) === -1) { if (_.isUndefined(UserList.availableGroups[gid])) {
UserList.availableGroups.push(gid); UserList.availableGroups[gid] = {displayName: gid};
} }
var $li = GroupList.getGroupLI(gid); var $li = GroupList.getGroupLI(gid);
var userCount = GroupList.getUserCount($li); var userCount = GroupList.getUserCount($li);

View File

@ -21,10 +21,10 @@ style('settings', 'settings');
$userlistParams = array(); $userlistParams = array();
$allGroups=array(); $allGroups=array();
foreach($_["adminGroup"] as $group) { foreach($_["adminGroup"] as $group) {
$allGroups[] = $group['name']; $allGroups[$group['id']] = array('displayName' => $group['name']);
} }
foreach($_["groups"] as $group) { foreach($_["groups"] as $group) {
$allGroups[] = $group['name']; $allGroups[$group['id']] = array('displayName' => $group['name']);
} }
$userlistParams['subadmingroups'] = $allGroups; $userlistParams['subadmingroups'] = $allGroups;
$userlistParams['allGroups'] = json_encode($allGroups); $userlistParams['allGroups'] = json_encode($allGroups);

View File

@ -50,7 +50,7 @@
<!--List of Groups--> <!--List of Groups-->
<?php foreach($_["groups"] as $group): ?> <?php foreach($_["groups"] as $group): ?>
<li data-gid="<?php p($group['name']) ?>" data-usercount="<?php p($group['usercount']) ?>" class="isgroup"> <li data-gid="<?php p($group['id']) ?>" data-usercount="<?php p($group['usercount']) ?>" class="isgroup">
<a href="#" class="dorename"> <a href="#" class="dorename">
<span class="groupname"><?php p($group['name']); ?></span> <span class="groupname"><?php p($group['name']); ?></span>
</a> </a>

View File

@ -66,6 +66,9 @@ class GroupsControllerTest extends \Test\TestCase {
$firstGroup $firstGroup
->method('getGID') ->method('getGID')
->will($this->returnValue('firstGroup')); ->will($this->returnValue('firstGroup'));
$firstGroup
->method('getDisplayName')
->will($this->returnValue('First group'));
$firstGroup $firstGroup
->method('count') ->method('count')
->will($this->returnValue(12)); ->will($this->returnValue(12));
@ -74,6 +77,9 @@ class GroupsControllerTest extends \Test\TestCase {
$secondGroup $secondGroup
->method('getGID') ->method('getGID')
->will($this->returnValue('secondGroup')); ->will($this->returnValue('secondGroup'));
$secondGroup
->method('getDisplayName')
->will($this->returnValue('Second group'));
$secondGroup $secondGroup
->method('count') ->method('count')
->will($this->returnValue(25)); ->will($this->returnValue(25));
@ -82,6 +88,9 @@ class GroupsControllerTest extends \Test\TestCase {
$thirdGroup $thirdGroup
->method('getGID') ->method('getGID')
->will($this->returnValue('thirdGroup')); ->will($this->returnValue('thirdGroup'));
$thirdGroup
->method('getDisplayName')
->will($this->returnValue('Third group'));
$thirdGroup $thirdGroup
->method('count') ->method('count')
->will($this->returnValue(14)); ->will($this->returnValue(14));
@ -90,6 +99,9 @@ class GroupsControllerTest extends \Test\TestCase {
$fourthGroup $fourthGroup
->method('getGID') ->method('getGID')
->will($this->returnValue('admin')); ->will($this->returnValue('admin'));
$fourthGroup
->method('getDisplayName')
->will($this->returnValue('Admin'));
$fourthGroup $fourthGroup
->method('count') ->method('count')
->will($this->returnValue(18)); ->will($this->returnValue(18));
@ -119,7 +131,7 @@ class GroupsControllerTest extends \Test\TestCase {
'adminGroups' => array( 'adminGroups' => array(
0 => array( 0 => array(
'id' => 'admin', 'id' => 'admin',
'name' => 'admin', 'name' => 'Admin',
'usercount' => 0,//User count disabled 18, 'usercount' => 0,//User count disabled 18,
) )
), ),
@ -127,17 +139,17 @@ class GroupsControllerTest extends \Test\TestCase {
array( array(
0 => array( 0 => array(
'id' => 'firstGroup', 'id' => 'firstGroup',
'name' => 'firstGroup', 'name' => 'First group',
'usercount' => 0,//User count disabled 12, 'usercount' => 0,//User count disabled 12,
), ),
1 => array( 1 => array(
'id' => 'secondGroup', 'id' => 'secondGroup',
'name' => 'secondGroup', 'name' => 'Second group',
'usercount' => 0,//User count disabled 25, 'usercount' => 0,//User count disabled 25,
), ),
2 => array( 2 => array(
'id' => 'thirdGroup', 'id' => 'thirdGroup',
'name' => 'thirdGroup', 'name' => 'Third group',
'usercount' => 0,//User count disabled 14, 'usercount' => 0,//User count disabled 14,
), ),
) )
@ -158,6 +170,9 @@ class GroupsControllerTest extends \Test\TestCase {
$firstGroup $firstGroup
->method('getGID') ->method('getGID')
->will($this->returnValue('firstGroup')); ->will($this->returnValue('firstGroup'));
$firstGroup
->method('getDisplayName')
->will($this->returnValue('First group'));
$firstGroup $firstGroup
->method('count') ->method('count')
->will($this->returnValue(12)); ->will($this->returnValue(12));
@ -166,6 +181,9 @@ class GroupsControllerTest extends \Test\TestCase {
$secondGroup $secondGroup
->method('getGID') ->method('getGID')
->will($this->returnValue('secondGroup')); ->will($this->returnValue('secondGroup'));
$secondGroup
->method('getDisplayName')
->will($this->returnValue('Second group'));
$secondGroup $secondGroup
->method('count') ->method('count')
->will($this->returnValue(25)); ->will($this->returnValue(25));
@ -174,6 +192,9 @@ class GroupsControllerTest extends \Test\TestCase {
$thirdGroup $thirdGroup
->method('getGID') ->method('getGID')
->will($this->returnValue('thirdGroup')); ->will($this->returnValue('thirdGroup'));
$thirdGroup
->method('getDisplayName')
->will($this->returnValue('Third group'));
$thirdGroup $thirdGroup
->method('count') ->method('count')
->will($this->returnValue(14)); ->will($this->returnValue(14));
@ -182,6 +203,9 @@ class GroupsControllerTest extends \Test\TestCase {
$fourthGroup $fourthGroup
->method('getGID') ->method('getGID')
->will($this->returnValue('admin')); ->will($this->returnValue('admin'));
$fourthGroup
->method('getDisplayName')
->will($this->returnValue('Admin'));
$fourthGroup $fourthGroup
->method('count') ->method('count')
->will($this->returnValue(18)); ->will($this->returnValue(18));
@ -212,7 +236,7 @@ class GroupsControllerTest extends \Test\TestCase {
'adminGroups' => array( 'adminGroups' => array(
0 => array( 0 => array(
'id' => 'admin', 'id' => 'admin',
'name' => 'admin', 'name' => 'Admin',
'usercount' => 18, 'usercount' => 18,
) )
), ),
@ -220,17 +244,17 @@ class GroupsControllerTest extends \Test\TestCase {
array( array(
0 => array( 0 => array(
'id' => 'secondGroup', 'id' => 'secondGroup',
'name' => 'secondGroup', 'name' => 'Second group',
'usercount' => 25, 'usercount' => 25,
), ),
1 => array( 1 => array(
'id' => 'thirdGroup', 'id' => 'thirdGroup',
'name' => 'thirdGroup', 'name' => 'Third group',
'usercount' => 14, 'usercount' => 14,
), ),
2 => array( 2 => array(
'id' => 'firstGroup', 'id' => 'firstGroup',
'name' => 'firstGroup', 'name' => 'First group',
'usercount' => 12, 'usercount' => 12,
), ),
) )
@ -259,6 +283,8 @@ class GroupsControllerTest extends \Test\TestCase {
} }
public function testCreateSuccessful() { public function testCreateSuccessful() {
$group = $this->getMockBuilder(Group::class)
->disableOriginalConstructor()->getMock();
$this->groupManager $this->groupManager
->expects($this->once()) ->expects($this->once())
->method('groupExists') ->method('groupExists')
@ -268,7 +294,11 @@ class GroupsControllerTest extends \Test\TestCase {
->expects($this->once()) ->expects($this->once())
->method('createGroup') ->method('createGroup')
->with('NewGroup') ->with('NewGroup')
->will($this->returnValue(true)); ->will($this->returnValue($group));
$group
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('NewGroup'));
$expectedResponse = new DataResponse( $expectedResponse = new DataResponse(
array( array(
@ -315,6 +345,9 @@ class GroupsControllerTest extends \Test\TestCase {
->expects($this->once()) ->expects($this->once())
->method('delete') ->method('delete')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$group
->method('getDisplayName')
->will($this->returnValue('ExistingGroup'));
$expectedResponse = new DataResponse( $expectedResponse = new DataResponse(
array( array(

View File

@ -206,7 +206,7 @@ class UsersControllerTest extends \Test\TestCase {
$foo $foo
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getQuota') ->method('getQuota')
->will($this->returnValue('1024')); ->will($this->returnValue(1024));
$foo $foo
->method('getLastLogin') ->method('getLastLogin')
->will($this->returnValue(500)); ->will($this->returnValue(500));
@ -236,7 +236,7 @@ class UsersControllerTest extends \Test\TestCase {
$admin $admin
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getQuota') ->method('getQuota')
->will($this->returnValue('404')); ->will($this->returnValue(404));
$admin $admin
->expects($this->once()) ->expects($this->once())
->method('getLastLogin') ->method('getLastLogin')
@ -268,7 +268,7 @@ class UsersControllerTest extends \Test\TestCase {
$bar $bar
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getQuota') ->method('getQuota')
->will($this->returnValue('2323')); ->will($this->returnValue(2323));
$bar $bar
->method('getLastLogin') ->method('getLastLogin')
->will($this->returnValue(3999)); ->will($this->returnValue(3999));
@ -296,8 +296,20 @@ class UsersControllerTest extends \Test\TestCase {
->will($this->returnValue(array('foo' => 'M. Foo', 'admin' => 'S. Admin', 'bar' => 'B. Ar'))); ->will($this->returnValue(array('foo' => 'M. Foo', 'admin' => 'S. Admin', 'bar' => 'B. Ar')));
$this->groupManager $this->groupManager
->expects($this->exactly(3)) ->expects($this->exactly(3))
->method('getUserGroupIds') ->method('getUserGroupNames')
->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users'))); ->will($this->onConsecutiveCalls(
array(
'Users' => array('displayName' => 'Users'),
'Support' => array('displayName' => 'Support')
),
array(
'admins' => array('displayName' => 'admins'),
'Support' => array('displayName' => 'Support')
),
array(
'External Users' => array('displayName' => 'External Users')
)
));
$this->userManager $this->userManager
->expects($this->at(0)) ->expects($this->at(0))
->method('get') ->method('get')
@ -319,17 +331,17 @@ class UsersControllerTest extends \Test\TestCase {
->getMock(); ->getMock();
$subadmin $subadmin
->expects($this->any()) ->expects($this->any())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($foo) ->with($foo)
->will($this->returnValue([])); ->will($this->returnValue([]));
$subadmin $subadmin
->expects($this->any()) ->expects($this->any())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($admin) ->with($admin)
->will($this->returnValue([])); ->will($this->returnValue([]));
$subadmin $subadmin
->expects($this->any()) ->expects($this->any())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($bar) ->with($bar)
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
@ -347,10 +359,13 @@ class UsersControllerTest extends \Test\TestCase {
0 => array( 0 => array(
'name' => 'foo', 'name' => 'foo',
'displayname' => 'M. Foo', 'displayname' => 'M. Foo',
'groups' => array('Users', 'Support'), 'groups' => array(
'Users' => array('displayName' => 'Users'),
'Support' => array('displayName' => 'Support')
),
'subadmin' => array(), 'subadmin' => array(),
'quota' => 1024, 'quota' => 1024,
'quota_bytes' => 1024, 'quota_bytes' => 1024.0,
'storageLocation' => '/home/foo', 'storageLocation' => '/home/foo',
'lastLogin' => 500000, 'lastLogin' => 500000,
'backend' => 'OC_User_Database', 'backend' => 'OC_User_Database',
@ -363,10 +378,13 @@ class UsersControllerTest extends \Test\TestCase {
1 => array( 1 => array(
'name' => 'admin', 'name' => 'admin',
'displayname' => 'S. Admin', 'displayname' => 'S. Admin',
'groups' => array('admins', 'Support'), 'groups' => array(
'admins' => array('displayName' => 'admins'),
'Support' => array('displayName' => 'Support')
),
'subadmin' => array(), 'subadmin' => array(),
'quota' => 404, 'quota' => 404,
'quota_bytes' => 404, 'quota_bytes' => 404.0,
'storageLocation' => '/home/admin', 'storageLocation' => '/home/admin',
'lastLogin' => 12000, 'lastLogin' => 12000,
'backend' => Dummy::class, 'backend' => Dummy::class,
@ -379,10 +397,12 @@ class UsersControllerTest extends \Test\TestCase {
2 => array( 2 => array(
'name' => 'bar', 'name' => 'bar',
'displayname' => 'B. Ar', 'displayname' => 'B. Ar',
'groups' => array('External Users'), 'groups' => array(
'External Users' => array('displayName' => 'External Users')
),
'subadmin' => array(), 'subadmin' => array(),
'quota' => 2323, 'quota' => 2323,
'quota_bytes' => 2323, 'quota_bytes' => 2323.0,
'storageLocation' => '/home/bar', 'storageLocation' => '/home/bar',
'lastLogin' => 3999000, 'lastLogin' => 3999000,
'backend' => Dummy::class, 'backend' => Dummy::class,
@ -553,6 +573,10 @@ class UsersControllerTest extends \Test\TestCase {
->expects($this->at(0)) ->expects($this->at(0))
->method('getSubAdminsGroups') ->method('getSubAdminsGroups')
->will($this->returnValue([$subgroup1, $subgroup2])); ->will($this->returnValue([$subgroup1, $subgroup2]));
$subadmin
->expects($this->any())
->method('getSubAdminsGroupsName')
->will($this->returnValue([]));
$subadmin $subadmin
->expects($this->any()) ->expects($this->any())
->method('getSubAdminsGroups') ->method('getSubAdminsGroups')
@ -574,8 +598,8 @@ class UsersControllerTest extends \Test\TestCase {
'displayname' => 'B. Ar', 'displayname' => 'B. Ar',
'groups' => ['SubGroup1'], 'groups' => ['SubGroup1'],
'subadmin' => [], 'subadmin' => [],
'quota' => 2323, 'quota' => '2323',
'quota_bytes' => 2323, 'quota_bytes' => 2323.0,
'storageLocation' => '/home/bar', 'storageLocation' => '/home/bar',
'lastLogin' => 3999000, 'lastLogin' => 3999000,
'backend' => Dummy::class, 'backend' => Dummy::class,
@ -590,8 +614,8 @@ class UsersControllerTest extends \Test\TestCase {
'displayname' => 'M. Foo', 'displayname' => 'M. Foo',
'groups' => ['SubGroup2', 'SubGroup1'], 'groups' => ['SubGroup2', 'SubGroup1'],
'subadmin' => [], 'subadmin' => [],
'quota' => 1024, 'quota' => '1024',
'quota_bytes' => 1024, 'quota_bytes' => 1024.0,
'storageLocation' => '/home/foo', 'storageLocation' => '/home/foo',
'lastLogin' => 500000, 'lastLogin' => 500000,
'backend' => 'OC_User_Database', 'backend' => 'OC_User_Database',
@ -606,8 +630,8 @@ class UsersControllerTest extends \Test\TestCase {
'displayname' => 'S. Admin', 'displayname' => 'S. Admin',
'groups' => ['SubGroup2'], 'groups' => ['SubGroup2'],
'subadmin' => [], 'subadmin' => [],
'quota' => 404, 'quota' => '404',
'quota_bytes' => 404, 'quota_bytes' => 404.0,
'storageLocation' => '/home/admin', 'storageLocation' => '/home/admin',
'lastLogin' => 12000, 'lastLogin' => 12000,
'backend' => Dummy::class, 'backend' => Dummy::class,
@ -731,14 +755,26 @@ class UsersControllerTest extends \Test\TestCase {
->will($this->returnValue([$foo, $admin, $bar])); ->will($this->returnValue([$foo, $admin, $bar]));
$this->groupManager $this->groupManager
->expects($this->exactly(3)) ->expects($this->exactly(3))
->method('getUserGroupIds') ->method('getUserGroupNames')
->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users'))); ->will($this->onConsecutiveCalls(
array(
'Users' => array('displayName' => 'Users'),
'Support' => array('displayName' => 'Support')
),
array(
'admins' => array('displayName' => 'admins'),
'Support' => array('displayName' => 'Support')
),
array(
'External Users' => array('displayName' => 'External Users')
)
));
$subadmin = $this->getMockBuilder(SubAdmin::class) $subadmin = $this->getMockBuilder(SubAdmin::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$subadmin->expects($this->any()) $subadmin->expects($this->any())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
->expects($this->any()) ->expects($this->any())
@ -755,7 +791,10 @@ class UsersControllerTest extends \Test\TestCase {
0 => array( 0 => array(
'name' => 'foo', 'name' => 'foo',
'displayname' => 'M. Foo', 'displayname' => 'M. Foo',
'groups' => array('Users', 'Support'), 'groups' => array(
'Users' => array('displayName' => 'Users'),
'Support' => array('displayName' => 'Support')
),
'subadmin' => array(), 'subadmin' => array(),
'quota' => 1024, 'quota' => 1024,
'quota_bytes' => 1024, 'quota_bytes' => 1024,
@ -771,7 +810,10 @@ class UsersControllerTest extends \Test\TestCase {
1 => array( 1 => array(
'name' => 'admin', 'name' => 'admin',
'displayname' => 'S. Admin', 'displayname' => 'S. Admin',
'groups' => array('admins', 'Support'), 'groups' => array(
'admins' => array('displayName' => 'admins'),
'Support' => array('displayName' => 'Support')
),
'subadmin' => array(), 'subadmin' => array(),
'quota' => 404, 'quota' => 404,
'quota_bytes' => 404, 'quota_bytes' => 404,
@ -787,7 +829,9 @@ class UsersControllerTest extends \Test\TestCase {
2 => array( 2 => array(
'name' => 'bar', 'name' => 'bar',
'displayname' => 'B. Ar', 'displayname' => 'B. Ar',
'groups' => array('External Users'), 'groups' => array(
'External Users' => array('displayName' => 'External Users')
),
'subadmin' => array(), 'subadmin' => array(),
'quota' => 2323, 'quota' => 2323,
'quota_bytes' => 2323, 'quota_bytes' => 2323,
@ -857,7 +901,7 @@ class UsersControllerTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$subadmin->expects($this->once()) $subadmin->expects($this->once())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
->expects($this->any()) ->expects($this->any())
@ -944,7 +988,7 @@ class UsersControllerTest extends \Test\TestCase {
->getMock(); ->getMock();
$subadmin $subadmin
->expects($this->any()) ->expects($this->any())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($user) ->with($user)
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
@ -1022,16 +1066,21 @@ class UsersControllerTest extends \Test\TestCase {
->will($this->onConsecutiveCalls($newGroup)); ->will($this->onConsecutiveCalls($newGroup));
$this->groupManager $this->groupManager
->expects($this->once()) ->expects($this->once())
->method('getUserGroupIds') ->method('getUserGroupNames')
->with($user) ->with($user)
->will($this->onConsecutiveCalls(array('NewGroup', 'ExistingGroup'))); ->will($this->onConsecutiveCalls(
array(
'NewGroup' => array('displayName' => 'NewGroup'),
'ExistingGroup' => array('displayName' => 'ExistingGroup')
)
));
$subadmin = $this->getMockBuilder(SubAdmin::class) $subadmin = $this->getMockBuilder(SubAdmin::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$subadmin $subadmin
->expects($this->once()) ->expects($this->once())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($user) ->with($user)
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
@ -1042,7 +1091,10 @@ class UsersControllerTest extends \Test\TestCase {
$expectedResponse = new DataResponse( $expectedResponse = new DataResponse(
array( array(
'name' => 'foo', 'name' => 'foo',
'groups' => array('NewGroup', 'ExistingGroup'), 'groups' => array(
'NewGroup' => array('displayName' => 'NewGroup'),
'ExistingGroup' => array('displayName' => 'ExistingGroup')
),
'storageLocation' => '/home/user', 'storageLocation' => '/home/user',
'backend' => 'bar', 'backend' => 'bar',
'lastLogin' => null, 'lastLogin' => null,
@ -1100,18 +1152,20 @@ class UsersControllerTest extends \Test\TestCase {
->will($this->returnValue($newUser)); ->will($this->returnValue($newUser));
$this->groupManager $this->groupManager
->expects($this->once()) ->expects($this->once())
->method('getUserGroupIds') ->method('getUserGroupNames')
->with($user) ->with($user)
->will($this->onConsecutiveCalls(['SubGroup1'])); ->will($this->onConsecutiveCalls(array('SubGroup1' =>
array('displayName' => 'SubGroup1')
)));
$this->groupManager $this->groupManager
->expects($this->once()) ->expects($this->once())
->method('getUserGroupIds') ->method('getUserGroupNames')
->with($newUser) ->with($newUser)
->will($this->onConsecutiveCalls(['SubGroup1'])); ->will($this->onConsecutiveCalls(['SubGroup1']));
$subadmin = $this->createMock(\OC\SubAdmin::class); $subadmin = $this->createMock(\OC\SubAdmin::class);
$subadmin->expects($this->atLeastOnce()) $subadmin->expects($this->atLeastOnce())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($user) ->with($user)
->willReturnMap([ ->willReturnMap([
[$user, [$subGroup1]], [$user, [$subGroup1]],
@ -1135,7 +1189,7 @@ class UsersControllerTest extends \Test\TestCase {
$expectedResponse = new DataResponse( $expectedResponse = new DataResponse(
array( array(
'name' => 'foo', 'name' => 'foo',
'groups' => ['SubGroup1'], 'groups' => array('SubGroup1' => array('displayName' => 'SubGroup1')),
'storageLocation' => '/home/user', 'storageLocation' => '/home/user',
'backend' => 'bar', 'backend' => 'bar',
'lastLogin' => 0, 'lastLogin' => 0,
@ -1563,7 +1617,7 @@ class UsersControllerTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$subadmin->expects($this->once()) $subadmin->expects($this->once())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($user) ->with($user)
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
@ -1629,7 +1683,7 @@ class UsersControllerTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$subadmin->expects($this->once()) $subadmin->expects($this->once())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($user) ->with($user)
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
@ -1676,7 +1730,7 @@ class UsersControllerTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$subadmin->expects($this->once()) $subadmin->expects($this->once())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($user) ->with($user)
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
@ -1714,7 +1768,7 @@ class UsersControllerTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$subadmin->expects($this->once()) $subadmin->expects($this->once())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($user) ->with($user)
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
@ -1771,7 +1825,7 @@ class UsersControllerTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$subadmin->expects($this->once()) $subadmin->expects($this->once())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($user) ->with($user)
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
@ -1793,7 +1847,7 @@ class UsersControllerTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$subadmin->expects($this->once()) $subadmin->expects($this->once())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($user) ->with($user)
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager
@ -1858,6 +1912,10 @@ class UsersControllerTest extends \Test\TestCase {
$subadmin = $this->getMockBuilder(SubAdmin::class) $subadmin = $this->getMockBuilder(SubAdmin::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$subadmin
->expects($this->at(0))
->method('getSubAdminsGroupsName')
->will($this->returnValue([$group1, $group2]));
$subadmin $subadmin
->expects($this->at(0)) ->expects($this->at(0))
->method('getSubAdminsGroups') ->method('getSubAdminsGroups')
@ -2407,7 +2465,7 @@ class UsersControllerTest extends \Test\TestCase {
->getMock(); ->getMock();
$subadmin $subadmin
->expects($this->any()) ->expects($this->any())
->method('getSubAdminsGroups') ->method('getSubAdminsGroupsName')
->with($user) ->with($user)
->will($this->returnValue([])); ->will($this->returnValue([]));
$this->groupManager $this->groupManager

View File

@ -53,12 +53,19 @@ class MetaDataTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$group->expects($this->exactly(9)) $group->expects($this->exactly(6))
->method('getGID') ->method('getGID')
->will($this->onConsecutiveCalls( ->will($this->onConsecutiveCalls(
'admin', 'admin', 'admin', 'admin', 'admin',
'g2', 'g2', 'g2', 'g2', 'g2',
'g3', 'g3', 'g3')); 'g3', 'g3'));
$group->expects($this->exactly(3))
->method('getDisplayName')
->will($this->onConsecutiveCalls(
'admin',
'g2',
'g3'));
$group->expects($this->exactly($countCallCount)) $group->expects($this->exactly($countCallCount))
->method('count') ->method('count')