Mercurial > kallithea
annotate rhodecode/controllers/api/api.py @ 2677:4fbbc65e8cd5 beta
Forbid changing changset status when it is associated with a closed pull request
- fixed some issues with cascade deleting repos with changeset statuses attached
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 30 Jul 2012 23:29:03 +0200 |
parents | 001c7e2ae986 |
children | 4565e655ea2a |
rev | line source |
---|---|
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
1 # -*- coding: utf-8 -*- |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
2 """ |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
3 rhodecode.controllers.api |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
5 |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
6 API controller for RhodeCode |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
7 |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
8 :created_on: Aug 20, 2011 |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
9 :author: marcink |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
10 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
12 """ |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
13 # This program is free software; you can redistribute it and/or |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
14 # modify it under the terms of the GNU General Public License |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
15 # as published by the Free Software Foundation; version 2 |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
16 # of the License or (at your opinion) any later version of the license. |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
17 # |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
21 # GNU General Public License for more details. |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
22 # |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
24 # along with this program; if not, write to the Free Software |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
26 # MA 02110-1301, USA. |
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
27 |
1500 | 28 import traceback |
29 import logging | |
30 | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 from rhodecode.controllers.api import JSONRPCController, JSONRPCError |
1594 | 32 from rhodecode.lib.auth import HasPermissionAllDecorator, \ |
2151
12ceeda33339
#404 API extensions for showing permission for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2146
diff
changeset
|
33 HasPermissionAnyDecorator, PasswordGenerator, AuthUser |
2526 | 34 from rhodecode.lib.utils import map_groups |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
35 from rhodecode.model.meta import Session |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 from rhodecode.model.scm import ScmModel |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
37 from rhodecode.model.repo import RepoModel |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
38 from rhodecode.model.user import UserModel |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
39 from rhodecode.model.users_group import UsersGroupModel |
2526 | 40 from rhodecode.model.permission import PermissionModel |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
41 |
1593 | 42 log = logging.getLogger(__name__) |
1500 | 43 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 |
2526 | 45 class Optional(object): |
46 """ | |
47 Defines an optional parameter:: | |
48 | |
49 param = param.getval() if isinstance(param, Optional) else param | |
50 param = param() if isinstance(param, Optional) else param | |
51 | |
52 is equivalent of:: | |
53 | |
54 param = Optional.extract(param) | |
55 | |
56 """ | |
57 def __init__(self, type_): | |
58 self.type_ = type_ | |
59 | |
60 def __repr__(self): | |
61 return '<Optional:%s>' % self.type_.__repr__() | |
62 | |
63 def __call__(self): | |
64 return self.getval() | |
65 | |
66 def getval(self): | |
67 """ | |
68 returns value from this Optional instance | |
69 """ | |
70 return self.type_ | |
71 | |
72 @classmethod | |
73 def extract(cls, val): | |
74 if isinstance(val, cls): | |
75 return val.getval() | |
76 return val | |
77 | |
78 | |
79 def get_user_or_error(userid): | |
80 """ | |
81 Get user by id or name or return JsonRPCError if not found | |
82 | |
83 :param userid: | |
84 """ | |
85 user = UserModel().get_user(userid) | |
86 if user is None: | |
87 raise JSONRPCError("user `%s` does not exist" % userid) | |
88 return user | |
89 | |
90 | |
91 def get_repo_or_error(repoid): | |
92 """ | |
93 Get repo by id or name or return JsonRPCError if not found | |
94 | |
95 :param userid: | |
96 """ | |
97 repo = RepoModel().get_repo(repoid) | |
98 if repo is None: | |
99 raise JSONRPCError('repository `%s` does not exist' % (repoid)) | |
100 return repo | |
101 | |
102 | |
103 def get_users_group_or_error(usersgroupid): | |
104 """ | |
105 Get users group by id or name or return JsonRPCError if not found | |
106 | |
107 :param userid: | |
108 """ | |
109 users_group = UsersGroupModel().get_group(usersgroupid) | |
110 if users_group is None: | |
111 raise JSONRPCError('users group `%s` does not exist' % usersgroupid) | |
112 return users_group | |
113 | |
114 | |
115 def get_perm_or_error(permid): | |
116 """ | |
117 Get permission by id or name or return JsonRPCError if not found | |
118 | |
119 :param userid: | |
120 """ | |
121 perm = PermissionModel().get_permission_by_name(permid) | |
122 if perm is None: | |
123 raise JSONRPCError('permission `%s` does not exist' % (permid)) | |
124 return perm | |
125 | |
126 | |
1593 | 127 class ApiController(JSONRPCController): |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 API Controller |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
130 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
131 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 Each method needs to have USER as argument this is then based on given |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 API_KEY propagated as instance of user object |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
134 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 Preferably this should be first argument also |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
136 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
137 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
138 Each function should also **raise** JSONRPCError for any |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 errors that happens |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
140 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 |
1593 | 143 @HasPermissionAllDecorator('hg.admin') |
2526 | 144 def pull(self, apiuser, repoid): |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 Dispatch pull action on given repo |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
147 |
2526 | 148 :param apiuser: |
149 :param repoid: | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
150 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 |
2526 | 152 repo = get_repo_or_error(repoid) |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
153 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
154 try: |
2526 | 155 ScmModel().pull_changes(repo.repo_name, |
156 self.rhodecode_user.username) | |
157 return 'Pulled from `%s`' % repo.repo_name | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
158 except Exception: |
2526 | 159 log.error(traceback.format_exc()) |
160 raise JSONRPCError( | |
161 'Unable to pull changes from `%s`' % repo.repo_name | |
162 ) | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 |
1593 | 164 @HasPermissionAllDecorator('hg.admin') |
2010
14dffcfebb02
API get_user and get_repo methods can fetch by id or names
Marcin Kuzminski <marcin@python-works.com>
parents:
2009
diff
changeset
|
165 def get_user(self, apiuser, userid): |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
166 """" |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
167 Get a user by username |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
168 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
169 :param apiuser: |
2526 | 170 :param userid: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
171 """ |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
172 |
2526 | 173 user = get_user_or_error(userid) |
174 data = user.get_api_data() | |
175 data['permissions'] = AuthUser(user_id=user.user_id).permissions | |
176 return data | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
177 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
178 @HasPermissionAllDecorator('hg.admin') |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
179 def get_users(self, apiuser): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
180 """" |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
181 Get all users |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
182 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
183 :param apiuser: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
184 """ |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
185 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
186 result = [] |
2526 | 187 for user in UserModel().get_all(): |
188 result.append(user.get_api_data()) | |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
189 return result |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
190 |
1593 | 191 @HasPermissionAllDecorator('hg.admin') |
2526 | 192 def create_user(self, apiuser, username, email, password, |
193 firstname=Optional(None), lastname=Optional(None), | |
194 active=Optional(True), admin=Optional(False), | |
195 ldap_dn=Optional(None)): | |
1500 | 196 """ |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
197 Create new user |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
198 |
1500 | 199 :param apiuser: |
200 :param username: | |
2526 | 201 :param email: |
1500 | 202 :param password: |
2526 | 203 :param firstname: |
1500 | 204 :param lastname: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
205 :param active: |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
206 :param admin: |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
207 :param ldap_dn: |
1500 | 208 """ |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
209 |
2526 | 210 if UserModel().get_by_username(username): |
211 raise JSONRPCError("user `%s` already exist" % username) | |
212 | |
213 if UserModel().get_by_email(email, case_insensitive=True): | |
214 raise JSONRPCError("email `%s` already exist" % email) | |
2008
9ddbfaeefb73
API: allowed password field to be null when used with ldap_dn ref #362
Marcin Kuzminski <marcin@python-works.com>
parents:
2006
diff
changeset
|
215 |
9ddbfaeefb73
API: allowed password field to be null when used with ldap_dn ref #362
Marcin Kuzminski <marcin@python-works.com>
parents:
2006
diff
changeset
|
216 if ldap_dn: |
9ddbfaeefb73
API: allowed password field to be null when used with ldap_dn ref #362
Marcin Kuzminski <marcin@python-works.com>
parents:
2006
diff
changeset
|
217 # generate temporary password if ldap_dn |
9ddbfaeefb73
API: allowed password field to be null when used with ldap_dn ref #362
Marcin Kuzminski <marcin@python-works.com>
parents:
2006
diff
changeset
|
218 password = PasswordGenerator().gen_password(length=8) |
9ddbfaeefb73
API: allowed password field to be null when used with ldap_dn ref #362
Marcin Kuzminski <marcin@python-works.com>
parents:
2006
diff
changeset
|
219 |
1500 | 220 try: |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
221 user = UserModel().create_or_update( |
2526 | 222 username=Optional.extract(username), |
223 password=Optional.extract(password), | |
224 email=Optional.extract(email), | |
225 firstname=Optional.extract(firstname), | |
226 lastname=Optional.extract(lastname), | |
227 active=Optional.extract(active), | |
228 admin=Optional.extract(admin), | |
229 ldap_dn=Optional.extract(ldap_dn) | |
1843 | 230 ) |
2526 | 231 Session().commit() |
1843 | 232 return dict( |
2526 | 233 msg='created new user `%s`' % username, |
234 user=user.get_api_data() | |
1843 | 235 ) |
1500 | 236 except Exception: |
1593 | 237 log.error(traceback.format_exc()) |
2526 | 238 raise JSONRPCError('failed to create user `%s`' % username) |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
239 |
1593 | 240 @HasPermissionAllDecorator('hg.admin') |
2526 | 241 def update_user(self, apiuser, userid, username=Optional(None), |
242 email=Optional(None), firstname=Optional(None), | |
243 lastname=Optional(None), active=Optional(None), | |
244 admin=Optional(None), ldap_dn=Optional(None), | |
245 password=Optional(None)): | |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
246 """ |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
247 Updates given user |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
248 |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
249 :param apiuser: |
2526 | 250 :param userid: |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
251 :param username: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
252 :param email: |
2526 | 253 :param firstname: |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
254 :param lastname: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
255 :param active: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
256 :param admin: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
257 :param ldap_dn: |
2526 | 258 :param password: |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
259 """ |
2526 | 260 |
261 user = get_user_or_error(userid) | |
262 | |
2657
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
263 # call function and store only updated arguments |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
264 updates = {} |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
265 |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
266 def store_update(attr, name): |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
267 if not isinstance(attr, Optional): |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
268 updates[name] = attr |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
269 |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
270 try: |
2526 | 271 |
2657
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
272 store_update(username, 'username') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
273 store_update(password, 'password') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
274 store_update(email, 'email') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
275 store_update(firstname, 'name') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
276 store_update(lastname, 'lastname') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
277 store_update(active, 'active') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
278 store_update(admin, 'admin') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
279 store_update(ldap_dn, 'ldap_dn') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
280 |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
281 user = UserModel().update_user(user, **updates) |
2526 | 282 Session().commit() |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
283 return dict( |
2507
374693af2849
API: update_user returns new updated user data
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
284 msg='updated user ID:%s %s' % (user.user_id, user.username), |
2526 | 285 user=user.get_api_data() |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
286 ) |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
287 except Exception: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
288 log.error(traceback.format_exc()) |
2526 | 289 raise JSONRPCError('failed to update user `%s`' % userid) |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
290 |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
291 @HasPermissionAllDecorator('hg.admin') |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
292 def delete_user(self, apiuser, userid): |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
293 """" |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
294 Deletes an user |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
295 |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
296 :param apiuser: |
2526 | 297 :param userid: |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
298 """ |
2526 | 299 user = get_user_or_error(userid) |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
300 |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
301 try: |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
302 UserModel().delete(userid) |
2526 | 303 Session().commit() |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
304 return dict( |
2526 | 305 msg='deleted user ID:%s %s' % (user.user_id, user.username), |
306 user=None | |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
307 ) |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
308 except Exception: |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
309 log.error(traceback.format_exc()) |
2526 | 310 raise JSONRPCError('failed to delete ID:%s %s' % (user.user_id, |
311 user.username)) | |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
312 |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
313 @HasPermissionAllDecorator('hg.admin') |
2526 | 314 def get_users_group(self, apiuser, usersgroupid): |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
315 """" |
2526 | 316 Get users group by name or id |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
317 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
318 :param apiuser: |
2526 | 319 :param usersgroupid: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
320 """ |
2526 | 321 users_group = get_users_group_or_error(usersgroupid) |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
322 |
2526 | 323 data = users_group.get_api_data() |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
324 |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
325 members = [] |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
326 for user in users_group.members: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
327 user = user.user |
2526 | 328 members.append(user.get_api_data()) |
329 data['members'] = members | |
330 return data | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
331 |
1593 | 332 @HasPermissionAllDecorator('hg.admin') |
333 def get_users_groups(self, apiuser): | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
334 """" |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
335 Get all users groups |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
336 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
337 :param apiuser: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
338 """ |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
339 |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
340 result = [] |
2526 | 341 for users_group in UsersGroupModel().get_all(): |
342 result.append(users_group.get_api_data()) | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
343 return result |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
344 |
1593 | 345 @HasPermissionAllDecorator('hg.admin') |
2526 | 346 def create_users_group(self, apiuser, group_name, active=Optional(True)): |
1500 | 347 """ |
348 Creates an new usergroup | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
349 |
2526 | 350 :param apiuser: |
1843 | 351 :param group_name: |
1500 | 352 :param active: |
353 """ | |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
354 |
2526 | 355 if UsersGroupModel().get_by_name(group_name): |
356 raise JSONRPCError("users group `%s` already exist" % group_name) | |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
357 |
1500 | 358 try: |
2526 | 359 active = Optional.extract(active) |
1843 | 360 ug = UsersGroupModel().create(name=group_name, active=active) |
2526 | 361 Session().commit() |
362 return dict( | |
363 msg='created new users group `%s`' % group_name, | |
364 users_group=ug.get_api_data() | |
365 ) | |
1500 | 366 except Exception: |
1593 | 367 log.error(traceback.format_exc()) |
2526 | 368 raise JSONRPCError('failed to create group `%s`' % group_name) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
369 |
1593 | 370 @HasPermissionAllDecorator('hg.admin') |
2526 | 371 def add_user_to_users_group(self, apiuser, usersgroupid, userid): |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
372 """" |
2146 | 373 Add a user to a users group |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
374 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
375 :param apiuser: |
2526 | 376 :param usersgroupid: |
377 :param userid: | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
378 """ |
2526 | 379 user = get_user_or_error(userid) |
380 users_group = get_users_group_or_error(usersgroupid) | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
381 |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
382 try: |
1593 | 383 ugm = UsersGroupModel().add_user_to_group(users_group, user) |
1989 | 384 success = True if ugm != True else False |
2526 | 385 msg = 'added member `%s` to users group `%s`' % ( |
386 user.username, users_group.users_group_name | |
387 ) | |
1989 | 388 msg = msg if success else 'User is already in that group' |
2526 | 389 Session().commit() |
1989 | 390 |
391 return dict( | |
392 success=success, | |
393 msg=msg | |
394 ) | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
395 except Exception: |
1593 | 396 log.error(traceback.format_exc()) |
2526 | 397 raise JSONRPCError( |
398 'failed to add member to users group `%s`' % ( | |
399 users_group.users_group_name | |
400 ) | |
401 ) | |
1989 | 402 |
403 @HasPermissionAllDecorator('hg.admin') | |
2526 | 404 def remove_user_from_users_group(self, apiuser, usersgroupid, userid): |
1989 | 405 """ |
406 Remove user from a group | |
407 | |
2526 | 408 :param apiuser: |
409 :param usersgroupid: | |
410 :param userid: | |
1989 | 411 """ |
2526 | 412 user = get_user_or_error(userid) |
413 users_group = get_users_group_or_error(usersgroupid) | |
1989 | 414 |
415 try: | |
2526 | 416 success = UsersGroupModel().remove_user_from_group(users_group, |
417 user) | |
418 msg = 'removed member `%s` from users group `%s`' % ( | |
419 user.username, users_group.users_group_name | |
420 ) | |
1989 | 421 msg = msg if success else "User wasn't in group" |
2526 | 422 Session().commit() |
1989 | 423 return dict(success=success, msg=msg) |
424 except Exception: | |
425 log.error(traceback.format_exc()) | |
2526 | 426 raise JSONRPCError( |
427 'failed to remove member from users group `%s`' % ( | |
428 users_group.users_group_name | |
429 ) | |
430 ) | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
431 |
1593 | 432 @HasPermissionAnyDecorator('hg.admin') |
2010
14dffcfebb02
API get_user and get_repo methods can fetch by id or names
Marcin Kuzminski <marcin@python-works.com>
parents:
2009
diff
changeset
|
433 def get_repo(self, apiuser, repoid): |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
434 """" |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
435 Get repository by name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
436 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
437 :param apiuser: |
2526 | 438 :param repoid: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
439 """ |
2526 | 440 repo = get_repo_or_error(repoid) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
441 |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
442 members = [] |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
443 for user in repo.repo_to_perm: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
444 perm = user.permission.permission_name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
445 user = user.user |
2526 | 446 user_data = user.get_api_data() |
447 user_data['type'] = "user" | |
448 user_data['permission'] = perm | |
449 members.append(user_data) | |
450 | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
451 for users_group in repo.users_group_to_perm: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
452 perm = users_group.permission.permission_name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
453 users_group = users_group.users_group |
2526 | 454 users_group_data = users_group.get_api_data() |
455 users_group_data['type'] = "users_group" | |
456 users_group_data['permission'] = perm | |
457 members.append(users_group_data) | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
458 |
2526 | 459 data = repo.get_api_data() |
460 data['members'] = members | |
461 return data | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
462 |
1593 | 463 @HasPermissionAnyDecorator('hg.admin') |
464 def get_repos(self, apiuser): | |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
465 """" |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
466 Get all repositories |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
467 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
468 :param apiuser: |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
469 """ |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
470 |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
471 result = [] |
2526 | 472 for repo in RepoModel().get_all(): |
473 result.append(repo.get_api_data()) | |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
474 return result |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
475 |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
476 @HasPermissionAnyDecorator('hg.admin') |
2526 | 477 def get_repo_nodes(self, apiuser, repoid, revision, root_path, |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
478 ret_type='all'): |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
479 """ |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
480 returns a list of nodes and it's children |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
481 for a given path at given revision. It's possible to specify ret_type |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
482 to show only files or dirs |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
483 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
484 :param apiuser: |
2526 | 485 :param repoid: name or id of repository |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
486 :param revision: revision for which listing should be done |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
487 :param root_path: path from which start displaying |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
488 :param ret_type: return type 'all|files|dirs' nodes |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
489 """ |
2526 | 490 repo = get_repo_or_error(repoid) |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
491 try: |
2526 | 492 _d, _f = ScmModel().get_nodes(repo, revision, root_path, |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
493 flat=False) |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
494 _map = { |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
495 'all': _d + _f, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
496 'files': _f, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
497 'dirs': _d, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
498 } |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
499 return _map[ret_type] |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
500 except KeyError: |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
501 raise JSONRPCError('ret_type must be one of %s' % _map.keys()) |
2526 | 502 except Exception: |
503 log.error(traceback.format_exc()) | |
504 raise JSONRPCError( | |
505 'failed to get repo: `%s` nodes' % repo.repo_name | |
506 ) | |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
507 |
1593 | 508 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') |
2526 | 509 def create_repo(self, apiuser, repo_name, owner, repo_type, |
510 description=Optional(''), private=Optional(False), | |
511 clone_uri=Optional(None), landing_rev=Optional('tip')): | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
512 """ |
2006
34d009e5147a
added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents:
2004
diff
changeset
|
513 Create repository, if clone_url is given it makes a remote clone |
2526 | 514 if repo_name is withina group name the groups will be created |
515 automatically if they aren't present | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
516 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
517 :param apiuser: |
1843 | 518 :param repo_name: |
2526 | 519 :param onwer: |
520 :param repo_type: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
521 :param description: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
522 :param private: |
2006
34d009e5147a
added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents:
2004
diff
changeset
|
523 :param clone_uri: |
2526 | 524 :param landing_rev: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
525 """ |
2526 | 526 owner = get_user_or_error(owner) |
527 | |
528 if RepoModel().get_by_repo_name(repo_name): | |
529 raise JSONRPCError("repo `%s` already exist" % repo_name) | |
530 | |
531 private = Optional.extract(private) | |
532 clone_uri = Optional.extract(clone_uri) | |
533 description = Optional.extract(description) | |
534 landing_rev = Optional.extract(landing_rev) | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
535 |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
536 try: |
2526 | 537 # create structure of groups and return the last group |
2120
d5527cebf76a
Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents:
2010
diff
changeset
|
538 group = map_groups(repo_name) |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
539 |
2526 | 540 repo = RepoModel().create_repo( |
541 repo_name=repo_name, | |
542 repo_type=repo_type, | |
543 description=description, | |
544 owner=owner, | |
545 private=private, | |
546 clone_uri=clone_uri, | |
547 repos_group=group, | |
548 landing_rev=landing_rev, | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
549 ) |
2526 | 550 |
551 Session().commit() | |
1843 | 552 |
553 return dict( | |
2526 | 554 msg="Created new repository `%s`" % (repo.repo_name), |
555 repo=repo.get_api_data() | |
1843 | 556 ) |
557 | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
558 except Exception: |
1593 | 559 log.error(traceback.format_exc()) |
2526 | 560 raise JSONRPCError('failed to create repository `%s`' % repo_name) |
561 | |
2653
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
562 @HasPermissionAnyDecorator('hg.admin') |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
563 def fork_repo(self, apiuser, repoid, fork_name, owner, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
564 description=Optional(''), copy_permissions=Optional(False), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
565 private=Optional(False), landing_rev=Optional('tip')): |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
566 repo = get_repo_or_error(repoid) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
567 repo_name = repo.repo_name |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
568 owner = get_user_or_error(owner) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
569 |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
570 _repo = RepoModel().get_by_repo_name(fork_name) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
571 if _repo: |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
572 type_ = 'fork' if _repo.fork else 'repo' |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
573 raise JSONRPCError("%s `%s` already exist" % (type_, fork_name)) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
574 |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
575 try: |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
576 # create structure of groups and return the last group |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
577 group = map_groups(fork_name) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
578 |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
579 form_data = dict( |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
580 repo_name=fork_name, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
581 repo_name_full=fork_name, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
582 repo_group=group, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
583 repo_type=repo.repo_type, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
584 description=Optional.extract(description), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
585 private=Optional.extract(private), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
586 copy_permissions=Optional.extract(copy_permissions), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
587 landing_rev=Optional.extract(landing_rev), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
588 update_after_clone=False, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
589 fork_parent_id=repo.repo_id, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
590 ) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
591 RepoModel().create_fork(form_data, cur_user=owner) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
592 return dict( |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
593 msg='Created fork of `%s` as `%s`' % (repo.repo_name, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
594 fork_name), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
595 success=True # cannot return the repo data here since fork |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
596 # cann be done async |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
597 ) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
598 except Exception: |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
599 log.error(traceback.format_exc()) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
600 raise JSONRPCError( |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
601 'failed to fork repository `%s` as `%s`' % (repo_name, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
602 fork_name) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
603 ) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
604 |
1593 | 605 @HasPermissionAnyDecorator('hg.admin') |
2526 | 606 def delete_repo(self, apiuser, repoid): |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
607 """ |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
608 Deletes a given repository |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
609 |
2526 | 610 :param apiuser: |
611 :param repoid: | |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
612 """ |
2526 | 613 repo = get_repo_or_error(repoid) |
614 | |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
615 try: |
2526 | 616 RepoModel().delete(repo) |
617 Session().commit() | |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
618 return dict( |
2526 | 619 msg='Deleted repository `%s`' % repo.repo_name, |
620 success=True | |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
621 ) |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
622 except Exception: |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
623 log.error(traceback.format_exc()) |
2526 | 624 raise JSONRPCError( |
625 'failed to delete repository `%s`' % repo.repo_name | |
626 ) | |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
627 |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
628 @HasPermissionAnyDecorator('hg.admin') |
2526 | 629 def grant_user_permission(self, apiuser, repoid, userid, perm): |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
630 """ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
631 Grant permission for user on given repository, or update existing one |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
632 if found |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
633 |
2526 | 634 :param repoid: |
635 :param userid: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
636 :param perm: |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
637 """ |
2526 | 638 repo = get_repo_or_error(repoid) |
639 user = get_user_or_error(userid) | |
640 perm = get_perm_or_error(perm) | |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
641 |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
642 try: |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
643 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
644 RepoModel().grant_user_permission(repo=repo, user=user, perm=perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
645 |
2526 | 646 Session().commit() |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
647 return dict( |
2526 | 648 msg='Granted perm: `%s` for user: `%s` in repo: `%s`' % ( |
649 perm.permission_name, user.username, repo.repo_name | |
650 ), | |
651 success=True | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
652 ) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
653 except Exception: |
1593 | 654 log.error(traceback.format_exc()) |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
655 raise JSONRPCError( |
2526 | 656 'failed to edit permission for user: `%s` in repo: `%s`' % ( |
657 userid, repoid | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
658 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
659 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
660 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
661 @HasPermissionAnyDecorator('hg.admin') |
2526 | 662 def revoke_user_permission(self, apiuser, repoid, userid): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
663 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
664 Revoke permission for user on given repository |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
665 |
2526 | 666 :param apiuser: |
667 :param repoid: | |
668 :param userid: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
669 """ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
670 |
2526 | 671 repo = get_repo_or_error(repoid) |
672 user = get_user_or_error(userid) | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
673 try: |
2526 | 674 |
675 RepoModel().revoke_user_permission(repo=repo, user=user) | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
676 |
2526 | 677 Session().commit() |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
678 return dict( |
2526 | 679 msg='Revoked perm for user: `%s` in repo: `%s`' % ( |
680 user.username, repo.repo_name | |
681 ), | |
682 success=True | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
683 ) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
684 except Exception: |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
685 log.error(traceback.format_exc()) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
686 raise JSONRPCError( |
2526 | 687 'failed to edit permission for user: `%s` in repo: `%s`' % ( |
688 userid, repoid | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
689 ) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
690 ) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
691 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
692 @HasPermissionAnyDecorator('hg.admin') |
2526 | 693 def grant_users_group_permission(self, apiuser, repoid, usersgroupid, |
694 perm): | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
695 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
696 Grant permission for users group on given repository, or update |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
697 existing one if found |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
698 |
2526 | 699 :param apiuser: |
700 :param repoid: | |
701 :param usersgroupid: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
702 :param perm: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
703 """ |
2526 | 704 repo = get_repo_or_error(repoid) |
705 perm = get_perm_or_error(perm) | |
706 users_group = get_users_group_or_error(usersgroupid) | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
707 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
708 try: |
2526 | 709 RepoModel().grant_users_group_permission(repo=repo, |
710 group_name=users_group, | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
711 perm=perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
712 |
2526 | 713 Session().commit() |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
714 return dict( |
2526 | 715 msg='Granted perm: `%s` for users group: `%s` in ' |
716 'repo: `%s`' % ( | |
717 perm.permission_name, users_group.users_group_name, | |
718 repo.repo_name | |
719 ), | |
720 success=True | |
721 ) | |
722 except Exception: | |
723 print traceback.format_exc() | |
724 log.error(traceback.format_exc()) | |
725 raise JSONRPCError( | |
726 'failed to edit permission for users group: `%s` in ' | |
727 'repo: `%s`' % ( | |
728 usersgroupid, repo.repo_name | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
729 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
730 ) |
2526 | 731 |
732 @HasPermissionAnyDecorator('hg.admin') | |
733 def revoke_users_group_permission(self, apiuser, repoid, usersgroupid): | |
734 """ | |
735 Revoke permission for users group on given repository | |
736 | |
737 :param apiuser: | |
738 :param repoid: | |
739 :param usersgroupid: | |
740 """ | |
741 repo = get_repo_or_error(repoid) | |
742 users_group = get_users_group_or_error(usersgroupid) | |
743 | |
744 try: | |
745 RepoModel().revoke_users_group_permission(repo=repo, | |
746 group_name=users_group) | |
747 | |
748 Session().commit() | |
749 return dict( | |
750 msg='Revoked perm for users group: `%s` in repo: `%s`' % ( | |
751 users_group.users_group_name, repo.repo_name | |
752 ), | |
753 success=True | |
754 ) | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
755 except Exception: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
756 log.error(traceback.format_exc()) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
757 raise JSONRPCError( |
2526 | 758 'failed to edit permission for users group: `%s` in ' |
759 'repo: `%s`' % ( | |
760 users_group.users_group_name, repo.repo_name | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
761 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
762 ) |