/
groups.php
134 lines (115 loc) · 3.95 KB
/
groups.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
namespace Concrete\Controller\SinglePage\Dashboard\Users;
use Concrete\Core\Page\Controller\DashboardPageController;
use Concrete\Controller\Search\Groups as SearchGroupsController;
use Permissions;
use Group;
use Exception;
use Concrete\Core\User\User;
use Loader;
use Concrete\Core\Tree\Type\Group as GroupTree;
use Page;
class Groups extends DashboardPageController
{
public function view()
{
$tree = GroupTree::get();
$this->set('tree', $tree);
$this->requireAsset('core/groups');
$cnt = $this->app->make(SearchGroupsController::class);
$cnt->search();
$this->set('searchController', $cnt);
$c = Page::getByPath('/dashboard/users/add_group');
$cp = new Permissions($c);
$this->set('canAddGroup', $cp->canViewPage());
}
public function edit($gID = false)
{
$g = Group::getByID(intval($gID));
$gp = new Permissions($g);
if (!is_object($g)) {
throw new \Exception(t('Invalid group.'));
}
if (!$gp->canEditGroup()) {
throw new \Exception(t('You do not have access to edit this group.'));
}
if (is_object($g)) {
$this->set('group', $g);
}
}
public function bulk_update_complete()
{
$this->set('success', t('Groups moved successfully.'));
$this->view();
}
public function update_group()
{
$g = Group::getByID(intval($_REQUEST['gID']));
if (is_object($g)) {
$this->set('group', $g);
}
$gp = new Permissions($g);
if (!$gp->canEditGroup()) {
$this->error->add(t('You do not have access to edit this group.'));
}
$txt = Loader::helper('text');
$valt = Loader::helper('validation/token');
$gName = $txt->sanitize($_POST['gName']);
$gDescription = $_POST['gDescription'];
if (!$gName) {
$this->error->add(t("Name required."));
}
if (!$valt->validate('add_or_update_group')) {
$this->error->add($valt->getErrorMessage());
}
if ($_POST['gIsBadge']) {
if (!$this->post('gBadgeDescription')) {
$this->error->add(t('You must specify a description for this badge. It will be displayed publicly.'));
}
}
if (!$this->error->has()) {
$g->update($gName, $_POST['gDescription']);
$cntp = Page::getByPath('/dashboard/users/add_group');
$cnta = $cntp->getController();
$cnta->checkExpirationOptions($g);
$cnta->checkBadgeOptions($g);
$cnta->checkAutomationOptions($g);
$this->redirect('/dashboard/users/groups', 'group_updated');
}
}
public function group_added()
{
$this->set('message', t('Group added successfully'));
$this->view();
}
public function group_updated()
{
$this->set('message', t('Group update successfully'));
$this->view();
}
public function delete($delGroupId, $token = '')
{
$u = $this->app->make(User::class);
try {
if (!$u->isSuperUser()) {
throw new Exception(t('You do not have permission to perform this action.'));
}
$group = Group::getByID($delGroupId);
if (!($group instanceof Group)) {
throw new Exception(t('Invalid group ID.'));
}
$valt = Loader::helper('validation/token');
if (!$valt->validate('delete_group_' . $delGroupId, $token)) {
throw new Exception($valt->getErrorMessage());
}
if ($group->delete() === false) {
throw new Exception(t("This group can't be deleted"));
}
$resultMsg = t('Group deleted successfully.');
$this->set('message', $resultMsg);
} catch (Exception $e) {
$this->error->add($e);
}
$this->view();
}
}