/
permissions.php
112 lines (94 loc) · 3.5 KB
/
permissions.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
<?php
namespace Concrete\Controller\SinglePage\Dashboard\Boards;
use Concrete\Core\Board\Permissions\PermissionsManager;
use Concrete\Core\Entity\Board\Board;
use Concrete\Core\Page\Controller\DashboardSitePageController;
use Concrete\Core\Permission\Access\Access;
use Concrete\Core\Permission\Checker;
use Concrete\Core\Permission\Key\Key;
class Permissions extends DashboardSitePageController
{
public function update_permissions_inheritance()
{
$board = $this->getBoard($this->request->request->get('boardID'));
if (!$this->token->validate('update_permissions_inheritance')) {
$this->error->add($this->token->getErrorMessage());
}
if (!is_object($board)) {
$this->error->add(t('Invalid board.'));
}
$cp = new \Permissions($board);
if (!$cp->canEditBoardPermissions()) {
$this->error->add(t('Access Denied.'));
}
if (!$this->error->has()) {
$override = $this->request->request->get('update_inheritance') == 'override' ? true : false;
$manager = new PermissionsManager($this->entityManager);
if ($override) {
$manager->setPermissionsToOverride($board);
} else {
$manager->clearCustomPermissions($board);
}
$this->flash('success', t('Permissions updated successfully.'));
$this->redirect('/dashboard/boards/permissions', 'view', $board->getBoardID());
} else {
$this->view($this->request->request->get('boardID'));
}
}
public function save_permissions()
{
if (!$this->token->validate('save_permissions')) {
$this->error->add($this->token->getErrorMessage());
}
$board = $this->getBoard($this->request->request->get('boardID'));
if (!is_object($board)) {
$this->error->add(t('Invalid board.'));
}
$cp = new \Permissions($board);
if (!$cp->canEditBoardPermissions()) {
$this->error->add(t('Access Denied.'));
}
if (!$this->error->has()) {
$permissions = Key::getList('board');
foreach ($permissions as $pk) {
$pk->setPermissionObject($board);
$paID = $_POST['pkID'][$pk->getPermissionKeyID()];
$pt = $pk->getPermissionAssignmentObject();
$pt->clearPermissionAssignment();
if ($paID > 0) {
$pa = Access::getByID($paID, $pk);
if (is_object($pa)) {
$pt->assignPermissionAccess($pa);
}
}
}
$this->flash('success', t('Permissions saved successfully.'));
$this->redirect('/dashboard/boards/permissions', 'view', $board->getBoardID());
}
$this->view($this->request->request->get('caID'));
}
/**
* @param $id
* @return Board
*/
protected function getBoard($id)
{
$r = $this->entityManager->getRepository(Board::class);
$board = $r->findOneByBoardID($id);
if ($board) {
$checker = new Checker($board);
if ($checker->canEditBoardPermissions()) {
return $board;
}
}
}
public function view($id = null)
{
$board = $this->getBoard($id);
if (is_object($board)) {
$this->set('board', $board);
} else {
return $this->redirect('/dashboard/boards/boards');
}
}
}