Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full implement group display names #8255

Merged
merged 17 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions apps/dav/lib/CalDAV/Activity/Provider/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use OCA\DAV\CalDAV\CalDavBackend;
use OCP\Activity\IEvent;
use OCP\Activity\IProvider;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
Expand All @@ -35,14 +37,22 @@ abstract class Base implements IProvider {
/** @var IUserManager */
protected $userManager;

/** @var string[] cached displayNames - key is the UID and value the displayname */
protected $displayNames = [];
/** @var string[] */
protected $userDisplayNames = [];

/** @var IGroupManager */
protected $groupManager;

/** @var string[] */
protected $groupDisplayNames = [];

/**
* @param IUserManager $userManager
* @param IGroupManager $groupManager
*/
public function __construct(IUserManager $userManager) {
public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
}

/**
Expand Down Expand Up @@ -112,44 +122,59 @@ protected function generateLegacyCalendarParameter($id, $name) {
];
}

/**
* @param string $id
* @return array
*/
protected function generateGroupParameter($id) {
return [
'type' => 'group',
'id' => $id,
'name' => $id,
];
}

/**
* @param string $uid
* @return array
*/
protected function generateUserParameter($uid) {
if (!isset($this->displayNames[$uid])) {
$this->displayNames[$uid] = $this->getDisplayName($uid);
if (!isset($this->userDisplayNames[$uid])) {
$this->userDisplayNames[$uid] = $this->getUserDisplayName($uid);
}

return [
'type' => 'user',
'id' => $uid,
'name' => $this->displayNames[$uid],
'name' => $this->userDisplayNames[$uid],
];
}

/**
* @param string $uid
* @return string
*/
protected function getDisplayName($uid) {
protected function getUserDisplayName($uid) {
$user = $this->userManager->get($uid);
if ($user instanceof IUser) {
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;
}
}
6 changes: 4 additions & 2 deletions apps/dav/lib/CalDAV/Activity/Provider/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
Expand Down Expand Up @@ -63,10 +64,11 @@ class Calendar extends Base {
* @param IURLGenerator $url
* @param IManager $activityManager
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IEventMerger $eventMerger
*/
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) {
parent::__construct($userManager);
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
parent::__construct($userManager, $groupManager);
$this->languageFactory = $languageFactory;
$this->url = $url;
$this->activityManager = $activityManager;
Expand Down
6 changes: 4 additions & 2 deletions apps/dav/lib/CalDAV/Activity/Provider/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
Expand Down Expand Up @@ -57,10 +58,11 @@ class Event extends Base {
* @param IURLGenerator $url
* @param IManager $activityManager
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IEventMerger $eventMerger
*/
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) {
parent::__construct($userManager);
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
parent::__construct($userManager, $groupManager);
$this->languageFactory = $languageFactory;
$this->url = $url;
$this->activityManager = $activityManager;
Expand Down
8 changes: 7 additions & 1 deletion apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,28 @@
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IGroupManager;
use Test\TestCase;

class BaseTest extends TestCase {

/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
protected $userManager;

/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
protected $groupManager;

/** @var IProvider|Base|\PHPUnit_Framework_MockObject_MockObject */
protected $provider;

protected function setUp() {
parent::setUp();
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->provider = $this->getMockBuilder(Base::class)
->setConstructorArgs([
$this->userManager
$this->userManager,
$this->groupManager
])
->setMethods(['parse'])
->getMock();
Expand Down
64 changes: 54 additions & 10 deletions apps/files_sharing/lib/Activity/Providers/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
namespace OCA\Files_Sharing\Activity\Providers;

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 {

Expand All @@ -32,6 +38,24 @@ class Groups extends Base {
const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
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
* @return IEvent
Expand Down Expand Up @@ -103,24 +127,44 @@ protected function getParsedParameters(IEvent $event) {
case self::SUBJECT_UNSHARED_GROUP_BY:
return [
'file' => $this->getFile($parameters[0], $event),
'group' => [
'type' => 'group',
'id' => $parameters[2],
'name' => $parameters[2],
],
'group' => $this->generateGroupParameter($parameters[2]),
'actor' => $this->getUser($parameters[1]),
];
case self::SUBJECT_SHARED_GROUP_SELF:
case self::SUBJECT_UNSHARED_GROUP_SELF:
return [
'file' => $this->getFile($parameters[0], $event),
'group' => [
'type' => 'group',
'id' => $parameters[1],
'name' => $parameters[1],
],
'group' => $this->generateGroupParameter($parameters[1]),
];
}
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;
}
}
7 changes: 4 additions & 3 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,10 @@ public function getUserSubAdminGroups(string $userId): DataResponse {
}

// Get the subadmin groups
$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
foreach ($groups as $key => $group) {
$groups[$key] = $group->getGID();
$subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
$groups = [];
foreach ($subAdminGroups as $key => $group) {
$groups[] = $group->getGID();
}

if(!$groups) {
Expand Down
23 changes: 22 additions & 1 deletion apps/workflowengine/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
message: '',
errorMessage: '',
saving: false,
groups: [],
initialize: function() {
// 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));
Expand All @@ -161,6 +162,25 @@
if (this.model.get('id') === undefined) {
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() {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
Expand Down Expand Up @@ -304,10 +324,11 @@
id = $element.data('id'),
check = checks[id],
valueElement = $element.find('.check-value').first();
var self = this;

_.each(OCA.WorkflowEngine.availablePlugins, function(plugin) {
if (_.isFunction(plugin.render)) {
plugin.render(valueElement, check);
plugin.render(valueElement, check, self.groups);
}
});
}, this);
Expand Down
Loading