Show More
@@ -152,6 +152,32 b' OUTPUT::' | |||||
152 | error : null |
|
152 | error : null | |
153 |
|
153 | |||
154 |
|
154 | |||
|
155 | lock | |||
|
156 | ---- | |||
|
157 | ||||
|
158 | Set locking state on given repository by given user. | |||
|
159 | This command can be executed only using api_key belonging to user with admin | |||
|
160 | rights. | |||
|
161 | ||||
|
162 | INPUT:: | |||
|
163 | ||||
|
164 | id : <id_for_response> | |||
|
165 | api_key : "<api_key>" | |||
|
166 | method : "lock" | |||
|
167 | args : { | |||
|
168 | "repoid" : "<reponame or repo_id>" | |||
|
169 | "userid" : "<user_id or username>", | |||
|
170 | "locked" : "<bool true|false>" | |||
|
171 | ||||
|
172 | } | |||
|
173 | ||||
|
174 | OUTPUT:: | |||
|
175 | ||||
|
176 | id : <id_given_in_input> | |||
|
177 | result : "User `<username>` set lock state for repo `<reponame>` to `true|false`" | |||
|
178 | error : null | |||
|
179 | ||||
|
180 | ||||
155 | get_user |
|
181 | get_user | |
156 | -------- |
|
182 | -------- | |
157 |
|
183 |
@@ -38,6 +38,7 b' from rhodecode.model.repo import RepoMod' | |||||
38 | from rhodecode.model.user import UserModel |
|
38 | from rhodecode.model.user import UserModel | |
39 | from rhodecode.model.users_group import UsersGroupModel |
|
39 | from rhodecode.model.users_group import UsersGroupModel | |
40 | from rhodecode.model.permission import PermissionModel |
|
40 | from rhodecode.model.permission import PermissionModel | |
|
41 | from rhodecode.model.db import Repository | |||
41 |
|
42 | |||
42 | log = logging.getLogger(__name__) |
|
43 | log = logging.getLogger(__name__) | |
43 |
|
44 | |||
@@ -180,7 +181,34 b' class ApiController(JSONRPCController):' | |||||
180 | except Exception: |
|
181 | except Exception: | |
181 | log.error(traceback.format_exc()) |
|
182 | log.error(traceback.format_exc()) | |
182 | raise JSONRPCError( |
|
183 | raise JSONRPCError( | |
183 |
' |
|
184 | 'Error occurred during rescan repositories action' | |
|
185 | ) | |||
|
186 | ||||
|
187 | @HasPermissionAllDecorator('hg.admin') | |||
|
188 | def lock(self, apiuser, repoid, userid, locked): | |||
|
189 | """ | |||
|
190 | Set locking state on particular repository by given user | |||
|
191 | ||||
|
192 | :param apiuser: | |||
|
193 | :param repoid: | |||
|
194 | :param userid: | |||
|
195 | :param locked: | |||
|
196 | """ | |||
|
197 | repo = get_repo_or_error(repoid) | |||
|
198 | user = get_user_or_error(userid) | |||
|
199 | locked = bool(locked) | |||
|
200 | try: | |||
|
201 | if locked: | |||
|
202 | Repository.lock(repo, user.user_id) | |||
|
203 | else: | |||
|
204 | Repository.unlock(repo) | |||
|
205 | ||||
|
206 | return ('User `%s` set lock state for repo `%s` to `%s`' | |||
|
207 | % (user.username, repo.repo_name, locked)) | |||
|
208 | except Exception: | |||
|
209 | log.error(traceback.format_exc()) | |||
|
210 | raise JSONRPCError( | |||
|
211 | 'Error occurred locking repository `%s`' % repo.repo_name | |||
184 | ) |
|
212 | ) | |
185 |
|
213 | |||
186 | @HasPermissionAllDecorator('hg.admin') |
|
214 | @HasPermissionAllDecorator('hg.admin') |
@@ -10,6 +10,7 b' from rhodecode.model.users_group import ' | |||||
10 | from rhodecode.model.repo import RepoModel |
|
10 | from rhodecode.model.repo import RepoModel | |
11 | from rhodecode.model.meta import Session |
|
11 | from rhodecode.model.meta import Session | |
12 | from rhodecode.model.scm import ScmModel |
|
12 | from rhodecode.model.scm import ScmModel | |
|
13 | from rhodecode.model.db import Repository | |||
13 |
|
14 | |||
14 | API_URL = '/_admin/api' |
|
15 | API_URL = '/_admin/api' | |
15 |
|
16 | |||
@@ -230,7 +231,41 b' class BaseTestApi(object):' | |||||
230 | response = self.app.post(API_URL, content_type='application/json', |
|
231 | response = self.app.post(API_URL, content_type='application/json', | |
231 | params=params) |
|
232 | params=params) | |
232 |
|
233 | |||
233 |
expected = ' |
|
234 | expected = 'Error occurred during rescan repositories action' | |
|
235 | self._compare_error(id_, expected, given=response.body) | |||
|
236 | ||||
|
237 | def test_api_lock_repo_lock_aquire(self): | |||
|
238 | id_, params = _build_data(self.apikey, 'lock', | |||
|
239 | userid=TEST_USER_ADMIN_LOGIN, | |||
|
240 | repoid=self.REPO, | |||
|
241 | locked=True) | |||
|
242 | response = self.app.post(API_URL, content_type='application/json', | |||
|
243 | params=params) | |||
|
244 | expected = ('User `%s` set lock state for repo `%s` to `%s`' | |||
|
245 | % (TEST_USER_ADMIN_LOGIN, self.REPO, True)) | |||
|
246 | self._compare_ok(id_, expected, given=response.body) | |||
|
247 | ||||
|
248 | def test_api_lock_repo_lock_release(self): | |||
|
249 | id_, params = _build_data(self.apikey, 'lock', | |||
|
250 | userid=TEST_USER_ADMIN_LOGIN, | |||
|
251 | repoid=self.REPO, | |||
|
252 | locked=False) | |||
|
253 | response = self.app.post(API_URL, content_type='application/json', | |||
|
254 | params=params) | |||
|
255 | expected = ('User `%s` set lock state for repo `%s` to `%s`' | |||
|
256 | % (TEST_USER_ADMIN_LOGIN, self.REPO, False)) | |||
|
257 | self._compare_ok(id_, expected, given=response.body) | |||
|
258 | ||||
|
259 | @mock.patch.object(Repository, 'lock', crash) | |||
|
260 | def test_api_lock_error(self): | |||
|
261 | id_, params = _build_data(self.apikey, 'lock', | |||
|
262 | userid=TEST_USER_ADMIN_LOGIN, | |||
|
263 | repoid=self.REPO, | |||
|
264 | locked=True) | |||
|
265 | response = self.app.post(API_URL, content_type='application/json', | |||
|
266 | params=params) | |||
|
267 | ||||
|
268 | expected = 'Error occurred locking repository `%s`' % self.REPO | |||
234 | self._compare_error(id_, expected, given=response.body) |
|
269 | self._compare_error(id_, expected, given=response.body) | |
235 |
|
270 | |||
236 | def test_api_create_existing_user(self): |
|
271 | def test_api_create_existing_user(self): |
General Comments 0
You need to be logged in to leave comments.
Login now