1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Jitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) Jitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jitamin\Http\Controllers\Manage; |
13
|
|
|
|
14
|
|
|
use Jitamin\Foundation\Exceptions\AccessForbiddenException; |
15
|
|
|
use Jitamin\Foundation\Security\Role; |
16
|
|
|
use Jitamin\Http\Controllers\Controller; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Project Permission Controller. |
20
|
|
|
*/ |
21
|
|
|
class ProjectPermissionController extends Controller |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Show all permissions. |
25
|
|
|
* |
26
|
|
|
* @param array $values |
27
|
|
|
* @param array $errors |
28
|
|
|
* |
29
|
|
|
* @throws AccessForbiddenException |
30
|
|
|
*/ |
31
|
|
|
public function index(array $values = [], array $errors = []) |
32
|
|
|
{ |
33
|
|
|
$project = $this->getProject(); |
34
|
|
|
|
35
|
|
|
if (empty($values)) { |
36
|
|
|
$values['role'] = Role::PROJECT_MEMBER; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$this->response->html($this->helper->layout->project('manage/project_permission/index', [ |
|
|
|
|
40
|
|
|
'project' => $project, |
41
|
|
|
'users' => $this->projectUserRoleModel->getUsers($project['id']), |
|
|
|
|
42
|
|
|
'groups' => $this->projectGroupRoleModel->getGroups($project['id']), |
|
|
|
|
43
|
|
|
'roles' => $this->projectRoleModel->getList($project['id']), |
|
|
|
|
44
|
|
|
'values' => $values, |
45
|
|
|
'errors' => $errors, |
46
|
|
|
'title' => t('Project Permissions'), |
47
|
|
|
])); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Allow everybody. |
52
|
|
|
*/ |
53
|
|
|
public function allowEverybody() |
54
|
|
|
{ |
55
|
|
|
$project = $this->getProject(); |
56
|
|
|
$values = $this->request->getValues() + ['is_everybody_allowed' => 0]; |
|
|
|
|
57
|
|
|
|
58
|
|
|
if ($this->projectModel->update($values)) { |
|
|
|
|
59
|
|
|
$this->flash->success(t('Project updated successfully.')); |
|
|
|
|
60
|
|
|
} else { |
61
|
|
|
$this->flash->failure(t('Unable to update this project.')); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->response->redirect($this->helper->url->to('Manage/ProjectPermissionController', 'index', ['project_id' => $project['id']])); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Add user to the project. |
69
|
|
|
*/ |
70
|
|
|
public function addUser() |
71
|
|
|
{ |
72
|
|
|
$project = $this->getProject(); |
73
|
|
|
$values = $this->request->getValues(); |
|
|
|
|
74
|
|
|
|
75
|
|
View Code Duplication |
if (empty($values['user_id'])) { |
|
|
|
|
76
|
|
|
$this->flash->failure(t('User not found.')); |
|
|
|
|
77
|
|
|
} elseif ($this->projectUserRoleModel->addUser($values['project_id'], $values['user_id'], $values['role'])) { |
|
|
|
|
78
|
|
|
$this->flash->success(t('Project updated successfully.')); |
|
|
|
|
79
|
|
|
} else { |
80
|
|
|
$this->flash->failure(t('Unable to update this project.')); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->response->redirect($this->helper->url->to('Manage/ProjectPermissionController', 'index', ['project_id' => $project['id']])); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Revoke user access. |
88
|
|
|
*/ |
89
|
|
View Code Duplication |
public function removeUser() |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
$project = $this->getProject(); |
92
|
|
|
$values = $this->request->getValues(); |
|
|
|
|
93
|
|
|
|
94
|
|
|
$user = $this->projectUserRoleModel->getRemoveUser($values['project_id'], $values['user_id']); |
|
|
|
|
95
|
|
|
|
96
|
|
|
if ($this->request->isPost()) { |
|
|
|
|
97
|
|
|
$this->request->checkCSRFToken(); |
|
|
|
|
98
|
|
|
if ($this->projectUserRoleModel->removeUser($project['id'], $user['id'])) { |
|
|
|
|
99
|
|
|
$this->flash->success(t('Project updated successfully.')); |
|
|
|
|
100
|
|
|
} else { |
101
|
|
|
$this->flash->failure(t('Unable to update this project.')); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $this->response->redirect($this->helper->url->to('Manage/ProjectPermissionController', 'index', ['project_id' => $project['id']])); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $this->response->html($this->helper->layout->app('manage/project_permission/remove_user', [ |
|
|
|
|
108
|
|
|
'user' => $user, |
109
|
|
|
'project' => $project, |
110
|
|
|
])); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Change user role. |
115
|
|
|
*/ |
116
|
|
View Code Duplication |
public function changeUserRole() |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
$project = $this->getProject(); |
119
|
|
|
$values = $this->request->getJson(); |
|
|
|
|
120
|
|
|
|
121
|
|
|
if (!empty($project) && !empty($values) && $this->projectUserRoleModel->changeUserRole($project['id'], $values['id'], $values['role'])) { |
|
|
|
|
122
|
|
|
$this->response->json(['status' => 'ok']); |
|
|
|
|
123
|
|
|
} else { |
124
|
|
|
$this->response->json(['status' => 'error']); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Add group to the project. |
130
|
|
|
*/ |
131
|
|
|
public function addGroup() |
132
|
|
|
{ |
133
|
|
|
$project = $this->getProject(); |
134
|
|
|
$values = $this->request->getValues(); |
|
|
|
|
135
|
|
|
|
136
|
|
|
if (empty($values['group_id']) && !empty($values['external_id'])) { |
137
|
|
|
$values['group_id'] = $this->groupModel->getOrCreateExternalGroupId($values['name'], $values['external_id']); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
View Code Duplication |
if (!empty($values['group_id']) && $this->projectGroupRoleModel->addGroup($project['id'], $values['group_id'], $values['role'])) { |
|
|
|
|
141
|
|
|
$this->flash->success(t('Project updated successfully.')); |
|
|
|
|
142
|
|
|
} else { |
143
|
|
|
$this->flash->failure(t('Unable to update this project.')); |
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$this->response->redirect($this->helper->url->to('Manage/ProjectPermissionController', 'index', ['project_id' => $project['id']])); |
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Revoke group access. |
151
|
|
|
*/ |
152
|
|
View Code Duplication |
public function removeGroup() |
|
|
|
|
153
|
|
|
{ |
154
|
|
|
$project = $this->getProject(); |
155
|
|
|
$group_id = $this->request->getIntegerParam('group_id'); |
|
|
|
|
156
|
|
|
|
157
|
|
|
if ($this->projectGroupRoleModel->removeGroup($project['id'], $group_id)) { |
|
|
|
|
158
|
|
|
$this->flash->success(t('Project updated successfully.')); |
|
|
|
|
159
|
|
|
} else { |
160
|
|
|
$this->flash->failure(t('Unable to update this project.')); |
|
|
|
|
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
$this->response->redirect($this->helper->url->to('Manage/ProjectPermissionController', 'index', ['project_id' => $project['id']])); |
|
|
|
|
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Change group role. |
168
|
|
|
*/ |
169
|
|
View Code Duplication |
public function changeGroupRole() |
|
|
|
|
170
|
|
|
{ |
171
|
|
|
$project = $this->getProject(); |
172
|
|
|
$values = $this->request->getJson(); |
|
|
|
|
173
|
|
|
|
174
|
|
|
if (!empty($project) && !empty($values) && $this->projectGroupRoleModel->changeGroupRole($project['id'], $values['id'], $values['role'])) { |
|
|
|
|
175
|
|
|
$this->response->json(['status' => 'ok']); |
|
|
|
|
176
|
|
|
} else { |
177
|
|
|
$this->response->json(['status' => 'error']); |
|
|
|
|
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Permissions are only available for team projects. |
183
|
|
|
* |
184
|
|
|
* @param int $project_id Default project id |
185
|
|
|
* |
186
|
|
|
* @throws AccessForbiddenException |
187
|
|
|
* |
188
|
|
|
* @return array |
189
|
|
|
*/ |
190
|
|
|
protected function getProject($project_id = 0) |
191
|
|
|
{ |
192
|
|
|
$project = parent::getProject($project_id); |
193
|
|
|
|
194
|
|
|
if ($project['is_private'] == 1) { |
195
|
|
|
throw new AccessForbiddenException(); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
return $project; |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.