Show More
@@ -146,7 +146,7 b' class ReposController(BaseController):' | |||
|
146 | 146 | form_result = RepoForm(repo_groups=c.repo_groups_choices, |
|
147 | 147 | landing_revs=c.landing_revs_choices)()\ |
|
148 | 148 | .to_python(dict(request.POST)) |
|
149 | RepoModel().create(form_result, self.rhodecode_user) | |
|
149 | RepoModel().create(form_result, self.rhodecode_user.user_id) | |
|
150 | 150 | if form_result['clone_uri']: |
|
151 | 151 | h.flash(_('created repository %s from %s') \ |
|
152 | 152 | % (form_result['repo_name'], form_result['clone_uri']), |
@@ -112,7 +112,7 b' def get_session():' | |||
|
112 | 112 | if CELERY_ON: |
|
113 | 113 | engine = engine_from_config(config, 'sqlalchemy.db1.') |
|
114 | 114 | init_model(engine) |
|
115 | sa = meta.Session | |
|
115 | sa = meta.Session() | |
|
116 | 116 | return sa |
|
117 | 117 | |
|
118 | 118 |
@@ -373,7 +373,7 b' def create_repo_fork(form_data, cur_user' | |||
|
373 | 373 | |
|
374 | 374 | base_path = Repository.base_path() |
|
375 | 375 | |
|
376 | fork_repo = RepoModel(DBS).create(form_data, cur_user, | |
|
376 | fork_repo = RepoModel(DBS).create(form_data, cur_user.user_id, | |
|
377 | 377 | just_db=True, fork=True) |
|
378 | 378 | |
|
379 | 379 | alias = form_data['repo_type'] |
@@ -49,6 +49,7 b' log = logging.getLogger(__name__)' | |||
|
49 | 49 | class RepoModel(BaseModel): |
|
50 | 50 | |
|
51 | 51 | cls = Repository |
|
52 | URL_SEPARATOR = Repository.url_sep() | |
|
52 | 53 | |
|
53 | 54 | def __get_users_group(self, users_group): |
|
54 | 55 | return self._get_instance(UsersGroup, users_group, |
@@ -203,37 +204,38 b' class RepoModel(BaseModel):' | |||
|
203 | 204 | log.error(traceback.format_exc()) |
|
204 | 205 | raise |
|
205 | 206 | |
|
206 | def create(self, form_data, cur_user, just_db=False, fork=False): | |
|
207 | def create_repo(self, repo_name, repo_type, description, owner, | |
|
208 | private=False, clone_uri=None, repos_group=None, | |
|
209 | landing_rev='tip', just_db=False, fork_of=None, | |
|
210 | copy_fork_permissions=False): | |
|
207 | 211 | from rhodecode.model.scm import ScmModel |
|
208 | 212 | |
|
213 | owner = self._get_user(owner) | |
|
214 | fork_of = self._get_repo(fork_of) | |
|
215 | repo_group = self.__get_repos_group(repos_group) | |
|
209 | 216 | try: |
|
210 | if fork: | |
|
211 | fork_parent_id = form_data['fork_parent_id'] | |
|
212 | 217 | |
|
213 | 218 | # repo name is just a name of repository |
|
214 | 219 | # while repo_name_full is a full qualified name that is combined |
|
215 | 220 | # with name and path of group |
|
216 |
repo_name = |
|
|
217 |
repo_name_full = |
|
|
221 | repo_name = repo_name.split(self.URL_SEPARATOR)[-1] | |
|
222 | repo_name_full = repo_name | |
|
218 | 223 | |
|
219 | 224 | new_repo = Repository() |
|
220 | 225 | new_repo.enable_statistics = False |
|
226 | new_repo.repo_name = repo_name_full | |
|
227 | new_repo.repo_type = repo_type | |
|
228 | new_repo.user = owner | |
|
229 | new_repo.group = repo_group | |
|
230 | new_repo.description = description or repo_name | |
|
231 | new_repo.private = private | |
|
232 | new_repo.clone_uri = clone_uri | |
|
233 | new_repo.landing_rev = landing_rev | |
|
221 | 234 | |
|
222 | for k, v in form_data.items(): | |
|
223 | if k == 'repo_name': | |
|
224 | v = repo_name_full | |
|
225 | if k == 'repo_group': | |
|
226 | k = 'group_id' | |
|
227 | if k == 'description': | |
|
228 | v = v or repo_name | |
|
229 | ||
|
230 | setattr(new_repo, k, v) | |
|
231 | ||
|
232 | if fork: | |
|
233 | parent_repo = Repository.get(fork_parent_id) | |
|
235 | if fork_of: | |
|
236 | parent_repo = fork_of | |
|
234 | 237 | new_repo.fork = parent_repo |
|
235 | 238 | |
|
236 | new_repo.user_id = cur_user.user_id | |
|
237 | 239 | self.sa.add(new_repo) |
|
238 | 240 | |
|
239 | 241 | def _create_default_perms(): |
@@ -245,7 +247,7 b' class RepoModel(BaseModel):' | |||
|
245 | 247 | default = p.permission.permission_name |
|
246 | 248 | break |
|
247 | 249 | |
|
248 |
default_perm = 'repository.none' if |
|
|
250 | default_perm = 'repository.none' if private else default | |
|
249 | 251 | |
|
250 | 252 | repo_to_perm.permission_id = self.sa.query(Permission)\ |
|
251 | 253 | .filter(Permission.permission_name == default_perm)\ |
@@ -256,9 +258,9 b' class RepoModel(BaseModel):' | |||
|
256 | 258 | |
|
257 | 259 | self.sa.add(repo_to_perm) |
|
258 | 260 | |
|
259 | if fork: | |
|
260 |
if |
|
|
261 |
repo = |
|
|
261 | if fork_of: | |
|
262 | if copy_fork_permissions: | |
|
263 | repo = fork_of | |
|
262 | 264 | user_perms = UserRepoToPerm.query()\ |
|
263 | 265 | .filter(UserRepoToPerm.repository == repo).all() |
|
264 | 266 | group_perms = UsersGroupRepoToPerm.query()\ |
@@ -277,20 +279,37 b' class RepoModel(BaseModel):' | |||
|
277 | 279 | _create_default_perms() |
|
278 | 280 | |
|
279 | 281 | if not just_db: |
|
280 |
self.__create_repo(repo_name, |
|
|
281 |
|
|
|
282 |
|
|
|
282 | self.__create_repo(repo_name, repo_type, | |
|
283 | repo_group, | |
|
284 | clone_uri) | |
|
283 | 285 | log_create_repository(new_repo.get_dict(), |
|
284 |
created_by= |
|
|
286 | created_by=owner.username) | |
|
285 | 287 | |
|
286 | 288 | # now automatically start following this repository as owner |
|
287 | 289 | ScmModel(self.sa).toggle_following_repo(new_repo.repo_id, |
|
288 |
|
|
|
290 | owner.user_id) | |
|
289 | 291 | return new_repo |
|
290 | 292 | except: |
|
291 | 293 | log.error(traceback.format_exc()) |
|
292 | 294 | raise |
|
293 | 295 | |
|
296 | def create(self, form_data, cur_user, just_db=False, fork=None): | |
|
297 | ||
|
298 | repo_name = form_data['repo_name_full'] | |
|
299 | repo_type = form_data['repo_type'] | |
|
300 | description = form_data['description'] | |
|
301 | owner = cur_user | |
|
302 | private = form_data['private'] | |
|
303 | clone_uri = form_data.get('clone_uri') | |
|
304 | repos_group = form_data['repo_group'] | |
|
305 | landing_rev = form_data['landing_rev'] | |
|
306 | copy_fork_permissions = form_data.get('copy_permissions') | |
|
307 | fork_of = form_data.get('fork_parent_id') | |
|
308 | return self.create_repo( | |
|
309 | repo_name, repo_type, description, owner, private, clone_uri, | |
|
310 | repos_group, landing_rev, just_db, fork_of, copy_fork_permissions | |
|
311 | ) | |
|
312 | ||
|
294 | 313 | def create_fork(self, form_data, cur_user): |
|
295 | 314 | """ |
|
296 | 315 | Simple wrapper into executing celery task for fork creation |
@@ -303,12 +322,13 b' class RepoModel(BaseModel):' | |||
|
303 | 322 | |
|
304 | 323 | def delete(self, repo): |
|
305 | 324 | repo = self._get_repo(repo) |
|
306 |
|
|
|
307 | self.sa.delete(repo) | |
|
308 |
self. |
|
|
309 | except: | |
|
310 | log.error(traceback.format_exc()) | |
|
311 | raise | |
|
325 | if repo: | |
|
326 | try: | |
|
327 | self.sa.delete(repo) | |
|
328 | self.__delete_repo(repo) | |
|
329 | except: | |
|
330 | log.error(traceback.format_exc()) | |
|
331 | raise | |
|
312 | 332 | |
|
313 | 333 | def grant_user_permission(self, repo, user, perm): |
|
314 | 334 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now