|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved |
|
4
|
|
|
* Copyright (c) Enalean, 2011-2015. All Rights Reserved. |
|
5
|
|
|
* |
|
6
|
|
|
* This file is a part of Tuleap. |
|
7
|
|
|
* |
|
8
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU General Public License as published by |
|
10
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with Tuleap; if not, write to the Free Software |
|
20
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
require_once 'constants.php'; |
|
24
|
|
|
require_once 'autoload.php'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* GitPlugin |
|
28
|
|
|
*/ |
|
29
|
|
|
class GitPlugin extends Plugin { |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* |
|
33
|
|
|
* @var Logger |
|
34
|
|
|
*/ |
|
35
|
|
|
private $logger; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var Git_UserAccountManager |
|
39
|
|
|
*/ |
|
40
|
|
|
private $user_account_manager; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Service short_name as it appears in 'service' table |
|
44
|
|
|
* |
|
45
|
|
|
* Should be transfered in 'ServiceGit' class when we introduce it |
|
46
|
|
|
*/ |
|
47
|
|
|
const SERVICE_SHORTNAME = 'plugin_git'; |
|
48
|
|
|
|
|
49
|
|
|
public function __construct($id) { |
|
50
|
|
|
parent::__construct($id); |
|
51
|
|
|
$this->setScope(Plugin::SCOPE_PROJECT); |
|
52
|
|
|
$this->_addHook('site_admin_option_hook', 'site_admin_option_hook', false); |
|
53
|
|
|
$this->_addHook('cssfile', 'cssFile', false); |
|
54
|
|
|
$this->_addHook('javascript_file', 'jsFile', false); |
|
55
|
|
|
$this->_addHook(Event::JAVASCRIPT, 'javascript', false); |
|
56
|
|
|
$this->_addHook(Event::GET_SYSTEM_EVENT_CLASS, 'getSystemEventClass', false); |
|
57
|
|
|
$this->_addHook(Event::GET_PLUGINS_AVAILABLE_KEYWORDS_REFERENCES, 'getReferenceKeywords', false); |
|
58
|
|
|
$this->_addHook(Event::GET_AVAILABLE_REFERENCE_NATURE, 'getReferenceNatures', false); |
|
59
|
|
|
$this->addHook(Event::GET_REFERENCE); |
|
60
|
|
|
$this->_addHook('SystemEvent_PROJECT_IS_PRIVATE', 'changeProjectRepositoriesAccess', false); |
|
61
|
|
|
$this->_addHook('SystemEvent_PROJECT_RENAME', 'systemEventProjectRename', false); |
|
62
|
|
|
$this->_addHook('project_is_deleted', 'project_is_deleted', false); |
|
63
|
|
|
$this->_addHook('file_exists_in_data_dir', 'file_exists_in_data_dir', false); |
|
64
|
|
|
$this->addHook(Event::SERVICE_ICON); |
|
65
|
|
|
$this->addHook(Event::SERVICES_ALLOWED_FOR_PROJECT); |
|
66
|
|
|
|
|
67
|
|
|
// Stats plugin |
|
68
|
|
|
$this->_addHook('plugin_statistics_disk_usage_collect_project', 'plugin_statistics_disk_usage_collect_project', false); |
|
69
|
|
|
$this->_addHook('plugin_statistics_disk_usage_service_label', 'plugin_statistics_disk_usage_service_label', false); |
|
70
|
|
|
$this->_addHook('plugin_statistics_color', 'plugin_statistics_color', false); |
|
71
|
|
|
|
|
72
|
|
|
$this->_addHook(Event::LIST_SSH_KEYS, 'getRemoteServersForUser', false); |
|
73
|
|
|
$this->_addHook(Event::DUMP_SSH_KEYS); |
|
74
|
|
|
$this->_addHook(Event::EDIT_SSH_KEYS); |
|
75
|
|
|
$this->_addHook(Event::PROCCESS_SYSTEM_CHECK); |
|
76
|
|
|
$this->_addHook(Event::SYSTEM_EVENT_GET_TYPES_FOR_DEFAULT_QUEUE); |
|
77
|
|
|
$this->_addHook(Event::SYSTEM_EVENT_GET_CUSTOM_QUEUES); |
|
78
|
|
|
$this->_addHook(Event::SYSTEM_EVENT_GET_TYPES_FOR_CUSTOM_QUEUE); |
|
79
|
|
|
|
|
80
|
|
|
$this->_addHook('permission_get_name', 'permission_get_name', false); |
|
81
|
|
|
$this->_addHook('permission_get_object_type', 'permission_get_object_type', false); |
|
82
|
|
|
$this->_addHook('permission_get_object_name', 'permission_get_object_name', false); |
|
83
|
|
|
$this->_addHook('permission_get_object_fullname', 'permission_get_object_fullname', false); |
|
84
|
|
|
$this->_addHook('permission_user_allowed_to_change', 'permission_user_allowed_to_change', false); |
|
85
|
|
|
$this->_addHook('permissions_for_ugroup', 'permissions_for_ugroup', false); |
|
86
|
|
|
|
|
87
|
|
|
$this->_addHook('statistics_collector', 'statistics_collector', false); |
|
88
|
|
|
|
|
89
|
|
|
$this->_addHook('collect_ci_triggers', 'collect_ci_triggers', false); |
|
90
|
|
|
$this->_addHook('save_ci_triggers', 'save_ci_triggers', false); |
|
91
|
|
|
$this->_addHook('update_ci_triggers', 'update_ci_triggers', false); |
|
92
|
|
|
$this->_addHook('delete_ci_triggers', 'delete_ci_triggers', false); |
|
93
|
|
|
|
|
94
|
|
|
$this->_addHook('logs_daily', 'logsDaily', false); |
|
95
|
|
|
$this->_addHook('widget_instance', 'myPageBox', false); |
|
96
|
|
|
$this->_addHook('widgets', 'widgets', false); |
|
97
|
|
|
$this->_addHook('codendi_daily_start', 'codendiDaily', false); |
|
98
|
|
|
$this->_addHook('show_pending_documents', 'showArchivedRepositories', false); |
|
99
|
|
|
|
|
100
|
|
|
$this->_addHook('SystemEvent_USER_RENAME', 'systemevent_user_rename'); |
|
101
|
|
|
|
|
102
|
|
|
// User Group membership modification |
|
103
|
|
|
$this->_addHook('project_admin_add_user'); |
|
104
|
|
|
$this->_addHook('project_admin_ugroup_add_user'); |
|
105
|
|
|
$this->_addHook('project_admin_remove_user'); |
|
106
|
|
|
$this->_addHook('project_admin_ugroup_remove_user'); |
|
107
|
|
|
$this->_addHook('project_admin_change_user_permissions'); |
|
108
|
|
|
$this->_addHook('project_admin_ugroup_deletion'); |
|
109
|
|
|
$this->_addHook('project_admin_remove_user_from_project_ugroups'); |
|
110
|
|
|
$this->_addHook('project_admin_ugroup_creation'); |
|
111
|
|
|
$this->_addHook('project_admin_parent_project_modification'); |
|
112
|
|
|
$this->_addHook(Event::UGROUP_MANAGER_UPDATE_UGROUP_BINDING_ADD); |
|
113
|
|
|
$this->_addHook(Event::UGROUP_MANAGER_UPDATE_UGROUP_BINDING_REMOVE); |
|
114
|
|
|
|
|
115
|
|
|
// Project hierarchy modification |
|
116
|
|
|
$this->_addHook(Event::PROJECT_SET_PARENT_PROJECT, 'project_admin_parent_project_modification'); |
|
117
|
|
|
$this->_addHook(Event::PROJECT_UNSET_PARENT_PROJECT, 'project_admin_parent_project_modification'); |
|
118
|
|
|
|
|
119
|
|
|
//Gerrit user synch help |
|
120
|
|
|
$this->_addHook(Event::MANAGE_THIRD_PARTY_APPS, 'manage_third_party_apps'); |
|
121
|
|
|
|
|
122
|
|
|
$this->_addHook('register_project_creation'); |
|
123
|
|
|
$this->_addHook(Event::GET_PROJECTID_FROM_URL); |
|
124
|
|
|
$this->_addHook('anonymous_access_to_script_allowed'); |
|
125
|
|
|
$this->_addHook(Event::IS_SCRIPT_HANDLED_FOR_RESTRICTED); |
|
126
|
|
|
$this->_addHook(Event::GET_SERVICES_ALLOWED_FOR_RESTRICTED); |
|
127
|
|
|
$this->_addHook(Event::PROJECT_ACCESS_CHANGE); |
|
128
|
|
|
$this->_addHook(Event::SITE_ACCESS_CHANGE); |
|
129
|
|
|
|
|
130
|
|
|
$this->_addHook('fill_project_history_sub_events'); |
|
131
|
|
|
$this->_addHook(Event::POST_SYSTEM_EVENTS_ACTIONS); |
|
132
|
|
|
|
|
133
|
|
|
$this->addHook(EVENT::REST_RESOURCES); |
|
134
|
|
|
$this->addHook(EVENT::REST_PROJECT_RESOURCES); |
|
135
|
|
|
$this->addHook(EVENT::REST_PROJECT_GET_GIT); |
|
136
|
|
|
$this->addHook(EVENT::REST_PROJECT_OPTIONS_GIT); |
|
137
|
|
|
|
|
138
|
|
|
$this->_addHook(Event::IMPORT_XML_PROJECT, 'importXmlProject', false); |
|
139
|
|
|
|
|
140
|
|
|
// Gerrit user suspension |
|
141
|
|
|
if (defined('LDAP_DAILY_SYNCHRO_UPDATE_USER')) { |
|
142
|
|
|
$this->addHook(LDAP_DAILY_SYNCHRO_UPDATE_USER); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
$this->addHook(Event::SERVICES_TRUNCATED_EMAILS); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function getServiceShortname() { |
|
149
|
|
|
return self::SERVICE_SHORTNAME; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function service_icon($params) { |
|
153
|
|
|
$params['list_of_icon_unicodes'][$this->getServiceShortname()] = '\e806'; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function site_admin_option_hook() { |
|
157
|
|
|
$url = $this->getPluginPath().'/admin/'; |
|
158
|
|
|
$name = $GLOBALS['Language']->getText('plugin_git', 'descriptor_name'); |
|
159
|
|
|
echo '<li><a href="', $url, '">', $name, '</a></li>'; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function getPluginInfo() { |
|
163
|
|
|
if (!is_a($this->pluginInfo, 'GitPluginInfo')) { |
|
164
|
|
|
$this->pluginInfo = new GitPluginInfo($this); |
|
165
|
|
|
} |
|
166
|
|
|
return $this->pluginInfo; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Returns the configuration defined for given variable name |
|
171
|
|
|
* |
|
172
|
|
|
* @param String $key |
|
173
|
|
|
* |
|
174
|
|
|
* @return Mixed |
|
175
|
|
|
*/ |
|
176
|
|
|
public function getConfigurationParameter($key) { |
|
177
|
|
|
return $this->getPluginInfo()->getPropertyValueForName($key); |
|
|
|
|
|
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function cssFile($params) { |
|
181
|
|
|
// Only show the stylesheet if we're actually in the Git pages. |
|
182
|
|
|
// This stops styles inadvertently clashing with the main site. |
|
183
|
|
|
if (strpos($_SERVER['REQUEST_URI'], $this->getPluginPath()) === 0 || |
|
184
|
|
|
strpos($_SERVER['REQUEST_URI'], '/widgets/') === 0) { |
|
185
|
|
|
echo '<link rel="stylesheet" type="text/css" href="'.$this->getThemePath().'/css/style.css" />'; |
|
186
|
|
|
echo '<link rel="stylesheet" type="text/css" href="/plugins/git/themes/default/css/gitphp.css" />'; |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function jsFile() { |
|
191
|
|
|
// Only show the javascript if we're actually in the Git pages. |
|
192
|
|
|
if (strpos($_SERVER['REQUEST_URI'], $this->getPluginPath()) === 0) { |
|
193
|
|
|
echo '<script type="text/javascript" src="'.$this->getPluginPath().'/scripts/git.js"></script>'; |
|
194
|
|
|
echo '<script type="text/javascript" src="'.$this->getPluginPath().'/scripts/online_edit.js"></script>'; |
|
195
|
|
|
echo '<script type="text/javascript" src="'.$this->getPluginPath().'/scripts/clone_url.js"></script>'; |
|
196
|
|
|
echo '<script type="text/javascript" src="'.$this->getPluginPath().'/scripts/mass-update.js"></script>'; |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function javascript($params) { |
|
201
|
|
|
include $GLOBALS['Language']->getContent('script_locale', null, 'git'); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
public function system_event_get_types_for_default_queue(array &$params) { |
|
205
|
|
|
$params['types'] = array_merge($params['types'], $this->getGitSystemEventManager()->getTypesForDefaultQueue()); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** @see Event::SYSTEM_EVENT_GET_CUSTOM_QUEUES */ |
|
209
|
|
|
public function system_event_get_custom_queues(array &$params) { |
|
210
|
|
|
$params['queues'][Git_SystemEventQueue::NAME] = new Git_SystemEventQueue($this->getLogger()); |
|
211
|
|
|
$params['queues'][Git_Mirror_MirrorSystemEventQueue::NAME] = new Git_Mirror_MirrorSystemEventQueue($this->getLogger()); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** @see Event::SYSTEM_EVENT_GET_TYPES_FOR_CUSTOM_QUEUE */ |
|
215
|
|
|
public function system_event_get_types_for_custom_queue(array &$params) { |
|
216
|
|
|
if ($params['queue'] == Git_SystemEventQueue::NAME) { |
|
217
|
|
|
$params['types'] = array_merge( |
|
218
|
|
|
$params['types'], |
|
219
|
|
|
$this->getGitSystemEventManager()->getTypes() |
|
220
|
|
|
); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
if ($params['queue'] == Git_Mirror_MirrorSystemEventQueue::NAME) { |
|
224
|
|
|
$params['types'] = array_merge( |
|
225
|
|
|
$params['types'], |
|
226
|
|
|
$this->getGitSystemEventManager()->getGrokMirrorTypes() |
|
227
|
|
|
); |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
*This callback make SystemEvent manager knows about git plugin System Events |
|
233
|
|
|
* @param <type> $params |
|
|
|
|
|
|
234
|
|
|
*/ |
|
235
|
|
|
public function getSystemEventClass($params) { |
|
236
|
|
|
switch($params['type']) { |
|
237
|
|
|
case SystemEvent_GIT_REPO_UPDATE::NAME: |
|
238
|
|
|
$params['class'] = 'SystemEvent_GIT_REPO_UPDATE'; |
|
239
|
|
|
$params['dependencies'] = array( |
|
240
|
|
|
$this->getRepositoryFactory(), |
|
241
|
|
|
$this->getSystemEventDao(), |
|
242
|
|
|
$this->getLogger(), |
|
243
|
|
|
$this->getGitSystemEventManager() |
|
244
|
|
|
); |
|
245
|
|
|
break; |
|
246
|
|
|
case SystemEvent_GIT_REPO_DELETE::NAME: |
|
247
|
|
|
$params['class'] = 'SystemEvent_GIT_REPO_DELETE'; |
|
248
|
|
|
$params['dependencies'] = array( |
|
249
|
|
|
$this->getRepositoryFactory(), |
|
250
|
|
|
$this->getLogger(), |
|
251
|
|
|
$this->getGitSystemEventManager(), |
|
252
|
|
|
); |
|
253
|
|
|
break; |
|
254
|
|
|
case SystemEvent_GIT_LEGACY_REPO_DELETE::NAME: |
|
255
|
|
|
$params['class'] = 'SystemEvent_GIT_LEGACY_REPO_DELETE'; |
|
256
|
|
|
$params['dependencies'] = array( |
|
257
|
|
|
$this->getRepositoryFactory(), |
|
258
|
|
|
$this->getManifestManager(), |
|
259
|
|
|
$this->getLogger(), |
|
260
|
|
|
); |
|
261
|
|
|
break; |
|
262
|
|
|
case SystemEvent_GIT_LEGACY_REPO_ACCESS::NAME: |
|
263
|
|
|
$params['class'] = 'SystemEvent_GIT_LEGACY_REPO_ACCESS'; |
|
264
|
|
|
break; |
|
265
|
|
|
case SystemEvent_GIT_GERRIT_MIGRATION::NAME: |
|
266
|
|
|
$params['class'] = 'SystemEvent_GIT_GERRIT_MIGRATION'; |
|
267
|
|
|
$params['dependencies'] = array( |
|
268
|
|
|
$this->getGitDao(), |
|
269
|
|
|
$this->getRepositoryFactory(), |
|
270
|
|
|
$this->getGerritServerFactory(), |
|
271
|
|
|
$this->getLogger(), |
|
272
|
|
|
$this->getProjectCreator(), |
|
273
|
|
|
$this->getGitRepositoryUrlManager(), |
|
274
|
|
|
); |
|
275
|
|
|
break; |
|
276
|
|
|
case SystemEvent_GIT_REPO_FORK::NAME: |
|
277
|
|
|
$params['class'] = 'SystemEvent_GIT_REPO_FORK'; |
|
278
|
|
|
$params['dependencies'] = array( |
|
279
|
|
|
$this->getRepositoryFactory() |
|
280
|
|
|
); |
|
281
|
|
|
break; |
|
282
|
|
|
case SystemEvent_GIT_GERRIT_ADMIN_KEY_DUMP::NAME: |
|
283
|
|
|
$params['class'] = 'SystemEvent_GIT_GERRIT_ADMIN_KEY_DUMP'; |
|
284
|
|
|
$params['dependencies'] = array( |
|
285
|
|
|
$this->getGerritServerFactory(), |
|
286
|
|
|
$this->getGitoliteSSHKeyDumper(), |
|
287
|
|
|
); |
|
288
|
|
|
break; |
|
289
|
|
|
case SystemEvent_GIT_GERRIT_PROJECT_DELETE::NAME: |
|
290
|
|
|
$params['class'] = 'SystemEvent_GIT_GERRIT_PROJECT_DELETE'; |
|
291
|
|
|
$params['dependencies'] = array( |
|
292
|
|
|
$this->getRepositoryFactory(), |
|
293
|
|
|
$this->getGerritServerFactory(), |
|
294
|
|
|
$this->getGerritDriverFactory() |
|
295
|
|
|
); |
|
296
|
|
|
break; |
|
297
|
|
|
case SystemEvent_GIT_GERRIT_PROJECT_READONLY::NAME: |
|
298
|
|
|
$params['class'] = 'SystemEvent_GIT_GERRIT_PROJECT_READONLY'; |
|
299
|
|
|
$params['dependencies'] = array( |
|
300
|
|
|
$this->getRepositoryFactory(), |
|
301
|
|
|
$this->getGerritServerFactory(), |
|
302
|
|
|
$this->getGerritDriverFactory() |
|
303
|
|
|
); |
|
304
|
|
|
break; |
|
305
|
|
|
case SystemEvent_GIT_USER_RENAME::NAME: |
|
306
|
|
|
$params['class'] = 'SystemEvent_GIT_USER_RENAME'; |
|
307
|
|
|
$params['dependencies'] = array( |
|
308
|
|
|
$this->getGitoliteSSHKeyDumper(), |
|
309
|
|
|
UserManager::instance() |
|
310
|
|
|
); |
|
311
|
|
|
break; |
|
312
|
|
|
case SystemEvent_GIT_GROKMIRROR_MANIFEST_UPDATE::NAME: |
|
313
|
|
|
$params['class'] = 'SystemEvent_GIT_GROKMIRROR_MANIFEST_UPDATE'; |
|
314
|
|
|
$params['dependencies'] = array( |
|
315
|
|
|
$this->getRepositoryFactory(), |
|
316
|
|
|
$this->getManifestManager(), |
|
317
|
|
|
); |
|
318
|
|
|
break; |
|
319
|
|
|
case SystemEvent_GIT_GROKMIRROR_MANIFEST_UPDATE_FOLLOWING_A_GIT_PUSH::NAME: |
|
320
|
|
|
$params['class'] = 'SystemEvent_GIT_GROKMIRROR_MANIFEST_UPDATE_FOLLOWING_A_GIT_PUSH'; |
|
321
|
|
|
$params['dependencies'] = array( |
|
322
|
|
|
$this->getRepositoryFactory(), |
|
323
|
|
|
$this->getManifestManager(), |
|
324
|
|
|
); |
|
325
|
|
|
break; |
|
326
|
|
|
case SystemEvent_GIT_GROKMIRROR_MANIFEST_CHECK::NAME: |
|
327
|
|
|
$params['class'] = 'SystemEvent_GIT_GROKMIRROR_MANIFEST_CHECK'; |
|
328
|
|
|
$params['dependencies'] = array( |
|
329
|
|
|
$this->getManifestManager(), |
|
330
|
|
|
); |
|
331
|
|
|
break; |
|
332
|
|
|
case SystemEvent_GIT_GROKMIRROR_MANIFEST_REPODELETE::NAME: |
|
333
|
|
|
$params['class'] = 'SystemEvent_GIT_GROKMIRROR_MANIFEST_REPODELETE'; |
|
334
|
|
|
$params['dependencies'] = array( |
|
335
|
|
|
$this->getManifestManager(), |
|
336
|
|
|
); |
|
337
|
|
|
break; |
|
338
|
|
|
case SystemEvent_GIT_EDIT_SSH_KEYS::NAME: |
|
339
|
|
|
$params['class'] = 'SystemEvent_GIT_EDIT_SSH_KEYS'; |
|
340
|
|
|
$params['dependencies'] = array( |
|
341
|
|
|
UserManager::instance(), |
|
342
|
|
|
$this->getSSHKeyDumper(), |
|
343
|
|
|
$this->getUserAccountManager(), |
|
344
|
|
|
$this->getGitSystemEventManager(), |
|
345
|
|
|
$this->getLogger() |
|
346
|
|
|
); |
|
347
|
|
|
break; |
|
348
|
|
|
case SystemEvent_GIT_DUMP_ALL_SSH_KEYS::NAME: |
|
349
|
|
|
$params['class'] = 'SystemEvent_GIT_DUMP_ALL_SSH_KEYS'; |
|
350
|
|
|
$params['dependencies'] = array( |
|
351
|
|
|
$this->getSSHKeyMassDumper(), |
|
352
|
|
|
$this->getLogger() |
|
353
|
|
|
); |
|
354
|
|
|
break; |
|
355
|
|
|
case SystemEvent_GIT_REPO_RESTORE::NAME: |
|
356
|
|
|
$params['class'] = 'SystemEvent_GIT_REPO_RESTORE'; |
|
357
|
|
|
$params['dependencies'] = array( |
|
358
|
|
|
$this->getRepositoryFactory(), |
|
359
|
|
|
$this->getGitSystemEventManager(), |
|
360
|
|
|
$this->getLogger() |
|
361
|
|
|
); |
|
362
|
|
|
break; |
|
363
|
|
|
case SystemEvent_GIT_PROJECTS_UPDATE::NAME: |
|
364
|
|
|
$params['class'] = 'SystemEvent_GIT_PROJECTS_UPDATE'; |
|
365
|
|
|
$params['dependencies'] = array( |
|
366
|
|
|
$this->getLogger(), |
|
367
|
|
|
$this->getGitSystemEventManager(), |
|
368
|
|
|
$this->getProjectManager(), |
|
369
|
|
|
$this->getGitoliteDriver(), |
|
370
|
|
|
); |
|
371
|
|
|
break; |
|
372
|
|
|
case SystemEvent_GIT_DUMP_ALL_MIRRORED_REPOSITORIES::NAME: |
|
373
|
|
|
$params['class'] = 'SystemEvent_GIT_DUMP_ALL_MIRRORED_REPOSITORIES'; |
|
374
|
|
|
$params['dependencies'] = array( |
|
375
|
|
|
$this->getGitoliteDriver() |
|
376
|
|
|
); |
|
377
|
|
|
break; |
|
378
|
|
|
case SystemEvent_GIT_UPDATE_MIRROR::NAME: |
|
379
|
|
|
$params['class'] = 'SystemEvent_GIT_UPDATE_MIRROR'; |
|
380
|
|
|
$params['dependencies'] = array( |
|
381
|
|
|
$this->getGitoliteDriver() |
|
382
|
|
|
); |
|
383
|
|
|
break; |
|
384
|
|
|
case SystemEvent_GIT_DELETE_MIRROR::NAME: |
|
385
|
|
|
$params['class'] = 'SystemEvent_GIT_DELETE_MIRROR'; |
|
386
|
|
|
$params['dependencies'] = array( |
|
387
|
|
|
$this->getGitoliteDriver() |
|
388
|
|
|
); |
|
389
|
|
|
break; |
|
390
|
|
|
default: |
|
391
|
|
|
break; |
|
392
|
|
|
} |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
|
|
private function getTemplateFactory() { |
|
396
|
|
|
return new Git_Driver_Gerrit_Template_TemplateFactory(new Git_Driver_Gerrit_Template_TemplateDao()); |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
private function getSystemEventDao() { |
|
400
|
|
|
return new SystemEventDao(); |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
public function getReferenceKeywords($params) { |
|
404
|
|
|
$params['keywords'] = array_merge( |
|
405
|
|
|
$params['keywords'], |
|
406
|
|
|
array(Git::REFERENCE_KEYWORD) |
|
407
|
|
|
); |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
public function getReferenceNatures($params) { |
|
411
|
|
|
$params['natures'] = array_merge( |
|
412
|
|
|
$params['natures'], |
|
413
|
|
|
array( |
|
414
|
|
|
Git::REFERENCE_NATURE => array( |
|
415
|
|
|
'keyword' => Git::REFERENCE_KEYWORD, |
|
416
|
|
|
'label' => $GLOBALS['Language']->getText('plugin_git', 'reference_commit_nature_key') |
|
417
|
|
|
) |
|
418
|
|
|
) |
|
419
|
|
|
); |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
public function get_reference($params) { |
|
423
|
|
|
if ($params['keyword'] == Git::REFERENCE_KEYWORD) { |
|
424
|
|
|
$reference = false; |
|
425
|
|
|
if ($params['project']) { |
|
426
|
|
|
$git_reference_manager = new Git_ReferenceManager( |
|
427
|
|
|
$this->getRepositoryFactory(), |
|
428
|
|
|
$params['reference_manager'] |
|
429
|
|
|
); |
|
430
|
|
|
$reference = $git_reference_manager->getReference( |
|
431
|
|
|
$params['project'], |
|
432
|
|
|
$params['keyword'], |
|
433
|
|
|
$params['value'] |
|
434
|
|
|
); |
|
435
|
|
|
} |
|
436
|
|
|
$params['reference'] = $reference; |
|
437
|
|
|
} |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
public function changeProjectRepositoriesAccess($params) { |
|
441
|
|
|
$groupId = $params[0]; |
|
442
|
|
|
$isPrivate = $params[1]; |
|
443
|
|
|
$dao = new GitDao(); |
|
444
|
|
|
$factory = $this->getRepositoryFactory(); |
|
445
|
|
|
GitActions::changeProjectRepositoriesAccess($groupId, $isPrivate, $dao, $factory); |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
public function systemEventProjectRename($params) { |
|
449
|
|
|
GitActions::renameProject($params['project'], $params['new_name']); |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
public function file_exists_in_data_dir($params) { |
|
453
|
|
|
$params['result'] = $this->isNameAvailable($params['new_name'], $params['error']); |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
private function isNameAvailable($newName, &$error) { |
|
457
|
|
|
$backend_gitolite = $this->getBackendGitolite(); |
|
458
|
|
|
$backend_gitshell = Backend::instance('Git','GitBackend', array($this->getGitRepositoryUrlManager())); |
|
459
|
|
|
|
|
460
|
|
|
if (! $backend_gitolite->isNameAvailable($newName) && ! $backend_gitshell->isNameAvailable($newName)) { |
|
461
|
|
|
$error = $GLOBALS['Language']->getText('plugin_git', 'actions_name_not_available'); |
|
462
|
|
|
return false; |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
return true; |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
public function getBackendGitolite() { |
|
469
|
|
|
return new Git_Backend_Gitolite($this->getGitoliteDriver(), $this->getLogger()); |
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
|
|
public function process() { |
|
473
|
|
|
$this->getGitController()->process(); |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
/** |
|
477
|
|
|
* We expect that the check fo access right to this method has already been done by the caller |
|
478
|
|
|
*/ |
|
479
|
|
|
public function processAdmin(Codendi_Request $request) { |
|
480
|
|
|
require_once 'common/include/CSRFSynchronizerToken.class.php'; |
|
481
|
|
|
$admin = new Git_AdminRouter( |
|
482
|
|
|
$this->getGerritServerFactory(), |
|
483
|
|
|
new CSRFSynchronizerToken('/plugin/git/admin/'), |
|
484
|
|
|
$this->getMirrorDataMapper(), |
|
485
|
|
|
new Git_MirrorResourceRestrictor( |
|
486
|
|
|
new Git_RestrictedMirrorDao(), |
|
487
|
|
|
$this->getMirrorDataMapper(), |
|
488
|
|
|
$this->getGitSystemEventManager(), |
|
489
|
|
|
new ProjectHistoryDao() |
|
490
|
|
|
), |
|
491
|
|
|
ProjectManager::instance(), |
|
492
|
|
|
$this->getManifestManager(), |
|
493
|
|
|
$this->getGitSystemEventManager() |
|
494
|
|
|
); |
|
495
|
|
|
$admin->process($request); |
|
496
|
|
|
$admin->display($request); |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
private function getMirrorDataMapper() { |
|
500
|
|
|
return new Git_Mirror_MirrorDataMapper( |
|
501
|
|
|
new Git_Mirror_MirrorDao(), |
|
502
|
|
|
UserManager::instance(), |
|
503
|
|
|
new GitRepositoryFactory( |
|
504
|
|
|
new GitDao(), |
|
505
|
|
|
ProjectManager::instance() |
|
506
|
|
|
), |
|
507
|
|
|
$this->getProjectManager(), |
|
508
|
|
|
$this->getGitSystemEventManager(), |
|
509
|
|
|
new Git_Gitolite_GitoliteRCReader(), |
|
510
|
|
|
new DefaultProjectMirrorDao() |
|
511
|
|
|
); |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
/** |
|
515
|
|
|
* Hook to collect docman disk size usage per project |
|
516
|
|
|
* |
|
517
|
|
|
* @param array $params |
|
518
|
|
|
*/ |
|
519
|
|
|
function plugin_statistics_disk_usage_collect_project($params) { |
|
520
|
|
|
$row = $params['project_row']; |
|
521
|
|
|
$sum = 0; |
|
522
|
|
|
|
|
523
|
|
|
// Git-Shell backend |
|
524
|
|
|
$path = $GLOBALS['sys_data_dir'].'/gitroot/'.strtolower($row['unix_group_name']); |
|
525
|
|
|
$sum += $params['DiskUsageManager']->getDirSize($path); |
|
526
|
|
|
|
|
527
|
|
|
// Gitolite backend |
|
528
|
|
|
$path = $GLOBALS['sys_data_dir'].'/gitolite/repositories/'.strtolower($row['unix_group_name']); |
|
529
|
|
|
$sum += $params['DiskUsageManager']->getDirSize($path); |
|
530
|
|
|
|
|
531
|
|
|
$params['DiskUsageManager']->_getDao()->addGroup($row['group_id'], self::SERVICE_SHORTNAME, $sum, $_SERVER['REQUEST_TIME']); |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
/** |
|
535
|
|
|
* Hook to list docman in the list of serices managed by disk stats |
|
536
|
|
|
* |
|
537
|
|
|
* @param array $params |
|
538
|
|
|
*/ |
|
539
|
|
|
function plugin_statistics_disk_usage_service_label($params) { |
|
540
|
|
|
$params['services'][self::SERVICE_SHORTNAME] = 'Git'; |
|
541
|
|
|
} |
|
542
|
|
|
|
|
543
|
|
|
/** |
|
544
|
|
|
* Hook to choose the color of the plugin in the graph |
|
545
|
|
|
* |
|
546
|
|
|
* @param array $params |
|
547
|
|
|
*/ |
|
548
|
|
|
function plugin_statistics_color($params) { |
|
549
|
|
|
if ($params['service'] == self::SERVICE_SHORTNAME) { |
|
550
|
|
|
$params['color'] = 'palegreen'; |
|
551
|
|
|
} |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
/** |
|
555
|
|
|
* Function called when a user is removed from a project |
|
556
|
|
|
* If a user is removed from a project wich having a private git repository, the |
|
557
|
|
|
* user should be removed from notification. |
|
558
|
|
|
* |
|
559
|
|
|
* @param array $params |
|
560
|
|
|
* |
|
561
|
|
|
* @return void |
|
562
|
|
|
*/ |
|
563
|
|
|
private function projectRemoveUserFromNotification($params) { |
|
564
|
|
|
$groupId = $params['group_id']; |
|
565
|
|
|
$userId = $params['user_id']; |
|
566
|
|
|
|
|
567
|
|
|
$userManager = UserManager::instance(); |
|
568
|
|
|
$user = $userManager->getUserById($userId); |
|
569
|
|
|
|
|
570
|
|
|
$notificationsManager = new Git_PostReceiveMailManager(); |
|
571
|
|
|
$notificationsManager->removeMailByProjectPrivateRepository($groupId, $user); |
|
572
|
|
|
|
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
/** |
|
576
|
|
|
* |
|
577
|
|
|
* @see Event::EDIT_SSH_KEYS |
|
578
|
|
|
* @param array $params |
|
579
|
|
|
*/ |
|
580
|
|
|
public function edit_ssh_keys(array $params) { |
|
581
|
|
|
$this->getGitSystemEventManager()->queueEditSSHKey($params['user_id'], $params['original_keys']); |
|
582
|
|
|
} |
|
583
|
|
|
|
|
584
|
|
|
/** |
|
585
|
|
|
* Hook. Call by backend when SSH keys are modified |
|
586
|
|
|
* |
|
587
|
|
|
* @param array $params Should contain two entries: |
|
588
|
|
|
* 'user' => PFUser, |
|
589
|
|
|
* 'original_keys' => string of concatenated ssh keys |
|
590
|
|
|
*/ |
|
591
|
|
|
public function dump_ssh_keys(array $params) { |
|
592
|
|
|
$this->getGitSystemEventManager()->queueDumpAllSSHKeys(); |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
/** |
|
596
|
|
|
* |
|
597
|
|
|
* @param PFUser $user |
|
|
|
|
|
|
598
|
|
|
* @return Git_UserAccountManager |
|
599
|
|
|
*/ |
|
600
|
|
|
private function getUserAccountManager() { |
|
601
|
|
|
if (! $this->user_account_manager) { |
|
602
|
|
|
$this->user_account_manager = new Git_UserAccountManager( |
|
603
|
|
|
$this->getGerritDriverFactory(), |
|
604
|
|
|
$this->getGerritServerFactory() |
|
605
|
|
|
); |
|
606
|
|
|
} |
|
607
|
|
|
|
|
608
|
|
|
return $this->user_account_manager; |
|
609
|
|
|
} |
|
610
|
|
|
|
|
611
|
|
|
/** |
|
612
|
|
|
* |
|
613
|
|
|
* @param Git_UserAccountManager $manager |
|
614
|
|
|
*/ |
|
615
|
|
|
public function setUserAccountManager(Git_UserAccountManager $manager) { |
|
616
|
|
|
$this->user_account_manager = $manager; |
|
617
|
|
|
} |
|
618
|
|
|
|
|
619
|
|
|
/** |
|
620
|
|
|
* Method called as a hook. |
|
621
|
|
|
* |
|
622
|
|
|
* @param array $params Should contain two entries: |
|
623
|
|
|
* 'user' => PFUser, |
|
624
|
|
|
* 'html' => string An emty string of html output- passed by reference |
|
625
|
|
|
*/ |
|
626
|
|
|
public function getRemoteServersForUser(array $params) { |
|
627
|
|
|
if (! $user = $this->getUserFromParameters($params)) { |
|
628
|
|
|
return; |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
if (! isset($params['html']) || ! is_string($params['html'])) { |
|
632
|
|
|
return; |
|
633
|
|
|
} |
|
634
|
|
|
$html = $params['html']; |
|
635
|
|
|
|
|
636
|
|
|
$remote_servers = $this->getGerritServerFactory()->getRemoteServersForUser($user); |
|
637
|
|
|
|
|
638
|
|
|
if (count($remote_servers) > 0) { |
|
639
|
|
|
$html = '<br />'. |
|
640
|
|
|
$GLOBALS['Language']->getText('plugin_git', 'push_ssh_keys_info'). |
|
641
|
|
|
'<ul>'; |
|
642
|
|
|
|
|
643
|
|
|
foreach ($remote_servers as $server) { |
|
644
|
|
|
$html .= '<li> |
|
645
|
|
|
<a href="'.$server->getBaseUrl().'/#/settings/ssh-keys">'. |
|
646
|
|
|
$server->getHost().' |
|
647
|
|
|
</a> |
|
648
|
|
|
</li>'; |
|
649
|
|
|
} |
|
650
|
|
|
|
|
651
|
|
|
$html .= '</ul> |
|
652
|
|
|
<form action="" method="post"> |
|
653
|
|
|
<input type="submit" |
|
654
|
|
|
class="btn btn-small" |
|
655
|
|
|
title="'.$GLOBALS['Language']->getText('plugin_git', 'push_ssh_keys_button_title').'" |
|
656
|
|
|
value="'.$GLOBALS['Language']->getText('plugin_git', 'push_ssh_keys_button_value').'" |
|
657
|
|
|
name="ssh_key_push"/> |
|
658
|
|
|
</form>'; |
|
659
|
|
|
} |
|
660
|
|
|
|
|
661
|
|
|
if (isset($_POST['ssh_key_push'])) { |
|
662
|
|
|
$this->pushUserSSHKeysToRemoteServers($user); |
|
663
|
|
|
} |
|
664
|
|
|
|
|
665
|
|
|
$params['html'] = $html; |
|
666
|
|
|
} |
|
667
|
|
|
|
|
668
|
|
|
/** |
|
669
|
|
|
* Method called as a hook. |
|
670
|
|
|
|
|
671
|
|
|
* Copies all SSH Keys to Remote Git Servers |
|
672
|
|
|
* @param PFUser $user |
|
673
|
|
|
*/ |
|
674
|
|
|
private function pushUserSSHKeysToRemoteServers(PFUser $user) { |
|
675
|
|
|
$this->getLogger()->info('Trying to push ssh keys for user: '.$user->getUnixName()); |
|
676
|
|
|
$git_user_account_manager = $this->getUserAccountManager(); |
|
677
|
|
|
|
|
678
|
|
|
try { |
|
679
|
|
|
$git_user_account_manager->pushSSHKeys( |
|
680
|
|
|
$user |
|
681
|
|
|
); |
|
682
|
|
|
} catch (Git_UserSynchronisationException $e) { |
|
683
|
|
|
$message = $GLOBALS['Language']->getText('plugin_git','push_ssh_keys_error'); |
|
684
|
|
|
$GLOBALS['Response']->addFeedback('error', $message); |
|
685
|
|
|
|
|
686
|
|
|
$this->getLogger()->error('Unable to push ssh keys: ' . $e->getMessage()); |
|
687
|
|
|
return; |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
$this->getLogger()->info('Successfully pushed ssh keys for user: '.$user->getUnixName()); |
|
691
|
|
|
} |
|
692
|
|
|
|
|
693
|
|
|
private function getUserFromParameters($params) { |
|
694
|
|
|
if (! isset($params['user']) || ! $params['user'] instanceof PFUser) { |
|
695
|
|
|
$this->getLogger()->error('Invalid user passed in params: ' . print_r($params, true)); |
|
696
|
|
|
return false; |
|
697
|
|
|
} |
|
698
|
|
|
|
|
699
|
|
|
return $params['user']; |
|
700
|
|
|
} |
|
701
|
|
|
|
|
702
|
|
|
function permission_get_name($params) { |
|
703
|
|
|
if (!$params['name']) { |
|
704
|
|
|
switch($params['permission_type']) { |
|
705
|
|
|
case 'PLUGIN_GIT_READ': |
|
706
|
|
|
$params['name'] = $GLOBALS['Language']->getText('plugin_git', 'perm_R'); |
|
707
|
|
|
break; |
|
708
|
|
|
case 'PLUGIN_GIT_WRITE': |
|
709
|
|
|
$params['name'] = $GLOBALS['Language']->getText('plugin_git', 'perm_W'); |
|
710
|
|
|
break; |
|
711
|
|
|
case 'PLUGIN_GIT_WPLUS': |
|
712
|
|
|
$params['name'] = $GLOBALS['Language']->getText('plugin_git', 'perm_W+'); |
|
713
|
|
|
break; |
|
714
|
|
|
default: |
|
715
|
|
|
break; |
|
716
|
|
|
} |
|
717
|
|
|
} |
|
718
|
|
|
} |
|
719
|
|
|
function permission_get_object_type($params) { |
|
720
|
|
|
if (!$params['object_type']) { |
|
721
|
|
|
if (in_array($params['permission_type'], array('PLUGIN_GIT_READ', 'PLUGIN_GIT_WRITE', 'PLUGIN_GIT_WPLUS'))) { |
|
722
|
|
|
$params['object_type'] = 'git_repository'; |
|
723
|
|
|
} |
|
724
|
|
|
} |
|
725
|
|
|
} |
|
726
|
|
|
function permission_get_object_name($params) { |
|
727
|
|
|
if (!$params['object_name']) { |
|
728
|
|
|
if (in_array($params['permission_type'], array('PLUGIN_GIT_READ', 'PLUGIN_GIT_WRITE', 'PLUGIN_GIT_WPLUS'))) { |
|
729
|
|
|
$repository = new GitRepository(); |
|
730
|
|
|
$repository->setId($params['object_id']); |
|
731
|
|
|
try { |
|
732
|
|
|
$repository->load(); |
|
733
|
|
|
$params['object_name'] = $repository->getName(); |
|
734
|
|
|
} catch (Exception $e) { |
|
735
|
|
|
// do nothing |
|
736
|
|
|
} |
|
737
|
|
|
} |
|
738
|
|
|
} |
|
739
|
|
|
} |
|
740
|
|
|
function permission_get_object_fullname($params) { |
|
741
|
|
|
if (!$params['object_fullname']) { |
|
742
|
|
|
if (in_array($params['permission_type'], array('PLUGIN_GIT_READ', 'PLUGIN_GIT_WRITE', 'PLUGIN_GIT_WPLUS'))) { |
|
743
|
|
|
$repository = new GitRepository(); |
|
744
|
|
|
$repository->setId($params['object_id']); |
|
745
|
|
|
try { |
|
746
|
|
|
$repository->load(); |
|
747
|
|
|
$params['object_name'] = 'git repository '. $repository->getName(); |
|
748
|
|
|
} catch (Exception $e) { |
|
749
|
|
|
// do nothing |
|
750
|
|
|
} |
|
751
|
|
|
} |
|
752
|
|
|
} |
|
753
|
|
|
} |
|
754
|
|
|
function permissions_for_ugroup($params) { |
|
755
|
|
|
if (!$params['results']) { |
|
756
|
|
|
if (in_array($params['permission_type'], array('PLUGIN_GIT_READ', 'PLUGIN_GIT_WRITE', 'PLUGIN_GIT_WPLUS'))) { |
|
757
|
|
|
$repository = new GitRepository(); |
|
758
|
|
|
$repository->setId($params['object_id']); |
|
759
|
|
|
try { |
|
760
|
|
|
$repository->load(); |
|
761
|
|
|
$params['results'] = $repository->getName(); |
|
762
|
|
|
} catch (Exception $e) { |
|
763
|
|
|
// do nothing |
|
764
|
|
|
} |
|
765
|
|
|
} |
|
766
|
|
|
} |
|
767
|
|
|
} |
|
768
|
|
|
|
|
769
|
|
|
var $_cached_permission_user_allowed_to_change; |
|
770
|
|
|
function permission_user_allowed_to_change($params) { |
|
771
|
|
|
if (!$params['allowed']) { |
|
772
|
|
|
$user = $this->getCurrentUser(); |
|
773
|
|
|
$project = $this->getProjectManager()->getProject($params['group_id']); |
|
774
|
|
|
|
|
775
|
|
|
if ($this->getGitPermissionsManager()->userIsGitAdmin($user, $project)) { |
|
776
|
|
|
$this->_cached_permission_user_allowed_to_change = true; |
|
777
|
|
|
} |
|
778
|
|
|
|
|
779
|
|
|
if (! $this->_cached_permission_user_allowed_to_change) { |
|
780
|
|
|
if (in_array($params['permission_type'], array('PLUGIN_GIT_READ', 'PLUGIN_GIT_WRITE', 'PLUGIN_GIT_WPLUS'))) { |
|
781
|
|
|
$repository = new GitRepository(); |
|
782
|
|
|
$repository->setId($params['object_id']); |
|
783
|
|
|
try { |
|
784
|
|
|
$repository->load(); |
|
785
|
|
|
//Only project admin can update perms of project repositories |
|
786
|
|
|
//Only repo owner can update perms of personal repositories |
|
787
|
|
|
$this->_cached_permission_user_allowed_to_change = $repository->belongsTo($user) || $this->getPermissionsManager()->userIsGitAdmin($user, $project); |
|
788
|
|
|
} catch (Exception $e) { |
|
789
|
|
|
// do nothing |
|
790
|
|
|
} |
|
791
|
|
|
} |
|
792
|
|
|
} |
|
793
|
|
|
$params['allowed'] = $this->_cached_permission_user_allowed_to_change; |
|
794
|
|
|
} |
|
795
|
|
|
} |
|
796
|
|
|
|
|
797
|
|
|
public function proccess_system_check($params) { |
|
798
|
|
|
$gitgc = new Git_GitoliteHousekeeping_GitoliteHousekeepingGitGc( |
|
799
|
|
|
new Git_GitoliteHousekeeping_GitoliteHousekeepingDao(), |
|
800
|
|
|
$params['logger'], |
|
801
|
|
|
$this->getGitoliteAdminPath() |
|
802
|
|
|
); |
|
803
|
|
|
$gitolite_driver = $this->getGitoliteDriver(); |
|
804
|
|
|
|
|
805
|
|
|
$system_check = new Git_SystemCheck( |
|
806
|
|
|
$gitgc, |
|
807
|
|
|
$gitolite_driver, |
|
808
|
|
|
$this->getGitSystemEventManager() |
|
809
|
|
|
); |
|
810
|
|
|
$system_check->process(); |
|
811
|
|
|
} |
|
812
|
|
|
|
|
813
|
|
|
public function getGitoliteDriver() { |
|
814
|
|
|
return new Git_GitoliteDriver( |
|
815
|
|
|
$this->getLogger(), |
|
816
|
|
|
$this->getGitSystemEventManager(), |
|
817
|
|
|
$this->getGitRepositoryUrlManager(), |
|
818
|
|
|
$this->getGitDao(), |
|
819
|
|
|
new Git_Mirror_MirrorDao, |
|
820
|
|
|
$this, |
|
821
|
|
|
null, |
|
822
|
|
|
null, |
|
823
|
|
|
null, |
|
824
|
|
|
null, |
|
825
|
|
|
$this->getProjectManager(), |
|
826
|
|
|
$this->getMirrorDataMapper() |
|
827
|
|
|
); |
|
828
|
|
|
} |
|
829
|
|
|
|
|
830
|
|
|
/** |
|
831
|
|
|
* When project is deleted all its git repositories are archived and marked as deleted |
|
832
|
|
|
* |
|
833
|
|
|
* @param Array $params Parameters contining project id |
|
834
|
|
|
* |
|
835
|
|
|
* @return void |
|
836
|
|
|
*/ |
|
837
|
|
|
public function project_is_deleted($params) { |
|
838
|
|
|
if (!empty($params['group_id'])) { |
|
839
|
|
|
$project = ProjectManager::instance()->getProject($params['group_id']); |
|
840
|
|
|
if ($project) { |
|
841
|
|
|
$repository_manager = $this->getRepositoryManager(); |
|
842
|
|
|
$repository_manager->deleteProjectRepositories($project); |
|
843
|
|
|
} |
|
844
|
|
|
} |
|
845
|
|
|
} |
|
846
|
|
|
|
|
847
|
|
|
/** |
|
848
|
|
|
* Display git backend statistics in CSV format |
|
849
|
|
|
* |
|
850
|
|
|
* @param Array $params parameters of the event |
|
851
|
|
|
* |
|
852
|
|
|
* @return void |
|
853
|
|
|
*/ |
|
854
|
|
|
public function statistics_collector($params) { |
|
855
|
|
|
if (!empty($params['formatter'])) { |
|
856
|
|
|
include_once('GitBackend.class.php'); |
|
857
|
|
|
$formatter = $params['formatter']; |
|
858
|
|
|
$gitBackend = Backend::instance('Git','GitBackend', array($this->getGitRepositoryUrlManager())); |
|
859
|
|
|
echo $gitBackend->getBackendStatistics($formatter); |
|
860
|
|
|
} |
|
861
|
|
|
} |
|
862
|
|
|
|
|
863
|
|
|
/** |
|
864
|
|
|
* Add ci trigger information for Git service |
|
865
|
|
|
* |
|
866
|
|
|
* @param Array $params Hook parms |
|
867
|
|
|
* |
|
868
|
|
|
* @return Void |
|
869
|
|
|
*/ |
|
870
|
|
|
public function collect_ci_triggers($params) { |
|
871
|
|
|
$ci = new Git_Ci(); |
|
872
|
|
|
$triggers = $ci->retrieveTriggers($params); |
|
873
|
|
|
$params['services'][] = $triggers; |
|
874
|
|
|
} |
|
875
|
|
|
|
|
876
|
|
|
/** |
|
877
|
|
|
* Save ci trigger for Git service |
|
878
|
|
|
* |
|
879
|
|
|
* @param Array $params Hook parms |
|
880
|
|
|
* |
|
881
|
|
|
* @return Void |
|
882
|
|
|
*/ |
|
883
|
|
|
public function save_ci_triggers($params) { |
|
884
|
|
|
if (isset($params['job_id']) && !empty($params['job_id']) && isset($params['request']) && !empty($params['request'])) { |
|
885
|
|
|
if ($params['request']->get('hudson_use_plugin_git_trigger_checkbox')) { |
|
886
|
|
|
$repositoryId = $params['request']->get('hudson_use_plugin_git_trigger'); |
|
887
|
|
|
if ($repositoryId) { |
|
888
|
|
|
$vRepoId = new Valid_Uint('hudson_use_plugin_git_trigger'); |
|
889
|
|
|
$vRepoId->required(); |
|
890
|
|
|
if($params['request']->valid($vRepoId)) { |
|
891
|
|
|
$ci = new Git_Ci(); |
|
892
|
|
|
if (!$ci->saveTrigger($params['job_id'], $repositoryId)) { |
|
893
|
|
|
$GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_git','ci_trigger_not_saved')); |
|
894
|
|
|
} |
|
895
|
|
|
} else { |
|
896
|
|
|
$GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_git','ci_bad_repo_id')); |
|
897
|
|
|
} |
|
898
|
|
|
} |
|
899
|
|
|
} |
|
900
|
|
|
} |
|
901
|
|
|
} |
|
902
|
|
|
|
|
903
|
|
|
/** |
|
904
|
|
|
* Update ci trigger for Git service |
|
905
|
|
|
* |
|
906
|
|
|
* @param Array $params Hook parms |
|
907
|
|
|
* |
|
908
|
|
|
* @return Void |
|
909
|
|
|
*/ |
|
910
|
|
|
public function update_ci_triggers($params) { |
|
911
|
|
|
if (isset($params['request']) && !empty($params['request'])) { |
|
912
|
|
|
$jobId = $params['request']->get('job_id'); |
|
913
|
|
|
$repositoryId = $params['request']->get('hudson_use_plugin_git_trigger'); |
|
914
|
|
|
if ($jobId) { |
|
915
|
|
|
$vJobId = new Valid_Uint('job_id'); |
|
916
|
|
|
$vJobId->required(); |
|
917
|
|
|
if($params['request']->valid($vJobId)) { |
|
918
|
|
|
$ci = new Git_Ci(); |
|
919
|
|
|
$vRepoId = new Valid_Uint('hudson_use_plugin_git_trigger'); |
|
920
|
|
|
$vRepoId->required(); |
|
921
|
|
|
if ($params['request']->valid($vRepoId)) { |
|
922
|
|
|
if (!$ci->saveTrigger($jobId, $repositoryId)) { |
|
923
|
|
|
$GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_git','ci_trigger_not_saved')); |
|
924
|
|
|
} |
|
925
|
|
|
} else { |
|
926
|
|
|
if (!$ci->deleteTrigger($jobId)) { |
|
927
|
|
|
$GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_git','ci_trigger_not_deleted')); |
|
928
|
|
|
} |
|
929
|
|
|
} |
|
930
|
|
|
} else { |
|
931
|
|
|
$GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_git','ci_bad_repo_id')); |
|
932
|
|
|
} |
|
933
|
|
|
} |
|
934
|
|
|
} |
|
935
|
|
|
} |
|
936
|
|
|
|
|
937
|
|
|
/** |
|
938
|
|
|
* Delete ci trigger for Git service |
|
939
|
|
|
* |
|
940
|
|
|
* @param Array $params Hook parms |
|
941
|
|
|
* |
|
942
|
|
|
* @return Void |
|
943
|
|
|
*/ |
|
944
|
|
|
public function delete_ci_triggers($params) { |
|
945
|
|
|
if (isset($params['job_id']) && !empty($params['job_id'])) { |
|
946
|
|
|
$ci = new Git_Ci(); |
|
947
|
|
|
if (!$ci->deleteTrigger($params['job_id'])) { |
|
948
|
|
|
$GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_git','ci_trigger_not_deleted')); |
|
949
|
|
|
} |
|
950
|
|
|
} |
|
951
|
|
|
} |
|
952
|
|
|
|
|
953
|
|
|
/** |
|
954
|
|
|
* Add log access for git pushs |
|
955
|
|
|
* |
|
956
|
|
|
* @param Array $params parameters of the event |
|
957
|
|
|
* |
|
958
|
|
|
* @return Void |
|
959
|
|
|
*/ |
|
960
|
|
|
function logsDaily($params) { |
|
961
|
|
|
$pm = ProjectManager::instance(); |
|
962
|
|
|
$project = $pm->getProject($params['group_id']); |
|
963
|
|
|
if ($project->usesService(GitPlugin::SERVICE_SHORTNAME)) { |
|
964
|
|
|
$controler = $this->getGitController(); |
|
965
|
|
|
$controler->logsDaily($params); |
|
966
|
|
|
} |
|
967
|
|
|
} |
|
968
|
|
|
|
|
969
|
|
|
/** |
|
970
|
|
|
* Instanciate the corresponding widget |
|
971
|
|
|
* |
|
972
|
|
|
* @param Array $params Name and instance of the widget |
|
973
|
|
|
* |
|
974
|
|
|
* @return Void |
|
975
|
|
|
*/ |
|
976
|
|
|
function myPageBox($params) { |
|
977
|
|
|
switch ($params['widget']) { |
|
978
|
|
|
case 'plugin_git_user_pushes': |
|
979
|
|
|
$params['instance'] = new Git_Widget_UserPushes($this->getPluginPath()); |
|
980
|
|
|
break; |
|
981
|
|
|
case 'plugin_git_project_pushes': |
|
982
|
|
|
$params['instance'] = new Git_Widget_ProjectPushes($this->getPluginPath()); |
|
983
|
|
|
break; |
|
984
|
|
|
default: |
|
985
|
|
|
break; |
|
986
|
|
|
} |
|
987
|
|
|
} |
|
988
|
|
|
|
|
989
|
|
|
public function project_admin_remove_user_from_project_ugroups($params) { |
|
990
|
|
|
foreach ($params['ugroups'] as $ugroup_id) { |
|
991
|
|
|
$this->project_admin_ugroup_remove_user( |
|
992
|
|
|
array( |
|
993
|
|
|
'group_id' => $params['group_id'], |
|
994
|
|
|
'user_id' => $params['user_id'], |
|
995
|
|
|
'ugroup_id' => $ugroup_id, |
|
996
|
|
|
) |
|
997
|
|
|
); |
|
998
|
|
|
} |
|
999
|
|
|
} |
|
1000
|
|
|
|
|
1001
|
|
|
public function project_admin_change_user_permissions($params) { |
|
1002
|
|
|
if ($params['user_permissions']['admin_flags'] == 'A') { |
|
1003
|
|
|
$params['ugroup_id'] = ProjectUGroup::PROJECT_ADMIN; |
|
1004
|
|
|
$this->project_admin_ugroup_add_user($params); |
|
1005
|
|
|
} else { |
|
1006
|
|
|
$params['ugroup_id'] = ProjectUGroup::PROJECT_ADMIN; |
|
1007
|
|
|
$this->project_admin_ugroup_remove_user($params); |
|
1008
|
|
|
} |
|
1009
|
|
|
} |
|
1010
|
|
|
|
|
1011
|
|
|
public function project_admin_ugroup_deletion($params) { |
|
1012
|
|
|
$ugroup = $params['ugroup']; |
|
1013
|
|
|
$users = $ugroup->getMembers(); |
|
1014
|
|
|
|
|
1015
|
|
|
foreach ($users as $user) { |
|
1016
|
|
|
$calling = array( |
|
1017
|
|
|
'group_id' => $params['group_id'], |
|
1018
|
|
|
'user_id' => $user->getId(), |
|
1019
|
|
|
'ugroup' => $ugroup |
|
1020
|
|
|
); |
|
1021
|
|
|
$this->project_admin_ugroup_remove_user($calling); |
|
1022
|
|
|
} |
|
1023
|
|
|
} |
|
1024
|
|
|
|
|
1025
|
|
|
public function project_admin_add_user($params) { |
|
1026
|
|
|
$params['ugroup_id'] = ProjectUGroup::PROJECT_MEMBERS; |
|
1027
|
|
|
$this->project_admin_ugroup_add_user($params); |
|
1028
|
|
|
} |
|
1029
|
|
|
|
|
1030
|
|
|
public function project_admin_remove_user($params) { |
|
1031
|
|
|
$params['ugroup_id'] = ProjectUGroup::PROJECT_MEMBERS; |
|
1032
|
|
|
$this->project_admin_ugroup_remove_user($params); |
|
1033
|
|
|
$this->projectRemoveUserFromNotification($params); |
|
1034
|
|
|
} |
|
1035
|
|
|
|
|
1036
|
|
|
public function project_admin_ugroup_add_user($params) { |
|
1037
|
|
|
$this->getGerritMembershipManager()->addUserToGroup( |
|
1038
|
|
|
$this->getUserFromParams($params), |
|
1039
|
|
|
$this->getUGroupFromParams($params) |
|
1040
|
|
|
); |
|
1041
|
|
|
} |
|
1042
|
|
|
|
|
1043
|
|
|
public function project_admin_ugroup_remove_user($params) { |
|
1044
|
|
|
$this->getGerritMembershipManager()->removeUserFromGroup( |
|
1045
|
|
|
$this->getUserFromParams($params), |
|
1046
|
|
|
$this->getUGroupFromParams($params) |
|
1047
|
|
|
); |
|
1048
|
|
|
} |
|
1049
|
|
|
|
|
1050
|
|
|
public function project_admin_ugroup_creation($params) { |
|
1051
|
|
|
$this->getGerritMembershipManager()->createGroupOnProjectsServers( |
|
1052
|
|
|
$this->getUGroupFromParams($params) |
|
1053
|
|
|
); |
|
1054
|
|
|
} |
|
1055
|
|
|
|
|
1056
|
|
|
public function project_admin_parent_project_modification($params) { |
|
1057
|
|
|
try { |
|
1058
|
|
|
$project = ProjectManager::instance()->getProject($params['group_id']); |
|
1059
|
|
|
$gerrit_servers = $this->getGerritServerFactory()->getServersForProject($project); |
|
1060
|
|
|
|
|
1061
|
|
|
$this->getGerritUmbrellaProjectManager()->recursivelyCreateUmbrellaProjects($gerrit_servers, $project); |
|
1062
|
|
|
} catch (Git_Driver_Gerrit_Exception $exception) { |
|
1063
|
|
|
$GLOBALS['Response']->addFeedback(Feedback::ERROR, $GLOBALS['Language']->getText('plugin_git', 'gerrit_remote_exception', $exception->getMessage())); |
|
1064
|
|
|
} catch (Exception $exception) { |
|
1065
|
|
|
$GLOBALS['Response']->addFeedback(Feedback::ERROR, $exception->getMessage()); |
|
1066
|
|
|
} |
|
1067
|
|
|
} |
|
1068
|
|
|
|
|
1069
|
|
|
public function ugroup_manager_update_ugroup_binding_add($params) { |
|
1070
|
|
|
$this->getGerritMembershipManager()->addUGroupBinding( |
|
1071
|
|
|
$params['ugroup'], |
|
1072
|
|
|
$params['source'] |
|
1073
|
|
|
); |
|
1074
|
|
|
} |
|
1075
|
|
|
|
|
1076
|
|
|
public function ugroup_manager_update_ugroup_binding_remove($params) { |
|
1077
|
|
|
$this->getGerritMembershipManager()->removeUGroupBinding( |
|
1078
|
|
|
$params['ugroup'] |
|
1079
|
|
|
); |
|
1080
|
|
|
} |
|
1081
|
|
|
|
|
1082
|
|
|
private function getUserFromParams(array $params) { |
|
1083
|
|
|
return UserManager::instance()->getUserById($params['user_id']); |
|
1084
|
|
|
} |
|
1085
|
|
|
|
|
1086
|
|
|
|
|
1087
|
|
|
private function getUGroupFromParams(array $params) { |
|
1088
|
|
|
if (isset($params['ugroup'])) { |
|
1089
|
|
|
return $params['ugroup']; |
|
1090
|
|
|
} else { |
|
1091
|
|
|
$project = ProjectManager::instance()->getProject($params['group_id']); |
|
1092
|
|
|
return $this->getUGroupManager()->getUGroup($project, $params['ugroup_id']); |
|
1093
|
|
|
} |
|
1094
|
|
|
} |
|
1095
|
|
|
|
|
1096
|
|
|
/** |
|
1097
|
|
|
* List plugin's widgets in customize menu |
|
1098
|
|
|
* |
|
1099
|
|
|
* @param Array $params List of widgets |
|
1100
|
|
|
* |
|
1101
|
|
|
* @return Void |
|
1102
|
|
|
*/ |
|
1103
|
|
|
function widgets($params) { |
|
1104
|
|
|
require_once('common/widget/WidgetLayoutManager.class.php'); |
|
1105
|
|
|
if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_USER) { |
|
1106
|
|
|
$params['codendi_widgets'][] = 'plugin_git_user_pushes'; |
|
1107
|
|
|
} |
|
1108
|
|
|
$request = HTTPRequest::instance(); |
|
1109
|
|
|
$groupId = $request->get('group_id'); |
|
1110
|
|
|
$pm = ProjectManager::instance(); |
|
1111
|
|
|
$project = $pm->getProject($groupId); |
|
1112
|
|
|
if ($project->usesService(GitPlugin::SERVICE_SHORTNAME)) { |
|
1113
|
|
|
if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_GROUP) { |
|
1114
|
|
|
$params['codendi_widgets'][] = 'plugin_git_project_pushes'; |
|
1115
|
|
|
} |
|
1116
|
|
|
} |
|
1117
|
|
|
} |
|
1118
|
|
|
|
|
1119
|
|
|
private function getProjectCreator() { |
|
1120
|
|
|
$tmp_dir = ForgeConfig::get('tmp_dir') .'/gerrit_'. uniqid(); |
|
1121
|
|
|
return new Git_Driver_Gerrit_ProjectCreator( |
|
1122
|
|
|
$tmp_dir, |
|
1123
|
|
|
$this->getGerritDriverFactory(), |
|
1124
|
|
|
$this->getGerritUserFinder(), |
|
1125
|
|
|
$this->getUGroupManager(), |
|
1126
|
|
|
$this->getGerritMembershipManager(), |
|
1127
|
|
|
$this->getGerritUmbrellaProjectManager(), |
|
1128
|
|
|
$this->getTemplateFactory(), |
|
1129
|
|
|
$this->getTemplateProcessor() |
|
1130
|
|
|
); |
|
1131
|
|
|
} |
|
1132
|
|
|
|
|
1133
|
|
|
private function getTemplateProcessor() { |
|
1134
|
|
|
return new Git_Driver_Gerrit_Template_TemplateProcessor(); |
|
1135
|
|
|
} |
|
1136
|
|
|
|
|
1137
|
|
|
private function getGerritUmbrellaProjectManager() { |
|
1138
|
|
|
return new Git_Driver_Gerrit_UmbrellaProjectManager( |
|
1139
|
|
|
$this->getUGroupManager(), |
|
1140
|
|
|
$this->getProjectManager(), |
|
1141
|
|
|
$this->getGerritMembershipManager(), |
|
1142
|
|
|
$this->getGerritDriverFactory() |
|
1143
|
|
|
); |
|
1144
|
|
|
} |
|
1145
|
|
|
|
|
1146
|
|
|
private function getProjectManager() { |
|
1147
|
|
|
return ProjectManager::instance(); |
|
1148
|
|
|
} |
|
1149
|
|
|
|
|
1150
|
|
|
private function getGerritUserFinder() { |
|
1151
|
|
|
return new Git_Driver_Gerrit_UserFinder(PermissionsManager::instance(), $this->getUGroupManager()); |
|
1152
|
|
|
} |
|
1153
|
|
|
|
|
1154
|
|
|
private function getGitController() { |
|
1155
|
|
|
return new Git( |
|
1156
|
|
|
$this, |
|
1157
|
|
|
$this->getGerritServerFactory(), |
|
1158
|
|
|
$this->getGerritDriverFactory(), |
|
1159
|
|
|
$this->getRepositoryManager(), |
|
1160
|
|
|
$this->getGitSystemEventManager(), |
|
1161
|
|
|
new Git_Driver_Gerrit_UserAccountManager($this->getGerritDriverFactory(), $this->getGerritServerFactory()), |
|
1162
|
|
|
$this->getRepositoryFactory(), |
|
1163
|
|
|
UserManager::instance(), |
|
1164
|
|
|
ProjectManager::instance(), |
|
1165
|
|
|
PluginManager::instance(), |
|
1166
|
|
|
HTTPRequest::instance(), |
|
1167
|
|
|
$this->getProjectCreator(), |
|
1168
|
|
|
new Git_Driver_Gerrit_Template_TemplateFactory(new Git_Driver_Gerrit_Template_TemplateDao()), |
|
1169
|
|
|
$this->getGitPermissionsManager(), |
|
1170
|
|
|
$this->getGitRepositoryUrlManager(), |
|
1171
|
|
|
$this->getLogger(), |
|
1172
|
|
|
$this->getBackendGitolite(), |
|
1173
|
|
|
$this->getMirrorDataMapper() |
|
1174
|
|
|
); |
|
1175
|
|
|
} |
|
1176
|
|
|
|
|
1177
|
|
|
public function getGitSystemEventManager() { |
|
1178
|
|
|
return new Git_SystemEventManager(SystemEventManager::instance(), $this->getRepositoryFactory()); |
|
1179
|
|
|
} |
|
1180
|
|
|
|
|
1181
|
|
|
/** |
|
1182
|
|
|
* @return GitRepositoryManager |
|
1183
|
|
|
*/ |
|
1184
|
|
|
private function getRepositoryManager() { |
|
1185
|
|
|
return new GitRepositoryManager( |
|
1186
|
|
|
$this->getRepositoryFactory(), |
|
1187
|
|
|
$this->getGitSystemEventManager(), |
|
1188
|
|
|
$this->getGitDao(), |
|
1189
|
|
|
$this->getConfigurationParameter('git_backup_dir') |
|
1190
|
|
|
); |
|
1191
|
|
|
} |
|
1192
|
|
|
|
|
1193
|
|
|
public function getRepositoryFactory() { |
|
1194
|
|
|
return new GitRepositoryFactory($this->getGitDao(), ProjectManager::instance()); |
|
1195
|
|
|
} |
|
1196
|
|
|
|
|
1197
|
|
|
private function getGitDao() { |
|
1198
|
|
|
return new GitDao(); |
|
1199
|
|
|
} |
|
1200
|
|
|
|
|
1201
|
|
|
/** |
|
1202
|
|
|
* @return Git_Driver_Gerrit_GerritDriverFactory |
|
1203
|
|
|
*/ |
|
1204
|
|
|
private function getGerritDriverFactory() { |
|
1205
|
|
|
return new Git_Driver_Gerrit_GerritDriverFactory($this->getLogger()); |
|
1206
|
|
|
} |
|
1207
|
|
|
|
|
1208
|
|
|
private function getPermissionsManager() { |
|
1209
|
|
|
return PermissionsManager::instance(); |
|
1210
|
|
|
} |
|
1211
|
|
|
|
|
1212
|
|
|
private function getGitPermissionsManager() { |
|
1213
|
|
|
return new GitPermissionsManager( |
|
1214
|
|
|
new Git_PermissionsDao(), |
|
1215
|
|
|
$this->getGitSystemEventManager() |
|
1216
|
|
|
); |
|
1217
|
|
|
} |
|
1218
|
|
|
|
|
1219
|
|
|
/** |
|
1220
|
|
|
* |
|
1221
|
|
|
* @return Logger |
|
1222
|
|
|
*/ |
|
1223
|
|
|
public function getLogger() { |
|
1224
|
|
|
if (!$this->logger) { |
|
1225
|
|
|
$this->logger = new GitBackendLogger(); |
|
1226
|
|
|
} |
|
1227
|
|
|
|
|
1228
|
|
|
return $this->logger; |
|
1229
|
|
|
} |
|
1230
|
|
|
|
|
1231
|
|
|
/** |
|
1232
|
|
|
* |
|
1233
|
|
|
* @param Logger $logger |
|
1234
|
|
|
*/ |
|
1235
|
|
|
public function setLogger(Logger $logger) { |
|
1236
|
|
|
$this->logger = $logger; |
|
1237
|
|
|
} |
|
1238
|
|
|
|
|
1239
|
|
|
private function getGerritMembershipManager() { |
|
1240
|
|
|
return new Git_Driver_Gerrit_MembershipManager( |
|
1241
|
|
|
new Git_Driver_Gerrit_MembershipDao(), |
|
1242
|
|
|
$this->getGerritDriverFactory(), |
|
1243
|
|
|
new Git_Driver_Gerrit_UserAccountManager($this->getGerritDriverFactory(), $this->getGerritServerFactory()), |
|
1244
|
|
|
$this->getGerritServerFactory(), |
|
1245
|
|
|
$this->getLogger(), |
|
1246
|
|
|
$this->getUGroupManager(), |
|
1247
|
|
|
$this->getProjectManager() |
|
1248
|
|
|
); |
|
1249
|
|
|
} |
|
1250
|
|
|
|
|
1251
|
|
|
protected function getGerritServerFactory() { |
|
1252
|
|
|
return new Git_RemoteServer_GerritServerFactory( |
|
1253
|
|
|
new Git_RemoteServer_Dao(), |
|
1254
|
|
|
$this->getGitDao(), |
|
1255
|
|
|
$this->getGitSystemEventManager(), |
|
1256
|
|
|
$this->getProjectManager() |
|
1257
|
|
|
); |
|
1258
|
|
|
} |
|
1259
|
|
|
|
|
1260
|
|
|
private function getGitoliteSSHKeyDumper() { |
|
1261
|
|
|
$gitolite_admin_path = $this->getGitoliteAdminPath(); |
|
1262
|
|
|
return new Git_Gitolite_SSHKeyDumper( |
|
1263
|
|
|
$gitolite_admin_path, |
|
1264
|
|
|
new Git_Exec($gitolite_admin_path) |
|
1265
|
|
|
); |
|
1266
|
|
|
} |
|
1267
|
|
|
|
|
1268
|
|
|
private function getGitoliteAdminPath() { |
|
1269
|
|
|
return $GLOBALS['sys_data_dir'] . '/gitolite/admin'; |
|
1270
|
|
|
} |
|
1271
|
|
|
|
|
1272
|
|
|
private function getUGroupManager() { |
|
1273
|
|
|
return new UGroupManager(); |
|
1274
|
|
|
} |
|
1275
|
|
|
|
|
1276
|
|
|
/** |
|
1277
|
|
|
* @param array $params |
|
1278
|
|
|
* Parameters: |
|
1279
|
|
|
* 'user' => PFUser |
|
1280
|
|
|
* 'html' => string |
|
1281
|
|
|
*/ |
|
1282
|
|
|
public function manage_third_party_apps($params) { |
|
1283
|
|
|
$this->resynch_gerrit_groups_with_user($params); |
|
1284
|
|
|
} |
|
1285
|
|
|
|
|
1286
|
|
|
/** |
|
1287
|
|
|
* @param array $params |
|
1288
|
|
|
* Parameters: |
|
1289
|
|
|
* 'user' => PFUser |
|
1290
|
|
|
* 'html' => string |
|
1291
|
|
|
*/ |
|
1292
|
|
|
private function resynch_gerrit_groups_with_user($params) { |
|
1293
|
|
|
if (! $this->getGerritServerFactory()->hasRemotesSetUp()) { |
|
1294
|
|
|
return; |
|
1295
|
|
|
} |
|
1296
|
|
|
|
|
1297
|
|
|
$renderer = TemplateRendererFactory::build()->getRenderer(dirname(GIT_BASE_DIR).'/templates'); |
|
1298
|
|
|
$presenter = new GitPresenters_GerritAsThirdPartyPresenter(); |
|
1299
|
|
|
$params['html'] .= $renderer->renderToString('gerrit_as_third_party', $presenter); |
|
1300
|
|
|
|
|
1301
|
|
|
$request = HTTPRequest::instance(); |
|
1302
|
|
|
$action = $request->get('action'); |
|
1303
|
|
|
if ($action && $action = $presenter->form_action) { |
|
1304
|
|
|
$this->addMissingGerritAccess($params['user']); |
|
1305
|
|
|
} |
|
1306
|
|
|
} |
|
1307
|
|
|
|
|
1308
|
|
|
private function addMissingGerritAccess($user) { |
|
1309
|
|
|
$this->getGerritMembershipManager()->addUserToAllTheirGroups($user); |
|
1310
|
|
|
} |
|
1311
|
|
|
|
|
1312
|
|
|
/** |
|
1313
|
|
|
* @see Event::USER_RENAME |
|
1314
|
|
|
*/ |
|
1315
|
|
|
public function systemevent_user_rename($params) { |
|
1316
|
|
|
$this->getGitSystemEventManager()->queueUserRenameUpdate($params['old_user_name'], $params['user']); |
|
1317
|
|
|
} |
|
1318
|
|
|
|
|
1319
|
|
|
public function register_project_creation($params) { |
|
1320
|
|
|
$this->getPermissionsManager()->duplicateWithStaticMapping( |
|
1321
|
|
|
$params['template_id'], |
|
1322
|
|
|
$params['group_id'], |
|
1323
|
|
|
array(Git::PERM_ADMIN), |
|
1324
|
|
|
$params['ugroupsMapping'] |
|
1325
|
|
|
); |
|
1326
|
|
|
|
|
1327
|
|
|
$this->getMirrorDataMapper()->duplicate($params['template_id'], $params['group_id']); |
|
1328
|
|
|
} |
|
1329
|
|
|
|
|
1330
|
|
|
/** @see Event::GET_PROJECTID_FROM_URL */ |
|
1331
|
|
|
public function get_projectid_from_url($params) { |
|
1332
|
|
|
if (strpos($_SERVER['REQUEST_URI'], $this->getPluginPath()) === 0) { |
|
1333
|
|
|
$url = new Git_URL( |
|
1334
|
|
|
ProjectManager::instance(), |
|
1335
|
|
|
$this->getRepositoryFactory(), |
|
1336
|
|
|
$_SERVER['REQUEST_URI'] |
|
1337
|
|
|
); |
|
1338
|
|
|
if ($url->isSmartHTTP()) { |
|
1339
|
|
|
return; |
|
1340
|
|
|
} |
|
1341
|
|
|
|
|
1342
|
|
|
$project = $url->getProject(); |
|
1343
|
|
|
if ($project && ! $project->isError()) { |
|
1344
|
|
|
$params['project_id'] = $url->getProject()->getId(); |
|
1345
|
|
|
} |
|
1346
|
|
|
} |
|
1347
|
|
|
} |
|
1348
|
|
|
|
|
1349
|
|
|
public function anonymous_access_to_script_allowed($params) { |
|
1350
|
|
|
if (strpos($_SERVER['REQUEST_URI'], $this->getPluginPath()) === 0) { |
|
1351
|
|
|
$url = new Git_URL( |
|
1352
|
|
|
ProjectManager::instance(), |
|
1353
|
|
|
$this->getRepositoryFactory(), |
|
1354
|
|
|
$_SERVER['REQUEST_URI'] |
|
1355
|
|
|
); |
|
1356
|
|
|
if ($url->isSmartHTTP()) { |
|
1357
|
|
|
$params['anonymous_allowed'] = true; |
|
1358
|
|
|
} |
|
1359
|
|
|
} |
|
1360
|
|
|
} |
|
1361
|
|
|
|
|
1362
|
|
|
/** |
|
1363
|
|
|
* @return boolean true if friendly URLs have been activated |
|
1364
|
|
|
*/ |
|
1365
|
|
|
public function areFriendlyUrlsActivated() { |
|
1366
|
|
|
return (bool) $this->getConfigurationParameter('git_use_friendly_urls'); |
|
1367
|
|
|
} |
|
1368
|
|
|
|
|
1369
|
|
|
/** |
|
1370
|
|
|
* @return Git_GitRepositoryUrlManager |
|
1371
|
|
|
*/ |
|
1372
|
|
|
private function getGitRepositoryUrlManager() { |
|
1373
|
|
|
return new Git_GitRepositoryUrlManager($this); |
|
1374
|
|
|
} |
|
1375
|
|
|
|
|
1376
|
|
|
/** |
|
1377
|
|
|
* @return Git_Mirror_ManifestManager |
|
1378
|
|
|
*/ |
|
1379
|
|
|
public function getManifestManager() { |
|
1380
|
|
|
return new Git_Mirror_ManifestManager( |
|
1381
|
|
|
$this->getMirrorDataMapper(), |
|
1382
|
|
|
new Git_Mirror_ManifestFileGenerator( |
|
1383
|
|
|
$this->getLogger(), |
|
1384
|
|
|
ForgeConfig::get('sys_data_dir').'/gitolite/grokmirror' |
|
1385
|
|
|
) |
|
1386
|
|
|
); |
|
1387
|
|
|
} |
|
1388
|
|
|
|
|
1389
|
|
|
private function getSSHKeyDumper() { |
|
1390
|
|
|
$admin_path = $GLOBALS['sys_data_dir'] . '/gitolite/admin'; |
|
1391
|
|
|
$git_exec = new Git_Exec($admin_path); |
|
1392
|
|
|
return new Git_Gitolite_SSHKeyDumper($admin_path, $git_exec); |
|
1393
|
|
|
} |
|
1394
|
|
|
|
|
1395
|
|
|
private function getSSHKeyMassDumper() { |
|
1396
|
|
|
return new Git_Gitolite_SSHKeyMassDumper( |
|
1397
|
|
|
$this->getSSHKeyDumper(), |
|
1398
|
|
|
UserManager::instance() |
|
1399
|
|
|
); |
|
1400
|
|
|
} |
|
1401
|
|
|
|
|
1402
|
|
|
/** |
|
1403
|
|
|
* Hook: called by daily codendi script. |
|
1404
|
|
|
*/ |
|
1405
|
|
|
function codendiDaily() { |
|
1406
|
|
|
$this->getRepositoryManager()->purgeArchivedRepositories($this->getLogger()); |
|
1407
|
|
|
} |
|
1408
|
|
|
|
|
1409
|
|
|
public function fill_project_history_sub_events($params) { |
|
1410
|
|
|
array_push( |
|
1411
|
|
|
$params['subEvents']['event_others'], |
|
1412
|
|
|
'git_repo_create', |
|
1413
|
|
|
'git_repo_delete', |
|
1414
|
|
|
'git_repo_update', |
|
1415
|
|
|
'git_repo_mirroring_update', |
|
1416
|
|
|
'git_repo_to_gerrit', |
|
1417
|
|
|
'git_create_template', |
|
1418
|
|
|
'git_delete_template', |
|
1419
|
|
|
'git_disconnect_gerrit_delete', |
|
1420
|
|
|
'git_disconnect_gerrit_read_only', |
|
1421
|
|
|
'git_admin_groups', |
|
1422
|
|
|
'git_fork_repositories' |
|
1423
|
|
|
); |
|
1424
|
|
|
} |
|
1425
|
|
|
|
|
1426
|
|
|
/** |
|
1427
|
|
|
* @see Event::POST_EVENTS_ACTIONS |
|
1428
|
|
|
*/ |
|
1429
|
|
|
public function post_system_events_actions($params) { |
|
1430
|
|
|
if (! $this->pluginIsConcerned($params)) { |
|
1431
|
|
|
return; |
|
1432
|
|
|
} |
|
1433
|
|
|
|
|
1434
|
|
|
$this->getLogger()->info('Processing git post system events actions'); |
|
1435
|
|
|
|
|
1436
|
|
|
$executed_events_ids = $params['executed_events_ids']; |
|
1437
|
|
|
|
|
1438
|
|
|
$this->getGitoliteDriver()->commit('Modifications from events ' . implode(',', $executed_events_ids)); |
|
1439
|
|
|
$this->getGitoliteDriver()->push(); |
|
1440
|
|
|
} |
|
1441
|
|
|
|
|
1442
|
|
|
private function pluginIsConcerned($params) { |
|
1443
|
|
|
return $params['queue_name'] == "git" |
|
1444
|
|
|
&& is_array($params['executed_events_ids']) |
|
1445
|
|
|
&& count($params['executed_events_ids']) > 0; |
|
1446
|
|
|
} |
|
1447
|
|
|
|
|
1448
|
|
|
public function getRESTRepositoryRepresentationBuilder($version) { |
|
1449
|
|
|
$class = "Tuleap\\Git\\REST\\".$version."\\RepositoryRepresentationBuilder"; |
|
1450
|
|
|
return new $class($this->getGitPermissionsManager()); |
|
1451
|
|
|
} |
|
1452
|
|
|
|
|
1453
|
|
|
public function rest_project_get_git($params) { |
|
1454
|
|
|
$class = "Tuleap\\Git\\REST\\".$params['version']."\\ProjectResource"; |
|
1455
|
|
|
$project_resource = new $class($this->getRepositoryFactory(), $this->getRESTRepositoryRepresentationBuilder($params['version'])); |
|
1456
|
|
|
$project = $params['project']; |
|
1457
|
|
|
|
|
1458
|
|
|
$params['result'] = $project_resource->getGit( |
|
1459
|
|
|
$project, |
|
1460
|
|
|
$this->getCurrentUser(), |
|
1461
|
|
|
$params['limit'], |
|
1462
|
|
|
$params['offset'], |
|
1463
|
|
|
$params['fields'] |
|
1464
|
|
|
); |
|
1465
|
|
|
|
|
1466
|
|
|
$params['total_git_repo'] = count($this->getRepositoryFactory()->getAllRepositories($project)); |
|
1467
|
|
|
} |
|
1468
|
|
|
|
|
1469
|
|
|
public function rest_project_options_git($params) { |
|
1470
|
|
|
$params['activated'] = true; |
|
1471
|
|
|
} |
|
1472
|
|
|
|
|
1473
|
|
|
/** |
|
1474
|
|
|
* @see Event::REST_PROJECT_RESOURCES |
|
1475
|
|
|
*/ |
|
1476
|
|
|
public function rest_project_resources(array $params) { |
|
1477
|
|
|
$injector = new Git_REST_ResourcesInjector(); |
|
1478
|
|
|
$injector->declareProjectPlanningResource($params['resources'], $params['project']); |
|
1479
|
|
|
} |
|
1480
|
|
|
|
|
1481
|
|
|
/** |
|
1482
|
|
|
* @see REST_RESOURCES |
|
1483
|
|
|
*/ |
|
1484
|
|
|
public function rest_resources($params) { |
|
1485
|
|
|
$injector = new Git_REST_ResourcesInjector(); |
|
1486
|
|
|
$injector->populate($params['restler']); |
|
1487
|
|
|
} |
|
1488
|
|
|
|
|
1489
|
|
|
/** |
|
1490
|
|
|
* @return PFUser |
|
1491
|
|
|
*/ |
|
1492
|
|
|
private function getCurrentUser() { |
|
1493
|
|
|
return UserManager::instance()->getCurrentUser(); |
|
1494
|
|
|
} |
|
1495
|
|
|
|
|
1496
|
|
|
/** |
|
1497
|
|
|
* Hook to list archived repositories for restore in site admin page |
|
1498
|
|
|
* |
|
1499
|
|
|
* @param array $params |
|
1500
|
|
|
*/ |
|
1501
|
|
|
public function showArchivedRepositories($params) { |
|
1502
|
|
|
$group_id = $params['group_id']; |
|
1503
|
|
|
$archived_repositories = $this->getRepositoryManager()->getRepositoriesForRestoreByProjectId($group_id); |
|
1504
|
|
|
$tab_content = '<div class="contenu_onglet" id="contenu_onglet_git_repository">'; |
|
1505
|
|
|
|
|
1506
|
|
|
if (count($archived_repositories) == 0) { |
|
1507
|
|
|
$tab_content .= '<center>'.$GLOBALS['Language']->getText('plugin_git', 'restore_no_repo_found').'</center>'; |
|
1508
|
|
|
} else { |
|
1509
|
|
|
$tab_content .= '<table>'; |
|
1510
|
|
|
foreach($archived_repositories as $archived_repository) { |
|
1511
|
|
|
$tab_content .= '<tr class="boxitemgrey">'; |
|
1512
|
|
|
$tab_content .= '<td>'.$archived_repository->getName().'</td>'; |
|
1513
|
|
|
$tab_content .= '<td>'.$archived_repository->getCreationDate().'</td>'; |
|
1514
|
|
|
$tab_content .= '<td>'.$archived_repository->getCreator()->getName().'</td>'; |
|
1515
|
|
|
$tab_content .= '<td>'.$archived_repository->getDeletionDate().'</td>'; |
|
1516
|
|
|
$tab_content .= '<td><a href="/plugins/git/?action=restore&group_id='.$group_id.'&repo_id='.$archived_repository->getId().'"><img src="'.util_get_image_theme("ic/convert.png").'" onClick="return confirm(\''.$GLOBALS['Language']->getText('plugin_git', 'restore_confirmation').'\')" border="0" height="16" width="16"></a></td>'; |
|
1517
|
|
|
$tab_content .= '</tr>'; |
|
1518
|
|
|
} |
|
1519
|
|
|
$tab_content .= '</table>'; |
|
1520
|
|
|
} |
|
1521
|
|
|
$tab_content .= '</div>'; |
|
1522
|
|
|
$params['id'][] = 'git_repository'; |
|
1523
|
|
|
$params['nom'][] = $GLOBALS['Language']->getText('plugin_git', 'archived_repositories'); |
|
1524
|
|
|
$params['html'][]= $tab_content; |
|
1525
|
|
|
} |
|
1526
|
|
|
|
|
1527
|
|
|
public function is_script_handled_for_restricted($params) { |
|
1528
|
|
|
$uri = $params['uri']; |
|
1529
|
|
|
if (strpos($uri, $this->getPluginPath()) === 0) { |
|
1530
|
|
|
$params['allow_restricted'] = true; |
|
1531
|
|
|
} |
|
1532
|
|
|
} |
|
1533
|
|
|
|
|
1534
|
|
|
public function get_services_allowed_for_restricted($params) { |
|
1535
|
|
|
$params['allowed_services'][] = $this->getServiceShortname(); |
|
1536
|
|
|
} |
|
1537
|
|
|
|
|
1538
|
|
|
/** |
|
1539
|
|
|
* @see Event::PROJECT_ACCESS_CHANGE |
|
1540
|
|
|
* @param type $params |
|
1541
|
|
|
*/ |
|
1542
|
|
|
public function project_access_change($params) { |
|
1543
|
|
|
$project = ProjectManager::instance()->getProject($params['project_id']); |
|
1544
|
|
|
|
|
1545
|
|
|
$this->getGitPermissionsManager()->updateAccessForRepositories($project, $params['old_access'], $params['access']); |
|
1546
|
|
|
} |
|
1547
|
|
|
|
|
1548
|
|
|
/** |
|
1549
|
|
|
* @see Event::SITE_ACCESS_CHANGE |
|
1550
|
|
|
* @param array $params |
|
1551
|
|
|
*/ |
|
1552
|
|
|
public function site_access_change(array $params) { |
|
1553
|
|
|
$this->getGitPermissionsManager()->updateSiteAccess($params['old_value'], $params['new_value']); |
|
1554
|
|
|
} |
|
1555
|
|
|
|
|
1556
|
|
|
/** |
|
1557
|
|
|
* @param PFUser user |
|
1558
|
|
|
*/ |
|
1559
|
|
|
public function ldap_daily_synchro_update_user(PFUser $user) { |
|
1560
|
|
|
if ($user->getStatus() == PFUser::STATUS_SUSPENDED) { |
|
1561
|
|
|
$factory = $this->getGerritServerFactory(); |
|
1562
|
|
|
$gerrit_servers = $factory->getServers(); |
|
1563
|
|
|
$gerritDriverFactory = new Git_Driver_Gerrit_GerritDriverFactory ($this->getLogger()); |
|
1564
|
|
|
foreach($gerrit_servers as $server) { |
|
1565
|
|
|
$gerritDriver = $gerritDriverFactory->getDriver($server); |
|
1566
|
|
|
$gerritDriver->setUserAccountInactive($server, $user); |
|
1567
|
|
|
} |
|
1568
|
|
|
} |
|
1569
|
|
|
} |
|
1570
|
|
|
|
|
1571
|
|
|
/** @see Event::SERVICES_TRUNCATED_EMAILS */ |
|
1572
|
|
|
public function services_truncated_emails(array $params) { |
|
1573
|
|
|
$project = $params['project']; |
|
1574
|
|
|
if ($project->usesService($this->getServiceShortname())) { |
|
1575
|
|
|
$params['services'][] = $GLOBALS['Language']->getText('plugin_git', 'service_lbl_key'); |
|
1576
|
|
|
} |
|
1577
|
|
|
} |
|
1578
|
|
|
|
|
1579
|
|
|
|
|
1580
|
|
|
/** |
|
1581
|
|
|
* |
|
1582
|
|
|
* @param array $params |
|
1583
|
|
|
* @see Event::IMPORT_XML_PROJECT |
|
1584
|
|
|
*/ |
|
1585
|
|
|
public function importXmlProject($params) { |
|
1586
|
|
|
$importer = new GitXmlImporter( |
|
1587
|
|
|
$params['logger'], |
|
1588
|
|
|
$this->getRepositoryManager(), |
|
1589
|
|
|
$this->getRepositoryFactory(), |
|
1590
|
|
|
$this->getBackendGitolite(), |
|
1591
|
|
|
$this->getGitSystemEventManager(), |
|
1592
|
|
|
PermissionsManager::instance(), |
|
1593
|
|
|
$this->getUGroupManager() |
|
1594
|
|
|
); |
|
1595
|
|
|
|
|
1596
|
|
|
$importer->import($params['project'], UserManager::instance()->getCurrentUser(), $params['xml_content'], $params['extraction_path']); |
|
1597
|
|
|
} |
|
1598
|
|
|
} |
|
1599
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: