Mercurial > kallithea
comparison rhodecode/controllers/api/api.py @ 1749:8ecc6b8229a5 beta
commit less models
- models don't do any commits(with few exceptions)
- all db transactions should be handled by higher level modules like controllers, celery tasks
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 02 Dec 2011 22:31:13 +0200 |
parents | 48d4fcf04a29 |
children | 631caf880b87 |
comparison
equal
deleted
inserted
replaced
1748:a3ee2611e6e8 | 1749:8ecc6b8229a5 |
---|---|
118 raise JSONRPCError("user %s already exist" % username) | 118 raise JSONRPCError("user %s already exist" % username) |
119 | 119 |
120 try: | 120 try: |
121 UserModel().create_or_update(username, password, email, firstname, | 121 UserModel().create_or_update(username, password, email, firstname, |
122 lastname, active, admin, ldap_dn) | 122 lastname, active, admin, ldap_dn) |
123 Session().commit() | 123 Session.commit() |
124 return dict(msg='created new user %s' % username) | 124 return dict(msg='created new user %s' % username) |
125 except Exception: | 125 except Exception: |
126 log.error(traceback.format_exc()) | 126 log.error(traceback.format_exc()) |
127 raise JSONRPCError('failed to create user %s' % username) | 127 raise JSONRPCError('failed to create user %s' % username) |
128 | 128 |
196 if self.get_users_group(apiuser, name): | 196 if self.get_users_group(apiuser, name): |
197 raise JSONRPCError("users group %s already exist" % name) | 197 raise JSONRPCError("users group %s already exist" % name) |
198 | 198 |
199 try: | 199 try: |
200 ug = UsersGroupModel().create(name=name, active=active) | 200 ug = UsersGroupModel().create(name=name, active=active) |
201 Session().commit() | 201 Session.commit() |
202 return dict(id=ug.users_group_id, | 202 return dict(id=ug.users_group_id, |
203 msg='created new users group %s' % name) | 203 msg='created new users group %s' % name) |
204 except Exception: | 204 except Exception: |
205 log.error(traceback.format_exc()) | 205 log.error(traceback.format_exc()) |
206 raise JSONRPCError('failed to create group %s' % name) | 206 raise JSONRPCError('failed to create group %s' % name) |
224 user = User.get_by_username(user_name) | 224 user = User.get_by_username(user_name) |
225 except NoResultFound: | 225 except NoResultFound: |
226 raise JSONRPCError('unknown user %s' % user_name) | 226 raise JSONRPCError('unknown user %s' % user_name) |
227 | 227 |
228 ugm = UsersGroupModel().add_user_to_group(users_group, user) | 228 ugm = UsersGroupModel().add_user_to_group(users_group, user) |
229 Session().commit() | 229 Session.commit() |
230 return dict(id=ugm.users_group_member_id, | 230 return dict(id=ugm.users_group_member_id, |
231 msg='created new users group member') | 231 msg='created new users group member') |
232 except Exception: | 232 except Exception: |
233 log.error(traceback.format_exc()) | 233 log.error(traceback.format_exc()) |
234 raise JSONRPCError('failed to create users group member') | 234 raise JSONRPCError('failed to create users group member') |
240 | 240 |
241 :param apiuser | 241 :param apiuser |
242 :param repo_name | 242 :param repo_name |
243 """ | 243 """ |
244 | 244 |
245 try: | 245 repo = Repository.get_by_repo_name(repo_name) |
246 repo = Repository.get_by_repo_name(repo_name) | 246 if repo is None: |
247 except NoResultFound: | 247 raise JSONRPCError('unknown repository %s' % repo) |
248 return None | |
249 | 248 |
250 members = [] | 249 members = [] |
251 for user in repo.repo_to_perm: | 250 for user in repo.repo_to_perm: |
252 perm = user.permission.permission_name | 251 perm = user.permission.permission_name |
253 user = user.user | 252 user = user.user |
332 description=description, | 331 description=description, |
333 private=private, | 332 private=private, |
334 repo_type=repo_type, | 333 repo_type=repo_type, |
335 repo_group=parent_id, | 334 repo_group=parent_id, |
336 clone_uri=None), owner) | 335 clone_uri=None), owner) |
337 Session().commit() | 336 Session.commit() |
338 except Exception: | 337 except Exception: |
339 log.error(traceback.format_exc()) | 338 log.error(traceback.format_exc()) |
340 raise JSONRPCError('failed to create repository %s' % name) | 339 raise JSONRPCError('failed to create repository %s' % name) |
341 | 340 |
342 @HasPermissionAnyDecorator('hg.admin') | 341 @HasPermissionAnyDecorator('hg.admin') |
349 :param user_name | 348 :param user_name |
350 :param perm | 349 :param perm |
351 """ | 350 """ |
352 | 351 |
353 try: | 352 try: |
354 try: | 353 repo = Repository.get_by_repo_name(repo_name) |
355 repo = Repository.get_by_repo_name(repo_name) | 354 if repo is None: |
356 except NoResultFound: | 355 raise JSONRPCError('unknown repository %s' % repo) |
357 raise JSONRPCError('unknown repository %s' % repo) | |
358 | 356 |
359 try: | 357 try: |
360 user = User.get_by_username(user_name) | 358 user = User.get_by_username(user_name) |
361 except NoResultFound: | 359 except NoResultFound: |
362 raise JSONRPCError('unknown user %s' % user) | 360 raise JSONRPCError('unknown user %s' % user) |
363 | 361 |
364 RepositoryPermissionModel()\ | 362 RepositoryPermissionModel()\ |
365 .update_or_delete_user_permission(repo, user, perm) | 363 .update_or_delete_user_permission(repo, user, perm) |
366 Session().commit() | 364 Session.commit() |
367 except Exception: | 365 except Exception: |
368 log.error(traceback.format_exc()) | 366 log.error(traceback.format_exc()) |
369 raise JSONRPCError('failed to edit permission %(repo)s for %(user)s' | 367 raise JSONRPCError('failed to edit permission %(repo)s for %(user)s' |
370 % dict(user=user_name, repo=repo_name)) | 368 % dict(user=user_name, repo=repo_name)) |
371 | 369 |