##// END OF EJS Templates
[API] Create groups needed when creating repo
Nicolas VINOT -
r1589:307ec693 beta
parent child Browse files
Show More
@@ -1,8 +1,6
1 1 syntax: glob
2 2 *.pyc
3 3 *.swp
4 *.ini
5 Paste*
6 4
7 5 syntax: regexp
8 6 ^build
@@ -16,4 +14,3 syntax: regexp
16 14 ^test\.db$
17 15 ^repositories\.config$
18 16 ^RhodeCode\.egg-info$
19 ^env$
@@ -11,6 +11,8 from rhodecode.model.user import UserMod
11 11 from rhodecode.model.repo_permission import RepositoryPermissionModel
12 12 from rhodecode.model.users_group import UsersGroupModel
13 13 from rhodecode.model import users_group
14 from rhodecode.model.repos_group import ReposGroupModel
15 from sqlalchemy.orm.exc import NoResultFound
14 16
15 17 log = logging.getLogger( __name__ )
16 18
@@ -59,8 +61,9 class ApiController( JSONRPCController )
59 61 :param username
60 62 """
61 63
64 try:
62 65 user = User.by_username( username )
63 if not user:
66 except NoResultFound:
64 67 return None
65 68
66 69 return dict( id = user.user_id,
@@ -109,6 +112,9 class ApiController( JSONRPCController )
109 112 :param ldap_dn:
110 113 """
111 114
115 if self.get_user( apiuser, username ):
116 raise JSONRPCError( "user %s already exist" % username )
117
112 118 try:
113 119 form_data = dict( username = username,
114 120 password = password,
@@ -191,6 +197,9 class ApiController( JSONRPCController )
191 197 :param active:
192 198 """
193 199
200 if self.get_users_group( apiuser, name ):
201 raise JSONRPCError( "users group %s already exist" % name )
202
194 203 try:
195 204 form_data = dict( users_group_name = name,
196 205 users_group_active = active )
@@ -216,8 +225,9 class ApiController( JSONRPCController )
216 225 if not users_group:
217 226 raise JSONRPCError( 'unknown users group %s' % group_name )
218 227
228 try:
219 229 user = User.by_username( user_name )
220 if not user:
230 except NoResultFound:
221 231 raise JSONRPCError( 'unknown user %s' % user_name )
222 232
223 233 ugm = UsersGroupModel().add_user_to_group( users_group, user )
@@ -237,8 +247,9 class ApiController( JSONRPCController )
237 247 :param repo_name
238 248 """
239 249
250 try:
240 251 repo = Repository.by_repo_name( repo_name )
241 if not repo:
252 except NoResultFound:
242 253 return None
243 254
244 255 members = []
@@ -287,8 +298,8 class ApiController( JSONRPCController )
287 298 return result
288 299
289 300 @HasPermissionAnyDecorator( 'hg.admin', 'hg.create.repository' )
290 def create_repo( self, apiuser, name, owner_name, description = None, repo_type = 'hg', \
291 private = False, group_name = None ):
301 def create_repo( self, apiuser, name, owner_name, description = '', repo_type = 'hg', \
302 private = False ):
292 303 """
293 304 Create a repository
294 305
@@ -298,29 +309,36 class ApiController( JSONRPCController )
298 309 :param type
299 310 :param private
300 311 :param owner_name
301 :param group_name
302 :param clone
303 312 """
304 313
305 314 try:
306 if group_name:
307 group = Group.get_by_group_name( group_name )
308 if group is None:
309 raise JSONRPCError( 'unknown group %s' % group_name )
310 else:
311 group = None
312
315 try:
313 316 owner = User.by_username( owner_name )
314 if owner is None:
317 except NoResultFound:
315 318 raise JSONRPCError( 'unknown user %s' % owner )
316 319
317 RepoModel().create( { "repo_name" : name,
318 "repo_name_full" : name,
319 "description" : description,
320 "private" : private,
321 "repo_type" : repo_type,
322 "repo_group" : group,
323 "clone_uri" : None }, owner )
320 if self.get_repo( apiuser, name ):
321 raise JSONRPCError( "repo %s already exist" % name )
322
323 groups = name.split( '/' )
324 real_name = groups[-1]
325 groups = groups[:-1]
326 parent_id = None
327 for g in groups:
328 group = Group.get_by_group_name( g )
329 if not group:
330 group = ReposGroupModel().create( dict( group_name = g,
331 group_description = '',
332 group_parent_id = parent_id ) )
333 parent_id = group.group_id
334
335 RepoModel().create( dict( repo_name = real_name,
336 repo_name_full = name,
337 description = description,
338 private = private,
339 repo_type = repo_type,
340 repo_group = parent_id,
341 clone_uri = None ), owner )
324 342 except Exception:
325 343 log.error( traceback.format_exc() )
326 344 raise JSONRPCError( 'failed to create repository %s' % name )
@@ -337,12 +355,14 class ApiController( JSONRPCController )
337 355 """
338 356
339 357 try:
358 try:
340 359 repo = Repository.by_repo_name( repo_name )
341 if not repo:
360 except NoResultFound:
342 361 raise JSONRPCError( 'unknown repository %s' % repo )
343 362
363 try:
344 364 user = User.by_username( user_name )
345 if not user:
365 except NoResultFound:
346 366 raise JSONRPCError( 'unknown user %s' % user )
347 367
348 368 RepositoryPermissionModel().updateOrDeleteUserPermission( repo, user, perm )
@@ -52,6 +52,7 class RepositoryPermissionModel(BaseMode
52 52
53 53 def deleteUserPermission(self, repository, user):
54 54 current = self.getUserPermission(repository, user)
55 if current:
55 56 Session.delete(current)
56 57 Session.commit()
57 58
@@ -59,4 +60,4 class RepositoryPermissionModel(BaseMode
59 60 if permission:
60 61 self.updateUserPermission(repository, user, permission)
61 62 else:
62 self.deleteUserPermission(repository, user) No newline at end of file
63 self.deleteUserPermission( repository, user )
@@ -130,6 +130,7 class ReposGroupModel(BaseModel):
130 130 form_data['group_parent_id'])
131 131
132 132 self.sa.commit()
133 return new_repos_group
133 134 except:
134 135 log.error(traceback.format_exc())
135 136 self.sa.rollback()
@@ -67,6 +67,11 class UsersGroupModel( BaseModel ):
67 67 raise
68 68
69 69 def add_user_to_group( self, users_group, user ):
70 for m in users_group.members:
71 u = m.user
72 if u.user_id == user.user_id:
73 return m
74
70 75 try:
71 76 users_group_member = UsersGroupMember()
72 77 users_group_member.user = user
General Comments 0
You need to be logged in to leave comments. Login now