Skip to content

Commit 208e38e

Browse files
authored
Merge pull request #8255 from nextcloud/bugfix/noid/group-display-name
Full implement group display names
2 parents fde08a9 + 23a1553 commit 208e38e

File tree

23 files changed

+466
-266
lines changed

23 files changed

+466
-266
lines changed

apps/dav/lib/CalDAV/Activity/Provider/Base.php

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use OCA\DAV\CalDAV\CalDavBackend;
2727
use OCP\Activity\IEvent;
2828
use OCP\Activity\IProvider;
29+
use OCP\IGroup;
30+
use OCP\IGroupManager;
2931
use OCP\IL10N;
3032
use OCP\IUser;
3133
use OCP\IUserManager;
@@ -35,14 +37,22 @@ abstract class Base implements IProvider {
3537
/** @var IUserManager */
3638
protected $userManager;
3739

38-
/** @var string[] cached displayNames - key is the UID and value the displayname */
39-
protected $displayNames = [];
40+
/** @var string[] */
41+
protected $userDisplayNames = [];
42+
43+
/** @var IGroupManager */
44+
protected $groupManager;
45+
46+
/** @var string[] */
47+
protected $groupDisplayNames = [];
4048

4149
/**
4250
* @param IUserManager $userManager
51+
* @param IGroupManager $groupManager
4352
*/
44-
public function __construct(IUserManager $userManager) {
53+
public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
4554
$this->userManager = $userManager;
55+
$this->groupManager = $groupManager;
4656
}
4757

4858
/**
@@ -112,44 +122,59 @@ protected function generateLegacyCalendarParameter($id, $name) {
112122
];
113123
}
114124

115-
/**
116-
* @param string $id
117-
* @return array
118-
*/
119-
protected function generateGroupParameter($id) {
120-
return [
121-
'type' => 'group',
122-
'id' => $id,
123-
'name' => $id,
124-
];
125-
}
126-
127125
/**
128126
* @param string $uid
129127
* @return array
130128
*/
131129
protected function generateUserParameter($uid) {
132-
if (!isset($this->displayNames[$uid])) {
133-
$this->displayNames[$uid] = $this->getDisplayName($uid);
130+
if (!isset($this->userDisplayNames[$uid])) {
131+
$this->userDisplayNames[$uid] = $this->getUserDisplayName($uid);
134132
}
135133

136134
return [
137135
'type' => 'user',
138136
'id' => $uid,
139-
'name' => $this->displayNames[$uid],
137+
'name' => $this->userDisplayNames[$uid],
140138
];
141139
}
142140

143141
/**
144142
* @param string $uid
145143
* @return string
146144
*/
147-
protected function getDisplayName($uid) {
145+
protected function getUserDisplayName($uid) {
148146
$user = $this->userManager->get($uid);
149147
if ($user instanceof IUser) {
150148
return $user->getDisplayName();
151-
} else {
152-
return $uid;
153149
}
150+
return $uid;
151+
}
152+
153+
/**
154+
* @param string $gid
155+
* @return array
156+
*/
157+
protected function generateGroupParameter($gid) {
158+
if (!isset($this->groupDisplayNames[$gid])) {
159+
$this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid);
160+
}
161+
162+
return [
163+
'type' => 'group',
164+
'id' => $gid,
165+
'name' => $this->groupDisplayNames[$gid],
166+
];
167+
}
168+
169+
/**
170+
* @param string $gid
171+
* @return string
172+
*/
173+
protected function getGroupDisplayName($gid) {
174+
$group = $this->groupManager->get($gid);
175+
if ($group instanceof IGroup) {
176+
return $group->getDisplayName();
177+
}
178+
return $gid;
154179
}
155180
}

apps/dav/lib/CalDAV/Activity/Provider/Calendar.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\Activity\IEvent;
2727
use OCP\Activity\IEventMerger;
2828
use OCP\Activity\IManager;
29+
use OCP\IGroupManager;
2930
use OCP\IL10N;
3031
use OCP\IURLGenerator;
3132
use OCP\IUserManager;
@@ -63,10 +64,11 @@ class Calendar extends Base {
6364
* @param IURLGenerator $url
6465
* @param IManager $activityManager
6566
* @param IUserManager $userManager
67+
* @param IGroupManager $groupManager
6668
* @param IEventMerger $eventMerger
6769
*/
68-
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) {
69-
parent::__construct($userManager);
70+
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
71+
parent::__construct($userManager, $groupManager);
7072
$this->languageFactory = $languageFactory;
7173
$this->url = $url;
7274
$this->activityManager = $activityManager;

apps/dav/lib/CalDAV/Activity/Provider/Event.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\Activity\IEvent;
2727
use OCP\Activity\IEventMerger;
2828
use OCP\Activity\IManager;
29+
use OCP\IGroupManager;
2930
use OCP\IL10N;
3031
use OCP\IURLGenerator;
3132
use OCP\IUserManager;
@@ -57,10 +58,11 @@ class Event extends Base {
5758
* @param IURLGenerator $url
5859
* @param IManager $activityManager
5960
* @param IUserManager $userManager
61+
* @param IGroupManager $groupManager
6062
* @param IEventMerger $eventMerger
6163
*/
62-
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IEventMerger $eventMerger) {
63-
parent::__construct($userManager);
64+
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager, IEventMerger $eventMerger) {
65+
parent::__construct($userManager, $groupManager);
6466
$this->languageFactory = $languageFactory;
6567
$this->url = $url;
6668
$this->activityManager = $activityManager;

apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,28 @@
2929
use OCP\IL10N;
3030
use OCP\IUser;
3131
use OCP\IUserManager;
32+
use OCP\IGroupManager;
3233
use Test\TestCase;
3334

3435
class BaseTest extends TestCase {
3536

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

40+
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
41+
protected $groupManager;
42+
3943
/** @var IProvider|Base|\PHPUnit_Framework_MockObject_MockObject */
4044
protected $provider;
4145

4246
protected function setUp() {
4347
parent::setUp();
4448
$this->userManager = $this->createMock(IUserManager::class);
49+
$this->groupManager = $this->createMock(IGroupManager::class);
4550
$this->provider = $this->getMockBuilder(Base::class)
4651
->setConstructorArgs([
47-
$this->userManager
52+
$this->userManager,
53+
$this->groupManager
4854
])
4955
->setMethods(['parse'])
5056
->getMock();

apps/files_sharing/lib/Activity/Providers/Groups.php

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
namespace OCA\Files_Sharing\Activity\Providers;
2525

2626
use OCP\Activity\IEvent;
27+
use OCP\Activity\IManager;
28+
use OCP\IGroup;
29+
use OCP\IGroupManager;
30+
use OCP\IURLGenerator;
31+
use OCP\IUserManager;
32+
use OCP\L10N\IFactory;
2733

2834
class Groups extends Base {
2935

@@ -32,6 +38,24 @@ class Groups extends Base {
3238
const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
3339
const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by';
3440

41+
/** @var IGroupManager */
42+
protected $groupManager;
43+
44+
/** @var string[] */
45+
protected $groupDisplayNames = [];
46+
47+
/**
48+
* @param IFactory $languageFactory
49+
* @param IURLGenerator $url
50+
* @param IManager $activityManager
51+
* @param IUserManager $userManager
52+
* @param IGroupManager $groupManager
53+
*/
54+
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager) {
55+
parent::__construct($languageFactory, $url, $activityManager, $userManager);
56+
$this->groupManager = $groupManager;
57+
}
58+
3559
/**
3660
* @param IEvent $event
3761
* @return IEvent
@@ -103,24 +127,44 @@ protected function getParsedParameters(IEvent $event) {
103127
case self::SUBJECT_UNSHARED_GROUP_BY:
104128
return [
105129
'file' => $this->getFile($parameters[0], $event),
106-
'group' => [
107-
'type' => 'group',
108-
'id' => $parameters[2],
109-
'name' => $parameters[2],
110-
],
130+
'group' => $this->generateGroupParameter($parameters[2]),
111131
'actor' => $this->getUser($parameters[1]),
112132
];
113133
case self::SUBJECT_SHARED_GROUP_SELF:
114134
case self::SUBJECT_UNSHARED_GROUP_SELF:
115135
return [
116136
'file' => $this->getFile($parameters[0], $event),
117-
'group' => [
118-
'type' => 'group',
119-
'id' => $parameters[1],
120-
'name' => $parameters[1],
121-
],
137+
'group' => $this->generateGroupParameter($parameters[1]),
122138
];
123139
}
124140
return [];
125141
}
142+
143+
/**
144+
* @param string $gid
145+
* @return array
146+
*/
147+
protected function generateGroupParameter($gid) {
148+
if (!isset($this->groupDisplayNames[$gid])) {
149+
$this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid);
150+
}
151+
152+
return [
153+
'type' => 'group',
154+
'id' => $gid,
155+
'name' => $this->groupDisplayNames[$gid],
156+
];
157+
}
158+
159+
/**
160+
* @param string $gid
161+
* @return string
162+
*/
163+
protected function getGroupDisplayName($gid) {
164+
$group = $this->groupManager->get($gid);
165+
if ($group instanceof IGroup) {
166+
return $group->getDisplayName();
167+
}
168+
return $gid;
169+
}
126170
}

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,10 @@ public function getUserSubAdminGroups(string $userId): DataResponse {
790790
}
791791

792792
// Get the subadmin groups
793-
$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
794-
foreach ($groups as $key => $group) {
795-
$groups[$key] = $group->getGID();
793+
$subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
794+
$groups = [];
795+
foreach ($subAdminGroups as $key => $group) {
796+
$groups[] = $group->getGID();
796797
}
797798

798799
if(!$groups) {

apps/workflowengine/js/admin.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
message: '',
150150
errorMessage: '',
151151
saving: false,
152+
groups: [],
152153
initialize: function() {
153154
// this creates a new copy of the object to definitely have a new reference and being able to reset the model
154155
this.originalModel = JSON.parse(JSON.stringify(this.model));
@@ -161,6 +162,25 @@
161162
if (this.model.get('id') === undefined) {
162163
this.hasChanged = true;
163164
}
165+
var self = this;
166+
$.ajax({
167+
url: OC.generateUrl('settings/users/groups'),
168+
dataType: 'json',
169+
quietMillis: 100,
170+
}).success(function(response) {
171+
// add admin groups
172+
$.each(response.data.adminGroups, function(id, group) {
173+
self.groups.push({ id: group.id, displayname: group.name });
174+
});
175+
// add groups
176+
$.each(response.data.groups, function(id, group) {
177+
self.groups.push({ id: group.id, displayname: group.name });
178+
});
179+
self.render();
180+
}).error(function(data) {
181+
OC.Notification.error(t('workflowengine', 'Unable to retrieve the group list'), {type: 'error'});
182+
console.log(data);
183+
});
164184
},
165185
delete: function() {
166186
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
@@ -304,10 +324,11 @@
304324
id = $element.data('id'),
305325
check = checks[id],
306326
valueElement = $element.find('.check-value').first();
327+
var self = this;
307328

308329
_.each(OCA.WorkflowEngine.availablePlugins, function(plugin) {
309330
if (_.isFunction(plugin.render)) {
310-
plugin.render(valueElement, check);
331+
plugin.render(valueElement, check, self.groups);
311332
}
312333
});
313334
}, this);

0 commit comments

Comments
 (0)