27
31
use Xibo\Factory\PermissionFactory;
28
32
use Xibo\Factory\UserFactory;
29
33
use Xibo\Factory\UserGroupFactory;
30
use Xibo\Helper\ByteFormatter;
31
use Xibo\Service\ConfigServiceInterface;
32
use Xibo\Service\DateServiceInterface;
33
use Xibo\Service\LogServiceInterface;
34
use Xibo\Service\SanitizerServiceInterface;
38
* @package Xibo\Controller
37
use Xibo\Helper\Sanitize;
40
40
class UserGroup extends Base
43
* @var UserGroupFactory
45
private $userGroupFactory;
53
* @var PermissionFactory
55
private $permissionFactory;
63
* Set common dependencies.
64
* @param LogServiceInterface $log
65
* @param SanitizerServiceInterface $sanitizerService
66
* @param \Xibo\Helper\ApplicationState $state
67
* @param \Xibo\Entity\User $user
68
* @param \Xibo\Service\HelpServiceInterface $help
69
* @param DateServiceInterface $date
70
* @param ConfigServiceInterface $config
71
* @param UserGroupFactory $userGroupFactory
72
* @param PageFactory $pageFactory
73
* @param PermissionFactory $permissionFactory
74
* @param UserFactory $userFactory
76
public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $userGroupFactory, $pageFactory, $permissionFactory, $userFactory)
78
$this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config);
80
$this->userGroupFactory = $userGroupFactory;
81
$this->pageFactory = $pageFactory;
82
$this->permissionFactory = $permissionFactory;
83
$this->userFactory = $userFactory;
87
43
* Display page logic
89
45
function displayPage()
48
if ($this->getSession()->get(get_class(), 'Filter') == 1) {
50
$filter_name = $this->getSession()->get(get_class(), 'filter_name');
58
'filterPinned' => $filter_pinned,
59
'name' => $filter_name
91
63
$this->getState()->template = 'usergroup-page';
64
$this->getState()->setData($data);
98
* operationId="userGroupSearch",
100
* summary="UserGroup Search",
101
* description="Search User Groups",
103
* name="userGroupId",
105
* description="Filter by UserGroup Id",
112
* description="Filter by UserGroup Name",
118
* description="successful operation",
121
* @SWG\Items(ref="#/definitions/UserGroup")
72
$user = $this->getUser();
74
$this->getSession()->set(get_class(), 'Filter', Sanitize::getCheckbox('XiboFilterPinned', 0));
129
'groupId' => $this->getSanitizer()->getInt('userGroupId'),
130
'group' => $this->getSanitizer()->getString('userGroup')
77
'group' => $this->getSession()->set(get_class(), 'filter_name', Sanitize::getString('filter_name'))
133
$groups = $this->userGroupFactory->query($this->gridRenderSort(), $this->gridRenderFilter($filterBy));
80
$groups = UserGroupFactory::query($this->gridRenderSort(), $this->gridRenderFilter($filterBy));
135
82
foreach ($groups as $group) {
136
83
/* @var \Xibo\Entity\UserGroup $group */
138
$group->libraryQuotaFormatted = ByteFormatter::format($group->libraryQuota * 1024);
143
85
// we only want to show certain buttons, depending on the user logged in
144
if ($this->isEditable($group)) {
86
if ($user->getUserTypeId() == 1) {
146
88
$group->buttons[] = array(
147
89
'id' => 'usergroup_button_edit',
149
91
'text' => __('Edit')
152
if ($this->getUser()->isSuperAdmin()) {
154
$group->buttons[] = array(
155
'id' => 'usergroup_button_delete',
156
'url' => $this->urlFor('group.delete.form', ['id' => $group->groupId]),
157
'text' => __('Delete')
160
$group->buttons[] = ['divider' => true];
163
$group->buttons[] = array(
164
'id' => 'usergroup_button_copy',
165
'url' => $this->urlFor('group.copy.form', ['id' => $group->groupId]),
169
$group->buttons[] = ['divider' => true];
95
$group->buttons[] = array(
96
'id' => 'usergroup_button_delete',
97
'url' => $this->urlFor('group.delete.form', ['id' => $group->groupId]),
98
'text' => __('Delete')
101
$group->buttons[] = ['divider' => true];
104
$group->buttons[] = array(
105
'id' => 'usergroup_button_copy',
106
'url' => $this->urlFor('group.copy.form', ['id' => $group->groupId]),
110
$group->buttons[] = ['divider' => true];
173
113
$group->buttons[] = array(
176
116
'text' => __('Members')
179
if ($this->getUser()->isSuperAdmin()) {
181
$group->buttons[] = array(
182
'id' => 'usergroup_button_page_security',
183
'url' => $this->urlFor('group.acl.form', ['id' => $group->groupId]),
184
'text' => __('Page Security')
120
$group->buttons[] = array(
121
'id' => 'usergroup_button_page_security',
122
'url' => $this->urlFor('group.acl.form', ['id' => $group->groupId]),
123
'text' => __('Page Security')
190
128
$this->getState()->template = 'grid';
191
$this->getState()->recordsTotal = $this->userGroupFactory->countLast();
129
$this->getState()->recordsTotal = UserGroupFactory::countLast();
192
130
$this->getState()->setData($groups);
255
if (!$this->getUser()->isSuperAdmin())
256
throw new AccessDeniedException();
258
192
// Build a user entity and save it
259
$group = $this->userGroupFactory->createEmpty();
260
$group->group = $this->getSanitizer()->getString('group');
261
$group->libraryQuota = $this->getSanitizer()->getInt('libraryQuota');
263
if ($this->getUser()->userTypeId == 1) {
264
$group->isSystemNotification = $this->getSanitizer()->getCheckbox('isSystemNotification');
265
$group->isDisplayNotification = $this->getSanitizer()->getCheckbox('isDisplayNotification');
193
$group = new \Xibo\Entity\UserGroup();
194
$group->group = Sanitize::getString('group');
195
$group->libraryQuota = Sanitize::getInt('libraryQuota');
283
212
function edit($groupId)
286
if (!$this->getUser()->isSuperAdmin() && !$this->getUser()->isGroupAdmin())
287
throw new AccessDeniedException();
289
$group = $this->userGroupFactory->getById($groupId);
291
if (!$this->isEditable($group))
292
throw new AccessDeniedException();
296
$group->group = $this->getSanitizer()->getString('group');
297
$group->libraryQuota = $this->getSanitizer()->getInt('libraryQuota');
299
if ($this->getUser()->userTypeId == 1) {
300
$group->isSystemNotification = $this->getSanitizer()->getCheckbox('isSystemNotification');
301
$group->isDisplayNotification = $this->getSanitizer()->getCheckbox('isDisplayNotification');
214
$group = UserGroupFactory::getById($groupId);
216
if (!$this->getUser()->checkEditable($group))
217
throw new AccessDeniedException();
219
$group->group = Sanitize::getString('group');
220
$group->libraryQuota = Sanitize::getInt('libraryQuota');
344
258
public function aclForm($groupId)
346
260
// Check permissions to this function
347
if (!$this->getUser()->isSuperAdmin())
261
if ($this->getUser()->userTypeId != 1)
348
262
throw new AccessDeniedException();
350
264
// Use the factory to get all the entities
351
$entities = $this->pageFactory->query();
265
$entities = PageFactory::query();
353
267
// Load the Group we are working on
354
268
// Get the object
355
269
if ($groupId == 0)
356
270
throw new \InvalidArgumentException(__('ACL form requested without a User Group'));
358
$group = $this->userGroupFactory->getById($groupId);
272
$group = UserGroupFactory::getById($groupId);
360
274
// Get all permissions for this user and this object
361
$permissions = $this->permissionFactory->getByGroupId('Page', $groupId);
275
$permissions = PermissionFactory::getByGroupId('Page', $groupId);
363
277
$checkboxes = array();
414
328
if ($groupId == 0)
415
329
throw new \InvalidArgumentException(__('ACL form requested without a User Group'));
417
$group = $this->userGroupFactory->getById($groupId);
331
$group = UserGroupFactory::getById($groupId);
419
333
// Use the factory to get all the entities
420
$entities = $this->pageFactory->query();
334
$entities = PageFactory::query();
422
336
// Get all permissions for this user and this object
423
$permissions = $this->permissionFactory->getByGroupId('Page', $groupId);
424
$objectIds = $this->getSanitizer()->getParam('objectId', null);
337
$permissions = PermissionFactory::getByGroupId('Page', $groupId);
338
$objectIds = $this->getApp()->request()->params('objectId');
426
340
if (!is_array($objectIds))
341
throw new \InvalidArgumentException(__('Missing New ACL'));
429
343
$newAcl = array();
430
344
array_map(function ($string) use (&$newAcl) {
453
367
if ($permission == null) {
455
369
// Not currently assigned and needs to be
456
$permission = $this->permissionFactory->create($groupId, get_class($page), $objectId, 1, 0, 0);
370
$permission = PermissionFactory::create($groupId, get_class($page), $objectId, 1, 0, 0);
457
371
$permission->save();
461
$this->getLog()->debug('Permission Exists for %s, and has been set to %d.', $page->getName(), $view);
375
Log::debug('Permission Exists for %s, and has been set to %d.', $page->getName(), $view);
462
376
// Currently assigned
464
378
$permission->view = 1;
484
398
public function membersForm($groupId)
486
$group = $this->userGroupFactory->getById($groupId);
400
$group = UserGroupFactory::getById($groupId);
488
if (!$this->isEditable($group))
402
if (!$this->getUser()->checkEditable($group))
489
403
throw new AccessDeniedException();
491
405
// Users in group
492
$usersAssigned = $this->userFactory->query(null, array('groupIds' => array($groupId)));
406
$usersAssigned = UserFactory::query(null, array('groupIds' => array($groupId)));
494
408
// Users not in group
495
$allUsers = $this->userFactory->query();
409
$allUsers = UserFactory::query();
497
411
// The available users are all users except users already in assigned users
498
412
$checkboxes = array();
534
448
public function assignUser($groupId)
536
$this->getLog()->debug('Assign User for groupId %d', $groupId);
538
$group = $this->userGroupFactory->getById($groupId);
540
if (!$this->isEditable($group))
450
Log::debug('Assign User for groupId %d', $groupId);
452
$group = UserGroupFactory::getById($groupId);
454
if (!$this->getUser()->checkEditable($group))
541
455
throw new AccessDeniedException();
543
$users = $this->getSanitizer()->getIntArray('userId');
457
$users = Sanitize::getIntArray('userId');
545
459
foreach ($users as $userId) {
547
$this->getLog()->debug('Assign User %d for groupId %d', $userId, $groupId);
461
Log::debug('Assign User %d for groupId %d', $userId, $groupId);
549
$user = $this->userFactory->getById($userId);
463
$user = UserFactory::getById($userId);
551
465
if (!$this->getUser()->checkViewable($user))
552
466
throw new AccessDeniedException(__('Access Denied to User'));
557
471
// Check to see if unassign has been provided.
558
$users = $this->getSanitizer()->getIntArray('unassignUserId');
472
$users = Sanitize::getIntArray('unassignUserId');
560
474
foreach ($users as $userId) {
562
$this->getLog()->debug('Unassign User %d for groupId %d', $userId, $groupId);
476
Log::debug('Unassign User %d for groupId %d', $userId, $groupId);
564
$user = $this->userFactory->getById($userId);
478
$user = UserFactory::getById($userId);
566
480
if (!$this->getUser()->checkViewable($user))
567
481
throw new AccessDeniedException(__('Access Denied to User'));
585
499
public function unassignUser($groupId)
587
$group = $this->userGroupFactory->getById($groupId);
501
$group = UserGroupFactory::getById($groupId);
589
if (!$this->isEditable($group))
503
if (!$this->getUser()->checkEditable($group))
590
504
throw new AccessDeniedException();
592
$users = $this->getSanitizer()->getIntArray('userId');
506
$users = Sanitize::getIntArray('userId');
594
508
foreach ($users as $userId) {
595
$group->unassignUser($this->userFactory->getById($userId));
509
$group->unassignUser(UserFactory::getById($userId));
598
$group->save(['validate' => false]);
601
515
$this->getState()->hydrate([
666
580
public function copy($userGroupId)
668
$group = $this->userGroupFactory->getById($userGroupId);
582
$group = UserGroupFactory::getById($userGroupId);
670
584
// Check we have permission to view this group
671
if (!$this->isEditable($group))
585
if (!$this->getUser()->checkViewable($group))
672
586
throw new AccessDeniedException();
674
588
// Clone the group
676
'loadUsers' => ($this->getSanitizer()->getCheckbox('copyMembers') == 1)
590
'loadUsers' => (Sanitize::getCheckbox('copyMembers') == 1)
678
592
$newGroup = clone $group;
679
$newGroup->group = $this->getSanitizer()->getString('group');
593
$newGroup->group = Sanitize::getString('group');
680
594
$newGroup->save();
682
596
// Copy permissions
683
foreach ($this->permissionFactory->getByGroupId('Page', $group->groupId) as $permission) {
597
foreach (PermissionFactory::getByGroupId('Page', $group->groupId) as $permission) {
684
598
/* @var Permission $permission */
685
599
$permission = clone $permission;
686
600
$permission->groupId = $newGroup->groupId;