Mercurial > kallithea
annotate rhodecode/controllers/api/api.py @ 3183:54bea1081508 beta
version bump
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 21 Jan 2013 01:10:30 +0100 |
parents | 2fb94c52e20e |
children | cd50d1b5f35b a50901f2108d |
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 | |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
30 from pylons.controllers.util import abort |
1500 | 31 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 from rhodecode.controllers.api import JSONRPCController, JSONRPCError |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
33 from rhodecode.lib.auth import PasswordGenerator, AuthUser, \ |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
34 HasPermissionAllDecorator, HasPermissionAnyDecorator, \ |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
35 HasPermissionAnyApi, HasRepoPermissionAnyApi |
2697
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
36 from rhodecode.lib.utils import map_groups, repo2db_mapper |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
37 from rhodecode.model.meta import Session |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 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
|
39 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
|
40 from rhodecode.model.user import UserModel |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
41 from rhodecode.model.users_group import UsersGroupModel |
2526 | 42 from rhodecode.model.permission import PermissionModel |
3126
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
43 from rhodecode.model.db import Repository, RhodeCodeSetting, UserIpMap |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
44 |
1593 | 45 log = logging.getLogger(__name__) |
1500 | 46 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
48 class OptionalAttr(object): |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
49 """ |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
50 Special Optional Option that defines other attribute |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
51 """ |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
52 def __init__(self, attr_name): |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
53 self.attr_name = attr_name |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
54 |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
55 def __repr__(self): |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
56 return '<OptionalAttr:%s>' % self.attr_name |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
57 |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
58 def __call__(self): |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
59 return self |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
60 #alias |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
61 OAttr = OptionalAttr |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
62 |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
63 |
2526 | 64 class Optional(object): |
65 """ | |
66 Defines an optional parameter:: | |
67 | |
68 param = param.getval() if isinstance(param, Optional) else param | |
69 param = param() if isinstance(param, Optional) else param | |
70 | |
71 is equivalent of:: | |
72 | |
73 param = Optional.extract(param) | |
74 | |
75 """ | |
76 def __init__(self, type_): | |
77 self.type_ = type_ | |
78 | |
79 def __repr__(self): | |
80 return '<Optional:%s>' % self.type_.__repr__() | |
81 | |
82 def __call__(self): | |
83 return self.getval() | |
84 | |
85 def getval(self): | |
86 """ | |
87 returns value from this Optional instance | |
88 """ | |
89 return self.type_ | |
90 | |
91 @classmethod | |
92 def extract(cls, val): | |
93 if isinstance(val, cls): | |
94 return val.getval() | |
95 return val | |
96 | |
97 | |
98 def get_user_or_error(userid): | |
99 """ | |
100 Get user by id or name or return JsonRPCError if not found | |
101 | |
102 :param userid: | |
103 """ | |
104 user = UserModel().get_user(userid) | |
105 if user is None: | |
106 raise JSONRPCError("user `%s` does not exist" % userid) | |
107 return user | |
108 | |
109 | |
110 def get_repo_or_error(repoid): | |
111 """ | |
112 Get repo by id or name or return JsonRPCError if not found | |
113 | |
114 :param userid: | |
115 """ | |
116 repo = RepoModel().get_repo(repoid) | |
117 if repo is None: | |
118 raise JSONRPCError('repository `%s` does not exist' % (repoid)) | |
119 return repo | |
120 | |
121 | |
122 def get_users_group_or_error(usersgroupid): | |
123 """ | |
124 Get users group by id or name or return JsonRPCError if not found | |
125 | |
126 :param userid: | |
127 """ | |
128 users_group = UsersGroupModel().get_group(usersgroupid) | |
129 if users_group is None: | |
130 raise JSONRPCError('users group `%s` does not exist' % usersgroupid) | |
131 return users_group | |
132 | |
133 | |
134 def get_perm_or_error(permid): | |
135 """ | |
136 Get permission by id or name or return JsonRPCError if not found | |
137 | |
138 :param userid: | |
139 """ | |
140 perm = PermissionModel().get_permission_by_name(permid) | |
141 if perm is None: | |
142 raise JSONRPCError('permission `%s` does not exist' % (permid)) | |
143 return perm | |
144 | |
145 | |
1593 | 146 class ApiController(JSONRPCController): |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
147 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 API Controller |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
149 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
150 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 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
|
152 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
|
153 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
154 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
|
155 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
156 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
157 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
|
158 errors that happens |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
159 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
160 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
161 |
1593 | 162 @HasPermissionAllDecorator('hg.admin') |
2526 | 163 def pull(self, apiuser, repoid): |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 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
|
166 |
2526 | 167 :param apiuser: |
168 :param repoid: | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
169 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
170 |
2526 | 171 repo = get_repo_or_error(repoid) |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
172 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
173 try: |
2526 | 174 ScmModel().pull_changes(repo.repo_name, |
175 self.rhodecode_user.username) | |
176 return 'Pulled from `%s`' % repo.repo_name | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
177 except Exception: |
2526 | 178 log.error(traceback.format_exc()) |
179 raise JSONRPCError( | |
180 'Unable to pull changes from `%s`' % repo.repo_name | |
181 ) | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
182 |
1593 | 183 @HasPermissionAllDecorator('hg.admin') |
2697
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
184 def rescan_repos(self, apiuser, remove_obsolete=Optional(False)): |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
185 """ |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
186 Dispatch rescan repositories action. If remove_obsolete is set |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
187 than also delete repos that are in database but not in the filesystem. |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
188 aka "clean zombies" |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
189 |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
190 :param apiuser: |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
191 :param remove_obsolete: |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
192 """ |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
193 |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
194 try: |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
195 rm_obsolete = Optional.extract(remove_obsolete) |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
196 added, removed = repo2db_mapper(ScmModel().repo_scan(), |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
197 remove_obsolete=rm_obsolete) |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
198 return {'added': added, 'removed': removed} |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
199 except Exception: |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
200 log.error(traceback.format_exc()) |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
201 raise JSONRPCError( |
2737
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
202 'Error occurred during rescan repositories action' |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
203 ) |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
204 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
205 def lock(self, apiuser, repoid, locked, userid=Optional(OAttr('apiuser'))): |
2737
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
206 """ |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
207 Set locking state on particular repository by given user, if |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
208 this command is runned by non-admin account userid is set to user |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
209 who is calling this method |
2737
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
210 |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
211 :param apiuser: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
212 :param repoid: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
213 :param userid: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
214 :param locked: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
215 """ |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
216 repo = get_repo_or_error(repoid) |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
217 if HasPermissionAnyApi('hg.admin')(user=apiuser): |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
218 pass |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
219 elif HasRepoPermissionAnyApi('repository.admin', |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
220 'repository.write')(user=apiuser, |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
221 repo_name=repo.repo_name): |
3168
2fb94c52e20e
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
3163
diff
changeset
|
222 #make sure normal user does not pass someone else userid, |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
223 #he is not allowed to do that |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
224 if not isinstance(userid, Optional) and userid != apiuser.user_id: |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
225 raise JSONRPCError( |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
226 'userid is not the same as your user' |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
227 ) |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
228 else: |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
229 raise JSONRPCError('repository `%s` does not exist' % (repoid)) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
230 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
231 if isinstance(userid, Optional): |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
232 userid = apiuser.user_id |
2737
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
233 user = get_user_or_error(userid) |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
234 locked = bool(locked) |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
235 try: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
236 if locked: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
237 Repository.lock(repo, user.user_id) |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
238 else: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
239 Repository.unlock(repo) |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
240 |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
241 return ('User `%s` set lock state for repo `%s` to `%s`' |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
242 % (user.username, repo.repo_name, locked)) |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
243 except Exception: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
244 log.error(traceback.format_exc()) |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
245 raise JSONRPCError( |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
246 'Error occurred locking repository `%s`' % repo.repo_name |
2697
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
247 ) |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
248 |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
249 @HasPermissionAllDecorator('hg.admin') |
3126
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
250 def show_ip(self, apiuser, userid): |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
251 """ |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
252 Shows IP address as seen from RhodeCode server, together with all |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
253 defined IP addresses for given user |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
254 |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
255 :param apiuser: |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
256 :param userid: |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
257 """ |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
258 user = get_user_or_error(userid) |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
259 ips = UserIpMap.query().filter(UserIpMap.user == user).all() |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
260 return dict( |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
261 ip_addr_server=self.ip_addr, |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
262 user_ips=ips |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
263 ) |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
264 |
3162
a0a8f38e8fb8
API method get_user can be executed by non-admin users ref #539
Marcin Kuzminski <marcin@python-works.com>
parents:
3161
diff
changeset
|
265 def get_user(self, apiuser, userid=Optional(OAttr('apiuser'))): |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
266 """" |
3162
a0a8f38e8fb8
API method get_user can be executed by non-admin users ref #539
Marcin Kuzminski <marcin@python-works.com>
parents:
3161
diff
changeset
|
267 Get a user by username, or userid, if userid is given |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
268 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
269 :param apiuser: |
2526 | 270 :param userid: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
271 """ |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
272 if HasPermissionAnyApi('hg.admin')(user=apiuser) is False: |
3168
2fb94c52e20e
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
3163
diff
changeset
|
273 #make sure normal user does not pass someone else userid, |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
274 #he is not allowed to do that |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
275 if not isinstance(userid, Optional) and userid != apiuser.user_id: |
3162
a0a8f38e8fb8
API method get_user can be executed by non-admin users ref #539
Marcin Kuzminski <marcin@python-works.com>
parents:
3161
diff
changeset
|
276 raise JSONRPCError( |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
277 'userid is not the same as your user' |
3162
a0a8f38e8fb8
API method get_user can be executed by non-admin users ref #539
Marcin Kuzminski <marcin@python-works.com>
parents:
3161
diff
changeset
|
278 ) |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
279 |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
280 if isinstance(userid, Optional): |
3162
a0a8f38e8fb8
API method get_user can be executed by non-admin users ref #539
Marcin Kuzminski <marcin@python-works.com>
parents:
3161
diff
changeset
|
281 userid = apiuser.user_id |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
282 |
2526 | 283 user = get_user_or_error(userid) |
284 data = user.get_api_data() | |
285 data['permissions'] = AuthUser(user_id=user.user_id).permissions | |
286 return data | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
287 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
288 @HasPermissionAllDecorator('hg.admin') |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
289 def get_users(self, apiuser): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
290 """" |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
291 Get all users |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
292 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
293 :param apiuser: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
294 """ |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
295 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
296 result = [] |
2526 | 297 for user in UserModel().get_all(): |
298 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
|
299 return result |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
300 |
1593 | 301 @HasPermissionAllDecorator('hg.admin') |
2526 | 302 def create_user(self, apiuser, username, email, password, |
303 firstname=Optional(None), lastname=Optional(None), | |
304 active=Optional(True), admin=Optional(False), | |
305 ldap_dn=Optional(None)): | |
1500 | 306 """ |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
307 Create new user |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
308 |
1500 | 309 :param apiuser: |
310 :param username: | |
2526 | 311 :param email: |
1500 | 312 :param password: |
2526 | 313 :param firstname: |
1500 | 314 :param lastname: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
315 :param active: |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
316 :param admin: |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
317 :param ldap_dn: |
1500 | 318 """ |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
319 |
2526 | 320 if UserModel().get_by_username(username): |
321 raise JSONRPCError("user `%s` already exist" % username) | |
322 | |
323 if UserModel().get_by_email(email, case_insensitive=True): | |
324 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
|
325 |
2758
dc4709e7da51
fixed passing password via API create_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2737
diff
changeset
|
326 if Optional.extract(ldap_dn): |
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
|
327 # 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
|
328 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
|
329 |
1500 | 330 try: |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
331 user = UserModel().create_or_update( |
2526 | 332 username=Optional.extract(username), |
333 password=Optional.extract(password), | |
334 email=Optional.extract(email), | |
335 firstname=Optional.extract(firstname), | |
336 lastname=Optional.extract(lastname), | |
337 active=Optional.extract(active), | |
338 admin=Optional.extract(admin), | |
339 ldap_dn=Optional.extract(ldap_dn) | |
1843 | 340 ) |
2526 | 341 Session().commit() |
1843 | 342 return dict( |
2526 | 343 msg='created new user `%s`' % username, |
344 user=user.get_api_data() | |
1843 | 345 ) |
1500 | 346 except Exception: |
1593 | 347 log.error(traceback.format_exc()) |
2526 | 348 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
|
349 |
1593 | 350 @HasPermissionAllDecorator('hg.admin') |
2526 | 351 def update_user(self, apiuser, userid, username=Optional(None), |
352 email=Optional(None), firstname=Optional(None), | |
353 lastname=Optional(None), active=Optional(None), | |
354 admin=Optional(None), ldap_dn=Optional(None), | |
355 password=Optional(None)): | |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
356 """ |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
357 Updates given user |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
358 |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
359 :param apiuser: |
2526 | 360 :param userid: |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
361 :param username: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
362 :param email: |
2526 | 363 :param firstname: |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
364 :param lastname: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
365 :param active: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
366 :param admin: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
367 :param ldap_dn: |
2526 | 368 :param password: |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
369 """ |
2526 | 370 |
371 user = get_user_or_error(userid) | |
372 | |
2657
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
373 # 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
|
374 updates = {} |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
375 |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
376 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
|
377 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
|
378 updates[name] = attr |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
379 |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
380 try: |
2526 | 381 |
2657
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
382 store_update(username, 'username') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
383 store_update(password, 'password') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
384 store_update(email, 'email') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
385 store_update(firstname, 'name') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
386 store_update(lastname, 'lastname') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
387 store_update(active, 'active') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
388 store_update(admin, 'admin') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
389 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
|
390 |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
391 user = UserModel().update_user(user, **updates) |
2526 | 392 Session().commit() |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
393 return dict( |
2507
374693af2849
API: update_user returns new updated user data
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
394 msg='updated user ID:%s %s' % (user.user_id, user.username), |
2526 | 395 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
|
396 ) |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
397 except Exception: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
398 log.error(traceback.format_exc()) |
2526 | 399 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
|
400 |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
401 @HasPermissionAllDecorator('hg.admin') |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
402 def delete_user(self, apiuser, userid): |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
403 """" |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
404 Deletes an user |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
405 |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
406 :param apiuser: |
2526 | 407 :param userid: |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
408 """ |
2526 | 409 user = get_user_or_error(userid) |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
410 |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
411 try: |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
412 UserModel().delete(userid) |
2526 | 413 Session().commit() |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
414 return dict( |
2526 | 415 msg='deleted user ID:%s %s' % (user.user_id, user.username), |
416 user=None | |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
417 ) |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
418 except Exception: |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
419 log.error(traceback.format_exc()) |
2526 | 420 raise JSONRPCError('failed to delete ID:%s %s' % (user.user_id, |
421 user.username)) | |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
422 |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
423 @HasPermissionAllDecorator('hg.admin') |
2526 | 424 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
|
425 """" |
2526 | 426 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
|
427 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
428 :param apiuser: |
2526 | 429 :param usersgroupid: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
430 """ |
2526 | 431 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
|
432 |
2526 | 433 data = users_group.get_api_data() |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
434 |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
435 members = [] |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
436 for user in users_group.members: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
437 user = user.user |
2526 | 438 members.append(user.get_api_data()) |
439 data['members'] = members | |
440 return data | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
441 |
1593 | 442 @HasPermissionAllDecorator('hg.admin') |
443 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
|
444 """" |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
445 Get all users groups |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
446 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
447 :param apiuser: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
448 """ |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
449 |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
450 result = [] |
2526 | 451 for users_group in UsersGroupModel().get_all(): |
452 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
|
453 return result |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
454 |
1593 | 455 @HasPermissionAllDecorator('hg.admin') |
2526 | 456 def create_users_group(self, apiuser, group_name, active=Optional(True)): |
1500 | 457 """ |
458 Creates an new usergroup | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
459 |
2526 | 460 :param apiuser: |
1843 | 461 :param group_name: |
1500 | 462 :param active: |
463 """ | |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
464 |
2526 | 465 if UsersGroupModel().get_by_name(group_name): |
466 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
|
467 |
1500 | 468 try: |
2526 | 469 active = Optional.extract(active) |
1843 | 470 ug = UsersGroupModel().create(name=group_name, active=active) |
2526 | 471 Session().commit() |
472 return dict( | |
473 msg='created new users group `%s`' % group_name, | |
474 users_group=ug.get_api_data() | |
475 ) | |
1500 | 476 except Exception: |
1593 | 477 log.error(traceback.format_exc()) |
2526 | 478 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
|
479 |
1593 | 480 @HasPermissionAllDecorator('hg.admin') |
2526 | 481 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
|
482 """" |
2146 | 483 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
|
484 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
485 :param apiuser: |
2526 | 486 :param usersgroupid: |
487 :param userid: | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
488 """ |
2526 | 489 user = get_user_or_error(userid) |
490 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
|
491 |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
492 try: |
1593 | 493 ugm = UsersGroupModel().add_user_to_group(users_group, user) |
1989 | 494 success = True if ugm != True else False |
2526 | 495 msg = 'added member `%s` to users group `%s`' % ( |
496 user.username, users_group.users_group_name | |
497 ) | |
1989 | 498 msg = msg if success else 'User is already in that group' |
2526 | 499 Session().commit() |
1989 | 500 |
501 return dict( | |
502 success=success, | |
503 msg=msg | |
504 ) | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
505 except Exception: |
1593 | 506 log.error(traceback.format_exc()) |
2526 | 507 raise JSONRPCError( |
508 'failed to add member to users group `%s`' % ( | |
509 users_group.users_group_name | |
510 ) | |
511 ) | |
1989 | 512 |
513 @HasPermissionAllDecorator('hg.admin') | |
2526 | 514 def remove_user_from_users_group(self, apiuser, usersgroupid, userid): |
1989 | 515 """ |
516 Remove user from a group | |
517 | |
2526 | 518 :param apiuser: |
519 :param usersgroupid: | |
520 :param userid: | |
1989 | 521 """ |
2526 | 522 user = get_user_or_error(userid) |
523 users_group = get_users_group_or_error(usersgroupid) | |
1989 | 524 |
525 try: | |
2526 | 526 success = UsersGroupModel().remove_user_from_group(users_group, |
527 user) | |
528 msg = 'removed member `%s` from users group `%s`' % ( | |
529 user.username, users_group.users_group_name | |
530 ) | |
1989 | 531 msg = msg if success else "User wasn't in group" |
2526 | 532 Session().commit() |
1989 | 533 return dict(success=success, msg=msg) |
534 except Exception: | |
535 log.error(traceback.format_exc()) | |
2526 | 536 raise JSONRPCError( |
537 'failed to remove member from users group `%s`' % ( | |
538 users_group.users_group_name | |
539 ) | |
540 ) | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
541 |
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
|
542 def get_repo(self, apiuser, repoid): |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
543 """" |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
544 Get repository by name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
545 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
546 :param apiuser: |
2526 | 547 :param repoid: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
548 """ |
2526 | 549 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
|
550 |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
551 if HasPermissionAnyApi('hg.admin')(user=apiuser) is False: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
552 # check if we have admin permission for this repo ! |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
553 if HasRepoPermissionAnyApi('repository.admin')(user=apiuser, |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
554 repo_name=repo.repo_name) is False: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
555 raise JSONRPCError('repository `%s` does not exist' % (repoid)) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
556 |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
557 members = [] |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
558 for user in repo.repo_to_perm: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
559 perm = user.permission.permission_name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
560 user = user.user |
2526 | 561 user_data = user.get_api_data() |
562 user_data['type'] = "user" | |
563 user_data['permission'] = perm | |
564 members.append(user_data) | |
565 | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
566 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
|
567 perm = users_group.permission.permission_name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
568 users_group = users_group.users_group |
2526 | 569 users_group_data = users_group.get_api_data() |
570 users_group_data['type'] = "users_group" | |
571 users_group_data['permission'] = perm | |
572 members.append(users_group_data) | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
573 |
2526 | 574 data = repo.get_api_data() |
575 data['members'] = members | |
576 return data | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
577 |
1593 | 578 def get_repos(self, apiuser): |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
579 """" |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
580 Get all repositories |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
581 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
582 :param apiuser: |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
583 """ |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
584 result = [] |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
585 if HasPermissionAnyApi('hg.admin')(user=apiuser) is False: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
586 repos = RepoModel().get_all_user_repos(user=apiuser) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
587 else: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
588 repos = RepoModel().get_all() |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
589 |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
590 for repo in repos: |
2526 | 591 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
|
592 return result |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
593 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
594 @HasPermissionAllDecorator('hg.admin') |
2526 | 595 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
|
596 ret_type='all'): |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
597 """ |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
598 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
|
599 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
|
600 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
|
601 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
602 :param apiuser: |
2526 | 603 :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
|
604 :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
|
605 :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
|
606 :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
|
607 """ |
2526 | 608 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
|
609 try: |
2526 | 610 _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
|
611 flat=False) |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
612 _map = { |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
613 'all': _d + _f, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
614 'files': _f, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
615 'dirs': _d, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
616 } |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
617 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
|
618 except KeyError: |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
619 raise JSONRPCError('ret_type must be one of %s' % _map.keys()) |
2526 | 620 except Exception: |
621 log.error(traceback.format_exc()) | |
622 raise JSONRPCError( | |
623 'failed to get repo: `%s` nodes' % repo.repo_name | |
624 ) | |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
625 |
1593 | 626 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
627 def create_repo(self, apiuser, repo_name, owner=Optional(OAttr('apiuser')), |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
628 repo_type=Optional('hg'), |
2526 | 629 description=Optional(''), private=Optional(False), |
3115
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
630 clone_uri=Optional(None), landing_rev=Optional('tip'), |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
631 enable_statistics=Optional(False), |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
632 enable_locking=Optional(False), |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
633 enable_downloads=Optional(False)): |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
634 """ |
2006
34d009e5147a
added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents:
2004
diff
changeset
|
635 Create repository, if clone_url is given it makes a remote clone |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
636 if repo_name is within a group name the groups will be created |
2526 | 637 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
|
638 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
639 :param apiuser: |
1843 | 640 :param repo_name: |
2526 | 641 :param onwer: |
642 :param repo_type: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
643 :param description: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
644 :param private: |
2006
34d009e5147a
added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents:
2004
diff
changeset
|
645 :param clone_uri: |
2526 | 646 :param landing_rev: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
647 """ |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
648 if HasPermissionAnyApi('hg.admin')(user=apiuser) is False: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
649 if not isinstance(owner, Optional): |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
650 #forbid setting owner for non-admins |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
651 raise JSONRPCError( |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
652 'Only RhodeCode admin can specify `owner` param' |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
653 ) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
654 if isinstance(owner, Optional): |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
655 owner = apiuser.user_id |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
656 |
2526 | 657 owner = get_user_or_error(owner) |
658 | |
659 if RepoModel().get_by_repo_name(repo_name): | |
660 raise JSONRPCError("repo `%s` already exist" % repo_name) | |
661 | |
3115
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
662 defs = RhodeCodeSetting.get_default_repo_settings(strip_prefix=True) |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
663 if isinstance(private, Optional): |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
664 private = defs.get('repo_private') or Optional.extract(private) |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
665 if isinstance(repo_type, Optional): |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
666 repo_type = defs.get('repo_type') |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
667 if isinstance(enable_statistics, Optional): |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
668 enable_statistics = defs.get('repo_enable_statistics') |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
669 if isinstance(enable_locking, Optional): |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
670 enable_locking = defs.get('repo_enable_locking') |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
671 if isinstance(enable_downloads, Optional): |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
672 enable_downloads = defs.get('repo_enable_downloads') |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
673 |
2526 | 674 clone_uri = Optional.extract(clone_uri) |
675 description = Optional.extract(description) | |
676 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
|
677 |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
678 try: |
2526 | 679 # 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
|
680 group = map_groups(repo_name) |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
681 |
2526 | 682 repo = RepoModel().create_repo( |
683 repo_name=repo_name, | |
684 repo_type=repo_type, | |
685 description=description, | |
686 owner=owner, | |
687 private=private, | |
688 clone_uri=clone_uri, | |
689 repos_group=group, | |
690 landing_rev=landing_rev, | |
3115
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
691 enable_statistics=enable_statistics, |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
692 enable_downloads=enable_downloads, |
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3024
diff
changeset
|
693 enable_locking=enable_locking |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
694 ) |
2526 | 695 |
696 Session().commit() | |
1843 | 697 return dict( |
2526 | 698 msg="Created new repository `%s`" % (repo.repo_name), |
699 repo=repo.get_api_data() | |
1843 | 700 ) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
701 except Exception: |
1593 | 702 log.error(traceback.format_exc()) |
2526 | 703 raise JSONRPCError('failed to create repository `%s`' % repo_name) |
704 | |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
705 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository') |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
706 def fork_repo(self, apiuser, repoid, fork_name, owner=Optional(OAttr('apiuser')), |
2653
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
707 description=Optional(''), copy_permissions=Optional(False), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
708 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
|
709 repo = get_repo_or_error(repoid) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
710 repo_name = repo.repo_name |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
711 |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
712 _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
|
713 if _repo: |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
714 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
|
715 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
|
716 |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
717 if HasPermissionAnyApi('hg.admin')(user=apiuser): |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
718 pass |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
719 elif HasRepoPermissionAnyApi('repository.admin', |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
720 'repository.write', |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
721 'repository.read')(user=apiuser, |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
722 repo_name=repo.repo_name): |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
723 if not isinstance(owner, Optional): |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
724 #forbid setting owner for non-admins |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
725 raise JSONRPCError( |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
726 'Only RhodeCode admin can specify `owner` param' |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
727 ) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
728 else: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
729 raise JSONRPCError('repository `%s` does not exist' % (repoid)) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
730 |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
731 if isinstance(owner, Optional): |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
732 owner = apiuser.user_id |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
733 |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
734 owner = get_user_or_error(owner) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
735 |
2653
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
736 try: |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
737 # 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
|
738 group = map_groups(fork_name) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
739 |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
740 form_data = dict( |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
741 repo_name=fork_name, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
742 repo_name_full=fork_name, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
743 repo_group=group, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
744 repo_type=repo.repo_type, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
745 description=Optional.extract(description), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
746 private=Optional.extract(private), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
747 copy_permissions=Optional.extract(copy_permissions), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
748 landing_rev=Optional.extract(landing_rev), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
749 update_after_clone=False, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
750 fork_parent_id=repo.repo_id, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
751 ) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
752 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
|
753 return dict( |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
754 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
|
755 fork_name), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
756 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
|
757 # cann be done async |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
758 ) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
759 except Exception: |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
760 log.error(traceback.format_exc()) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
761 raise JSONRPCError( |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
762 '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
|
763 fork_name) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
764 ) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
765 |
2526 | 766 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
|
767 """ |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
768 Deletes a given repository |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
769 |
2526 | 770 :param apiuser: |
771 :param repoid: | |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
772 """ |
2526 | 773 repo = get_repo_or_error(repoid) |
774 | |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
775 if HasPermissionAnyApi('hg.admin')(user=apiuser) is False: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
776 # check if we have admin permission for this repo ! |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
777 if HasRepoPermissionAnyApi('repository.admin')(user=apiuser, |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
778 repo_name=repo.repo_name) is False: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
779 raise JSONRPCError('repository `%s` does not exist' % (repoid)) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
780 |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
781 try: |
2526 | 782 RepoModel().delete(repo) |
783 Session().commit() | |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
784 return dict( |
2526 | 785 msg='Deleted repository `%s`' % repo.repo_name, |
786 success=True | |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
787 ) |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
788 except Exception: |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
789 log.error(traceback.format_exc()) |
2526 | 790 raise JSONRPCError( |
791 'failed to delete repository `%s`' % repo.repo_name | |
792 ) | |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
793 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
794 @HasPermissionAllDecorator('hg.admin') |
2526 | 795 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
|
796 """ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
797 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
|
798 if found |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
799 |
2526 | 800 :param repoid: |
801 :param userid: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
802 :param perm: |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
803 """ |
2526 | 804 repo = get_repo_or_error(repoid) |
805 user = get_user_or_error(userid) | |
806 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
|
807 |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
808 try: |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
809 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
810 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
|
811 |
2526 | 812 Session().commit() |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
813 return dict( |
2526 | 814 msg='Granted perm: `%s` for user: `%s` in repo: `%s`' % ( |
815 perm.permission_name, user.username, repo.repo_name | |
816 ), | |
817 success=True | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
818 ) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
819 except Exception: |
1593 | 820 log.error(traceback.format_exc()) |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
821 raise JSONRPCError( |
2526 | 822 'failed to edit permission for user: `%s` in repo: `%s`' % ( |
823 userid, repoid | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
824 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
825 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
826 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
827 @HasPermissionAllDecorator('hg.admin') |
2526 | 828 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
|
829 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
830 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
|
831 |
2526 | 832 :param apiuser: |
833 :param repoid: | |
834 :param userid: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
835 """ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
836 |
2526 | 837 repo = get_repo_or_error(repoid) |
838 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
|
839 try: |
2526 | 840 |
841 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
|
842 |
2526 | 843 Session().commit() |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
844 return dict( |
2526 | 845 msg='Revoked perm for user: `%s` in repo: `%s`' % ( |
846 user.username, repo.repo_name | |
847 ), | |
848 success=True | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
849 ) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
850 except Exception: |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
851 log.error(traceback.format_exc()) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
852 raise JSONRPCError( |
2526 | 853 'failed to edit permission for user: `%s` in repo: `%s`' % ( |
854 userid, repoid | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
855 ) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
856 ) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
857 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
858 @HasPermissionAllDecorator('hg.admin') |
2526 | 859 def grant_users_group_permission(self, apiuser, repoid, usersgroupid, |
860 perm): | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
861 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
862 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
|
863 existing one if found |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
864 |
2526 | 865 :param apiuser: |
866 :param repoid: | |
867 :param usersgroupid: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
868 :param perm: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
869 """ |
2526 | 870 repo = get_repo_or_error(repoid) |
871 perm = get_perm_or_error(perm) | |
872 users_group = get_users_group_or_error(usersgroupid) | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
873 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
874 try: |
2526 | 875 RepoModel().grant_users_group_permission(repo=repo, |
876 group_name=users_group, | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
877 perm=perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
878 |
2526 | 879 Session().commit() |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
880 return dict( |
2526 | 881 msg='Granted perm: `%s` for users group: `%s` in ' |
882 'repo: `%s`' % ( | |
883 perm.permission_name, users_group.users_group_name, | |
884 repo.repo_name | |
885 ), | |
886 success=True | |
887 ) | |
888 except Exception: | |
889 log.error(traceback.format_exc()) | |
890 raise JSONRPCError( | |
891 'failed to edit permission for users group: `%s` in ' | |
892 'repo: `%s`' % ( | |
893 usersgroupid, repo.repo_name | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
894 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
895 ) |
2526 | 896 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
897 @HasPermissionAllDecorator('hg.admin') |
2526 | 898 def revoke_users_group_permission(self, apiuser, repoid, usersgroupid): |
899 """ | |
900 Revoke permission for users group on given repository | |
901 | |
902 :param apiuser: | |
903 :param repoid: | |
904 :param usersgroupid: | |
905 """ | |
906 repo = get_repo_or_error(repoid) | |
907 users_group = get_users_group_or_error(usersgroupid) | |
908 | |
909 try: | |
910 RepoModel().revoke_users_group_permission(repo=repo, | |
911 group_name=users_group) | |
912 | |
913 Session().commit() | |
914 return dict( | |
915 msg='Revoked perm for users group: `%s` in repo: `%s`' % ( | |
916 users_group.users_group_name, repo.repo_name | |
917 ), | |
918 success=True | |
919 ) | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
920 except Exception: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
921 log.error(traceback.format_exc()) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
922 raise JSONRPCError( |
2526 | 923 'failed to edit permission for users group: `%s` in ' |
924 'repo: `%s`' % ( | |
925 users_group.users_group_name, repo.repo_name | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
926 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
927 ) |