1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Enalean, 2013. All Rights Reserved. |
4
|
|
|
* |
5
|
|
|
* This file is a part of Tuleap. |
6
|
|
|
* |
7
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with Tuleap; if not, write to the Free Software |
19
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
class Project_Admin_UGroup_UGroupController_Binding extends Project_Admin_UGroup_UGroupController { |
23
|
|
|
|
24
|
|
|
private $bindOption; |
25
|
|
|
private $synchro; |
26
|
|
|
|
27
|
|
|
public function __construct(Codendi_Request $request, ProjectUGroup $ugroup, Project_Admin_UGroup_PaneInfo $pane) { |
28
|
|
|
parent::__construct($request, $ugroup); |
29
|
|
|
$this->synchro = null; |
30
|
|
|
$this->bindOption = null; |
31
|
|
|
$this->pane = $pane; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function edit_binding() { |
35
|
|
|
$source_project_id = $this->request->getValidated('source_project', 'GroupId', 0); |
36
|
|
|
$view = new Project_Admin_UGroup_View_EditBinding($this->ugroup, $this->ugroup_binding, $source_project_id); |
37
|
|
|
$this->render($view); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function edit_directory_group() { |
41
|
|
|
$pluginManager = PluginManager::instance(); |
42
|
|
|
$ldapPlugin = $pluginManager->getPluginByName('ldap'); |
43
|
|
|
$pluginPath = $this->getLDAPPath($pluginManager,$ldapPlugin); |
44
|
|
|
|
45
|
|
|
if (! $pluginPath) { |
46
|
|
|
exit_error($GLOBALS['Language']->getText('global','error'), 'No ldap plugin'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$ugroupId = $this->getUGroupIdInRequest($this->request); |
50
|
|
|
|
51
|
|
|
if (! $ugroupId) { |
52
|
|
|
exit_error( |
53
|
|
|
$GLOBALS['Language']->getText('global','error'), |
54
|
|
|
$GLOBALS['Language']->getText('project_admin_editugroup','ug_not_found') |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$ugroup_row = $this->getUGroupRow($ugroupId); |
59
|
|
|
|
60
|
|
|
if (! $ugroup_row) { |
61
|
|
|
exit_error($GLOBALS['Language']->getText('global','error'), "Cannot modify this ugroup with LDAP plugin"); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$ldapUserGroupManager = $this->setldapUserGroupManager($ldapPlugin, $ugroupId); |
65
|
|
|
$view = new Project_Admin_UGroup_View_EditDirectoryGroup($this->ugroup, $this->ugroup_binding, $ugroup_row, $ldapUserGroupManager, $pluginPath, $this->bindOption, $this->synchro); |
66
|
|
|
$this->render($view); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function setldapUserGroupManager($ldapPlugin, $ugroupId) { |
70
|
|
|
$ldapUserGroupManager = new LDAP_UserGroupManager($ldapPlugin->getLdap()); |
71
|
|
|
$ldapUserGroupManager->setGroupName($this->request->get('bind_with_group')); |
72
|
|
|
$ldapUserGroupManager->setId($ugroupId); |
73
|
|
|
|
74
|
|
|
return $ldapUserGroupManager; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function getLDAPPath($pluginManager, $ldapPlugin) { |
78
|
|
|
if ($ldapPlugin && $pluginManager->isPluginAvailable($ldapPlugin)) { |
79
|
|
|
$pluginPath = $ldapPlugin->getPluginPath(); |
80
|
|
|
} else { |
81
|
|
|
$pluginPath = null; |
82
|
|
|
} |
83
|
|
|
return $pluginPath; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
private function getUGroupIdInRequest($request) { |
87
|
|
|
$vUgroupId = new Valid_UInt('ugroup_id'); |
88
|
|
|
$vUgroupId->required(); |
89
|
|
|
if($request->valid($vUgroupId)) { |
90
|
|
|
$ugroupId = $request->get('ugroup_id'); |
91
|
|
|
} else { |
92
|
|
|
$ugroupId = null; |
93
|
|
|
} |
94
|
|
|
return $ugroupId; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
private function getUGroupRow($ugroupId) { |
98
|
|
|
$res = ugroup_db_get_ugroup($ugroupId); |
99
|
|
|
if($res && !db_error($res) && db_numrows($res) == 1) { |
100
|
|
|
$row = db_fetch_array($res); |
101
|
|
|
session_require(array('group'=>$row['group_id'],'admin_flags'=>'A')); |
102
|
|
|
if($row['group_id'] == 100) { |
103
|
|
|
$row = null; |
104
|
|
|
} |
105
|
|
|
} else { |
106
|
|
|
exit_error($GLOBALS['Language']->getText('global','error'),$GLOBALS['Language']->getText('project_admin_editugroup','ug_not_found',array($ugroupId,db_error()))); |
107
|
|
|
} |
108
|
|
|
return $row; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Display the binding pane content |
113
|
|
|
* |
114
|
|
|
* @return String |
115
|
|
|
*/ |
116
|
|
|
public function displayUgroupBinding() { |
117
|
|
|
$html = ''; |
118
|
|
|
$ugroupUpdateUsersAllowed = !$this->ugroup->isBound(); |
119
|
|
|
if ($ugroupUpdateUsersAllowed) { |
120
|
|
|
$em = EventManager::instance(); |
121
|
|
|
$em->processEvent('ugroup_table_row', array('row' => array('group_id' => $this->ugroup->getProjectId(), 'ugroup_id' => $this->ugroup->getId()), 'html' => &$html)); |
122
|
|
|
} |
123
|
|
|
return $html; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function add_binding() { |
127
|
|
|
$historyDao = new ProjectHistoryDao(); |
128
|
|
|
$projectSourceId = $this->request->getValidated('source_project', 'GroupId'); |
129
|
|
|
$sourceId = $this->request->get('source_ugroup'); |
130
|
|
|
$validSourceUgroup = $this->ugroup_manager->checkUGroupValidityByGroupId($projectSourceId, $sourceId); |
131
|
|
|
$projectSource = ProjectManager::instance()->getProject($projectSourceId); |
132
|
|
|
if ($validSourceUgroup && $projectSource->userIsAdmin()) { |
|
|
|
|
133
|
|
|
if ($this->ugroup_binding->addBinding($this->ugroup->getId(), $sourceId)) { |
134
|
|
|
$historyDao->groupAddHistory("ugroup_add_binding", $this->ugroup->getId().":".$sourceId, $this->ugroup->getProjectId()); |
135
|
|
|
$this->launchEditBindingUgroupEvent(); |
136
|
|
|
} |
137
|
|
|
} else { |
138
|
|
|
$GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('project_ugroup_binding', 'add_error')); |
139
|
|
|
} |
140
|
|
|
$this->redirect(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function remove_binding() { |
144
|
|
|
$historyDao = new ProjectHistoryDao(); |
145
|
|
|
if ($this->ugroup_binding->removeBinding($this->ugroup->getId())) { |
146
|
|
|
$historyDao->groupAddHistory("ugroup_remove_binding", $this->ugroup->getId(), $this->ugroup->getProjectId()); |
147
|
|
|
$this->launchEditBindingUgroupEvent(); |
148
|
|
|
} |
149
|
|
|
$this->redirect(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function edit_directory() { |
153
|
|
|
$ldapPlugin = $this->getLdapPlugin(); |
154
|
|
|
|
155
|
|
|
$ldapUserGroupManager = new LDAP_UserGroupManager($ldapPlugin->getLdap()); |
156
|
|
|
$ldapUserGroupManager->setGroupName($this->request->get('bind_with_group')); |
157
|
|
|
$ldapUserGroupManager->setId($this->ugroup->getId()); |
158
|
|
|
|
159
|
|
|
$btn_update = $GLOBALS['Language']->getText('plugin_ldap', 'ugroup_edit_btn_update'); |
160
|
|
|
$btn_unlink = $GLOBALS['Language']->getText('plugin_ldap', 'ugroup_edit_btn_unlink'); |
161
|
|
|
|
162
|
|
|
$vSubmit = new Valid_WhiteList('submit', array($btn_update, $btn_unlink)); |
163
|
|
|
$vSubmit->required(); |
164
|
|
|
|
165
|
|
|
if($this->request->isPost() && $this->request->valid($vSubmit)) { |
166
|
|
|
if($this->request->get('submit') == $btn_unlink) { |
167
|
|
|
$this->unlinkLDAPGroup($ldapUserGroupManager); |
168
|
|
|
} else { |
169
|
|
|
$this->linkLDAPGroup($ldapUserGroupManager); |
170
|
|
|
} |
171
|
|
|
} else { |
172
|
|
|
$this->edit_directory_group(); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
private function unlinkLDAPGroup($ldapUserGroupManager) { |
177
|
|
|
if($ldapUserGroupManager->unbindFromBindLdap()) { |
178
|
|
|
$GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_ldap', 'ugroup_manager_unlink')); |
179
|
|
|
$this->launchEditBindingUgroupEvent(); |
180
|
|
|
$this->redirect(); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
private function linkLDAPGroup($ldapUserGroupManager) { |
185
|
|
|
$vBindWithGroup = new Valid_String('bind_with_group'); |
186
|
|
|
$vBindWithGroup->required(); |
187
|
|
|
|
188
|
|
|
$this->bindOption = $this->getBindOption(); |
189
|
|
|
$this->synchro = $this->getSynchro(); |
190
|
|
|
|
191
|
|
|
if($this->request->valid($vBindWithGroup)) { |
192
|
|
|
|
193
|
|
|
if($this->request->existAndNonEmpty('confirm')) { |
194
|
|
|
// |
195
|
|
|
// Perform ProjectUGroup <-> LDAP Group synchro |
196
|
|
|
// |
197
|
|
|
$ldapUserGroupManager->bindWithLdap($this->bindOption, $this->synchro); |
198
|
|
|
$GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('project_ugroup_binding', 'link_ldap_group', array($this->request->get('bind_with_group')))); |
199
|
|
|
$this->launchEditBindingUgroupEvent(); |
200
|
|
|
$this->redirect(); |
201
|
|
|
|
202
|
|
|
} elseif($this->request->exist('cancel')) { |
203
|
|
|
// Display the screen below! |
204
|
|
|
continue; |
205
|
|
|
|
206
|
|
|
} else { |
207
|
|
|
if ($ldapUserGroupManager->getGroupDn()) { |
208
|
|
|
$view = new Project_Admin_UGroup_View_UGroupAction($this->ugroup, $this->ugroup_binding, $ldapUserGroupManager, $this->request, $this->bindOption, $this->synchro); |
209
|
|
|
$this->render($view); |
210
|
|
|
} else { |
211
|
|
|
$GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('project_ugroup_binding', 'ldap_group_error', array($this->request->get('bind_with_group')))); |
212
|
|
|
$this->edit_directory_group($this->bindOption, $this->synchro); |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
} else { |
216
|
|
|
$GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('project_ugroup_binding', 'ldap_group_empty')); |
217
|
|
|
$this->edit_directory_group(); |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
protected function getLdapPlugin() { |
223
|
|
|
return PluginManager::instance()->getPluginByName('ldap'); |
224
|
|
|
|
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
private function getSynchro() { |
228
|
|
|
$synchro = LDAP_GroupManager::NO_SYNCHRONIZATION; |
229
|
|
|
if ($this->request->existAndNonEmpty('synchronize')) { |
230
|
|
|
$synchro = LDAP_GroupManager::AUTO_SYNCHRONIZATION; |
231
|
|
|
} |
232
|
|
|
return $synchro; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
private function getBindOption() { |
236
|
|
|
$bindOption = LDAP_GroupManager::BIND_OPTION; |
237
|
|
|
if($this->request->exist('preserve_members') && $this->request->get('preserve_members') == 'on') { |
238
|
|
|
$bindOption = LDAP_GroupManager::PRESERVE_MEMBERS_OPTION; |
239
|
|
|
} |
240
|
|
|
return $bindOption; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
private function launchEditBindingUgroupEvent() { |
244
|
|
|
$event_manager = EventManager::instance(); |
245
|
|
|
$event_manager->processEvent('project_admin_ugroup_bind_modified', |
246
|
|
|
array( |
247
|
|
|
'group_id' => $this->ugroup->getProjectId(), |
248
|
|
|
'ugroup_id' => $this->ugroup->getId() |
249
|
|
|
) |
250
|
|
|
); |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.