Mercurial > kallithea
annotate rhodecode/controllers/api/api.py @ 3898:c9f5a397c0dc beta
Updated boolean checks in API permissions calls
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 23 May 2013 00:01:00 +0200 |
parents | 31f8c9d76a26 |
children | 1cb0a1f82fb4 |
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 |
3808
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
28 import time |
1500 | 29 import traceback |
30 import logging | |
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 |
3502
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
37 from rhodecode.lib.utils2 import str2bool, time_to_datetime, safe_int |
3457
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
38 from rhodecode.lib import helpers as h |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
39 from rhodecode.model.meta import Session |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 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
|
41 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
|
42 from rhodecode.model.user import UserModel |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3410
diff
changeset
|
43 from rhodecode.model.users_group import UserGroupModel |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3714
diff
changeset
|
44 from rhodecode.model.db import Repository, RhodeCodeSetting, UserIpMap,\ |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
45 Permission, User, Gist |
3502
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
46 from rhodecode.lib.compat import json |
3799
a732bbc40c7e
hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3759
diff
changeset
|
47 from rhodecode.lib.exceptions import DefaultUserException |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
48 from rhodecode.model.gist import GistModel |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
49 |
1593 | 50 log = logging.getLogger(__name__) |
1500 | 51 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
53 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
|
54 """ |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
55 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
|
56 """ |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
57 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
|
58 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
|
59 |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
60 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
|
61 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
|
62 |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
63 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
|
64 return self |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
65 #alias |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
66 OAttr = OptionalAttr |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
67 |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
68 |
2526 | 69 class Optional(object): |
70 """ | |
71 Defines an optional parameter:: | |
72 | |
73 param = param.getval() if isinstance(param, Optional) else param | |
74 param = param() if isinstance(param, Optional) else param | |
75 | |
76 is equivalent of:: | |
77 | |
78 param = Optional.extract(param) | |
79 | |
80 """ | |
81 def __init__(self, type_): | |
82 self.type_ = type_ | |
83 | |
84 def __repr__(self): | |
85 return '<Optional:%s>' % self.type_.__repr__() | |
86 | |
87 def __call__(self): | |
88 return self.getval() | |
89 | |
90 def getval(self): | |
91 """ | |
92 returns value from this Optional instance | |
93 """ | |
94 return self.type_ | |
95 | |
96 @classmethod | |
97 def extract(cls, val): | |
98 if isinstance(val, cls): | |
99 return val.getval() | |
100 return val | |
101 | |
102 | |
103 def get_user_or_error(userid): | |
104 """ | |
105 Get user by id or name or return JsonRPCError if not found | |
106 | |
107 :param userid: | |
108 """ | |
109 user = UserModel().get_user(userid) | |
110 if user is None: | |
111 raise JSONRPCError("user `%s` does not exist" % userid) | |
112 return user | |
113 | |
114 | |
115 def get_repo_or_error(repoid): | |
116 """ | |
117 Get repo by id or name or return JsonRPCError if not found | |
118 | |
3898
c9f5a397c0dc
Updated boolean checks in API permissions calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3884
diff
changeset
|
119 :param repoid: |
2526 | 120 """ |
121 repo = RepoModel().get_repo(repoid) | |
122 if repo is None: | |
123 raise JSONRPCError('repository `%s` does not exist' % (repoid)) | |
124 return repo | |
125 | |
126 | |
127 def get_users_group_or_error(usersgroupid): | |
128 """ | |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
129 Get user group by id or name or return JsonRPCError if not found |
2526 | 130 |
131 :param userid: | |
132 """ | |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3410
diff
changeset
|
133 users_group = UserGroupModel().get_group(usersgroupid) |
2526 | 134 if users_group is None: |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
135 raise JSONRPCError('user group `%s` does not exist' % usersgroupid) |
2526 | 136 return users_group |
137 | |
138 | |
139 def get_perm_or_error(permid): | |
140 """ | |
141 Get permission by id or name or return JsonRPCError if not found | |
142 | |
143 :param userid: | |
144 """ | |
3730
e42e1d4e1c47
make the permission update function idempotent
Marcin Kuzminski <marcin@python-works.com>
parents:
3714
diff
changeset
|
145 perm = Permission.get_by_key(permid) |
2526 | 146 if perm is None: |
147 raise JSONRPCError('permission `%s` does not exist' % (permid)) | |
148 return perm | |
149 | |
150 | |
1593 | 151 class ApiController(JSONRPCController): |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
152 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
153 API Controller |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
154 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
155 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
156 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
|
157 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
|
158 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
159 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
|
160 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
161 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
162 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
|
163 errors that happens |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
164 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
166 |
1593 | 167 @HasPermissionAllDecorator('hg.admin') |
2526 | 168 def pull(self, apiuser, 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 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
|
171 |
2526 | 172 :param apiuser: |
173 :param repoid: | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
174 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
175 |
2526 | 176 repo = get_repo_or_error(repoid) |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
177 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
178 try: |
2526 | 179 ScmModel().pull_changes(repo.repo_name, |
180 self.rhodecode_user.username) | |
181 return 'Pulled from `%s`' % repo.repo_name | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
182 except Exception: |
2526 | 183 log.error(traceback.format_exc()) |
184 raise JSONRPCError( | |
185 'Unable to pull changes from `%s`' % repo.repo_name | |
186 ) | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
187 |
1593 | 188 @HasPermissionAllDecorator('hg.admin') |
2697
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
189 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
|
190 """ |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
191 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
|
192 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
|
193 aka "clean zombies" |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
194 |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
195 :param apiuser: |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
196 :param remove_obsolete: |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
197 """ |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
198 |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
199 try: |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
200 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
|
201 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
|
202 remove_obsolete=rm_obsolete) |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
203 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
|
204 except Exception: |
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
205 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
|
206 raise JSONRPCError( |
2737
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
207 'Error occurred during rescan repositories action' |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
208 ) |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
209 |
3235
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
210 def invalidate_cache(self, apiuser, repoid): |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
211 """ |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
212 Dispatch cache invalidation action on given repo |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
213 |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
214 :param apiuser: |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
215 :param repoid: |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
216 """ |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
217 repo = get_repo_or_error(repoid) |
3898
c9f5a397c0dc
Updated boolean checks in API permissions calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3884
diff
changeset
|
218 if not HasPermissionAnyApi('hg.admin')(user=apiuser): |
3235
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
219 # check if we have admin permission for this repo ! |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
220 if HasRepoPermissionAnyApi('repository.admin', |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
221 'repository.write')(user=apiuser, |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
222 repo_name=repo.repo_name) is False: |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
223 raise JSONRPCError('repository `%s` does not exist' % (repoid)) |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
224 |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
225 try: |
3759
12ca667b69b6
api: don't report invalidated cache_keys after invalidating a repo
Mads Kiilerich <madski@unity3d.com>
parents:
3730
diff
changeset
|
226 ScmModel().mark_for_invalidation(repo.repo_name) |
12ca667b69b6
api: don't report invalidated cache_keys after invalidating a repo
Mads Kiilerich <madski@unity3d.com>
parents:
3730
diff
changeset
|
227 return ('Caches of repository `%s` was invalidated' % repoid) |
3235
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
228 except Exception: |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
229 log.error(traceback.format_exc()) |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
230 raise JSONRPCError( |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
231 'Error occurred during cache invalidation action' |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
232 ) |
d6029dacbcc4
API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents:
3195
diff
changeset
|
233 |
3898
c9f5a397c0dc
Updated boolean checks in API permissions calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3884
diff
changeset
|
234 # permission check inside |
3457
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
235 def lock(self, apiuser, repoid, locked=Optional(None), |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
236 userid=Optional(OAttr('apiuser'))): |
2737
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
237 """ |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
238 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
|
239 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
|
240 who is calling this method |
2737
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
241 |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
242 :param apiuser: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
243 :param repoid: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
244 :param userid: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
245 :param locked: |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
246 """ |
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
247 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
|
248 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
|
249 pass |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
250 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
|
251 '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
|
252 repo_name=repo.repo_name): |
3168
2fb94c52e20e
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
3163
diff
changeset
|
253 #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
|
254 #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
|
255 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
|
256 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
|
257 '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
|
258 ) |
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
259 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
|
260 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
|
261 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
262 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
|
263 userid = apiuser.user_id |
3457
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
264 |
2737
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
265 user = get_user_or_error(userid) |
3457
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
266 |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
267 if isinstance(locked, Optional): |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
268 lockobj = Repository.getlock(repo) |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
269 |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
270 if lockobj[0] is None: |
3808
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
271 _d = { |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
272 'repo': repo.repo_name, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
273 'locked': False, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
274 'locked_since': None, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
275 'locked_by': None, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
276 'msg': 'Repo `%s` not locked.' % repo.repo_name |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
277 } |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
278 return _d |
2737
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
279 else: |
3457
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
280 userid, time_ = lockobj |
3808
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
281 lock_user = get_user_or_error(userid) |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
282 _d = { |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
283 'repo': repo.repo_name, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
284 'locked': True, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
285 'locked_since': time_, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
286 'locked_by': lock_user.username, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
287 'msg': ('Repo `%s` locked by `%s`. ' |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
288 % (repo.repo_name, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
289 json.dumps(time_to_datetime(time_)))) |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
290 } |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
291 return _d |
2737
e21cb7b1a4a5
added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2697
diff
changeset
|
292 |
3808
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
293 # force locked state through a flag |
3457
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
294 else: |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
295 locked = str2bool(locked) |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
296 try: |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
297 if locked: |
3808
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
298 lock_time = time.time() |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
299 Repository.lock(repo, user.user_id, lock_time) |
3457
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
300 else: |
3808
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
301 lock_time = None |
3457
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
302 Repository.unlock(repo) |
3808
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
303 _d = { |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
304 'repo': repo.repo_name, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
305 'locked': locked, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
306 'locked_since': lock_time, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
307 'locked_by': user.username, |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
308 'msg': ('User `%s` set lock state for repo `%s` to `%s`' |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
309 % (user.username, repo.repo_name, locked)) |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
310 } |
2feb58495f34
locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
3799
diff
changeset
|
311 return _d |
3457
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
312 except Exception: |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
313 log.error(traceback.format_exc()) |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
314 raise JSONRPCError( |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
315 'Error occurred locking repository `%s`' % repo.repo_name |
08e8115585bd
calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents:
3450
diff
changeset
|
316 ) |
2697
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
317 |
3502
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
318 def get_locks(self, apiuser, userid=Optional(OAttr('apiuser'))): |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
319 """ |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
320 Get all locks for given userid, if |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
321 this command is runned by non-admin account userid is set to user |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
322 who is calling this method, thus returning locks for himself |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
323 |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
324 :param apiuser: |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
325 :param userid: |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
326 """ |
3898
c9f5a397c0dc
Updated boolean checks in API permissions calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3884
diff
changeset
|
327 |
c9f5a397c0dc
Updated boolean checks in API permissions calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3884
diff
changeset
|
328 if not HasPermissionAnyApi('hg.admin')(user=apiuser): |
3502
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
329 #make sure normal user does not pass someone else userid, |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
330 #he is not allowed to do that |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
331 if not isinstance(userid, Optional) and userid != apiuser.user_id: |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
332 raise JSONRPCError( |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
333 'userid is not the same as your user' |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
334 ) |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
335 ret = [] |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
336 if isinstance(userid, Optional): |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
337 user = None |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
338 else: |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
339 user = get_user_or_error(userid) |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
340 |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
341 #show all locks |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
342 for r in Repository.getAll(): |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
343 userid, time_ = r.locked |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
344 if time_: |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
345 _api_data = r.get_api_data() |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
346 # if we use userfilter just show the locks for this user |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
347 if user: |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
348 if safe_int(userid) == user.user_id: |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
349 ret.append(_api_data) |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
350 else: |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
351 ret.append(_api_data) |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
352 |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
353 return ret |
7cde75eac0fe
get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents:
3457
diff
changeset
|
354 |
2697
4565e655ea2a
API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents:
2657
diff
changeset
|
355 @HasPermissionAllDecorator('hg.admin') |
3126
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
356 def show_ip(self, apiuser, userid): |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
357 """ |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
358 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
|
359 defined IP addresses for given user |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
360 |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
361 :param apiuser: |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
362 :param userid: |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
363 """ |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
364 user = get_user_or_error(userid) |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
365 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
|
366 return dict( |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
367 ip_addr_server=self.ip_addr, |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
368 user_ips=ips |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
369 ) |
703070153bc1
added API method for checking IP
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
370 |
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
|
371 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
|
372 """" |
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
|
373 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
|
374 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
375 :param apiuser: |
2526 | 376 :param userid: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
377 """ |
3898
c9f5a397c0dc
Updated boolean checks in API permissions calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3884
diff
changeset
|
378 if not HasPermissionAnyApi('hg.admin')(user=apiuser): |
3168
2fb94c52e20e
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
3163
diff
changeset
|
379 #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
|
380 #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
|
381 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
|
382 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
|
383 '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
|
384 ) |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
385 |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
386 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
|
387 userid = apiuser.user_id |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
388 |
2526 | 389 user = get_user_or_error(userid) |
390 data = user.get_api_data() | |
391 data['permissions'] = AuthUser(user_id=user.user_id).permissions | |
392 return data | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
393 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
394 @HasPermissionAllDecorator('hg.admin') |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
395 def get_users(self, apiuser): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
396 """" |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
397 Get all users |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
398 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
399 :param apiuser: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
400 """ |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
401 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
402 result = [] |
3799
a732bbc40c7e
hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3759
diff
changeset
|
403 users_list = User.query().order_by(User.username)\ |
a732bbc40c7e
hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3759
diff
changeset
|
404 .filter(User.username != User.DEFAULT_USER)\ |
a732bbc40c7e
hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3759
diff
changeset
|
405 .all() |
a732bbc40c7e
hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3759
diff
changeset
|
406 for user in users_list: |
2526 | 407 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
|
408 return result |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
409 |
1593 | 410 @HasPermissionAllDecorator('hg.admin') |
3809
647fb653048e
make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3808
diff
changeset
|
411 def create_user(self, apiuser, username, email, password=Optional(None), |
2526 | 412 firstname=Optional(None), lastname=Optional(None), |
413 active=Optional(True), admin=Optional(False), | |
414 ldap_dn=Optional(None)): | |
1500 | 415 """ |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
416 Create new user |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
417 |
1500 | 418 :param apiuser: |
419 :param username: | |
2526 | 420 :param email: |
1500 | 421 :param password: |
2526 | 422 :param firstname: |
1500 | 423 :param lastname: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
424 :param active: |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
425 :param admin: |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
426 :param ldap_dn: |
1500 | 427 """ |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
428 |
2526 | 429 if UserModel().get_by_username(username): |
430 raise JSONRPCError("user `%s` already exist" % username) | |
431 | |
432 if UserModel().get_by_email(email, case_insensitive=True): | |
433 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
|
434 |
2758
dc4709e7da51
fixed passing password via API create_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2737
diff
changeset
|
435 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
|
436 # 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
|
437 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
|
438 |
1500 | 439 try: |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
440 user = UserModel().create_or_update( |
2526 | 441 username=Optional.extract(username), |
442 password=Optional.extract(password), | |
443 email=Optional.extract(email), | |
444 firstname=Optional.extract(firstname), | |
445 lastname=Optional.extract(lastname), | |
446 active=Optional.extract(active), | |
447 admin=Optional.extract(admin), | |
448 ldap_dn=Optional.extract(ldap_dn) | |
1843 | 449 ) |
2526 | 450 Session().commit() |
1843 | 451 return dict( |
2526 | 452 msg='created new user `%s`' % username, |
453 user=user.get_api_data() | |
1843 | 454 ) |
1500 | 455 except Exception: |
1593 | 456 log.error(traceback.format_exc()) |
2526 | 457 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
|
458 |
1593 | 459 @HasPermissionAllDecorator('hg.admin') |
2526 | 460 def update_user(self, apiuser, userid, username=Optional(None), |
461 email=Optional(None), firstname=Optional(None), | |
462 lastname=Optional(None), active=Optional(None), | |
463 admin=Optional(None), ldap_dn=Optional(None), | |
464 password=Optional(None)): | |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
465 """ |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
466 Updates given user |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
467 |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
468 :param apiuser: |
2526 | 469 :param userid: |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
470 :param username: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
471 :param email: |
2526 | 472 :param firstname: |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
473 :param lastname: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
474 :param active: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
475 :param admin: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
476 :param ldap_dn: |
2526 | 477 :param password: |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
478 """ |
2526 | 479 |
480 user = get_user_or_error(userid) | |
481 | |
2657
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
482 # 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
|
483 updates = {} |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
484 |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
485 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
|
486 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
|
487 updates[name] = attr |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
488 |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
489 try: |
2526 | 490 |
2657
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
491 store_update(username, 'username') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
492 store_update(password, 'password') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
493 store_update(email, 'email') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
494 store_update(firstname, 'name') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
495 store_update(lastname, 'lastname') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
496 store_update(active, 'active') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
497 store_update(admin, 'admin') |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
498 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
|
499 |
001c7e2ae986
fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents:
2653
diff
changeset
|
500 user = UserModel().update_user(user, **updates) |
2526 | 501 Session().commit() |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
502 return dict( |
2507
374693af2849
API: update_user returns new updated user data
Marcin Kuzminski <marcin@python-works.com>
parents:
2506
diff
changeset
|
503 msg='updated user ID:%s %s' % (user.user_id, user.username), |
2526 | 504 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
|
505 ) |
3799
a732bbc40c7e
hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3759
diff
changeset
|
506 except DefaultUserException: |
a732bbc40c7e
hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3759
diff
changeset
|
507 log.error(traceback.format_exc()) |
a732bbc40c7e
hide listing of default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3759
diff
changeset
|
508 raise JSONRPCError('editing default user is forbidden') |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
509 except Exception: |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
510 log.error(traceback.format_exc()) |
2526 | 511 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
|
512 |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
513 @HasPermissionAllDecorator('hg.admin') |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
514 def delete_user(self, apiuser, userid): |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
515 """" |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
516 Deletes an user |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
517 |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
518 :param apiuser: |
2526 | 519 :param userid: |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
520 """ |
2526 | 521 user = get_user_or_error(userid) |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
522 |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
523 try: |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
524 UserModel().delete(userid) |
2526 | 525 Session().commit() |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
526 return dict( |
2526 | 527 msg='deleted user ID:%s %s' % (user.user_id, user.username), |
528 user=None | |
2365
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
529 ) |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
530 except Exception: |
b902baeaa494
API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents:
2338
diff
changeset
|
531 log.error(traceback.format_exc()) |
2526 | 532 raise JSONRPCError('failed to delete ID:%s %s' % (user.user_id, |
533 user.username)) | |
2002
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
534 |
bdc0ad168006
API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents:
1989
diff
changeset
|
535 @HasPermissionAllDecorator('hg.admin') |
2526 | 536 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
|
537 """" |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
538 Get user group by name or id |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
539 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
540 :param apiuser: |
2526 | 541 :param usersgroupid: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
542 """ |
2526 | 543 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
|
544 |
2526 | 545 data = users_group.get_api_data() |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
546 |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
547 members = [] |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
548 for user in users_group.members: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
549 user = user.user |
2526 | 550 members.append(user.get_api_data()) |
551 data['members'] = members | |
552 return data | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
553 |
1593 | 554 @HasPermissionAllDecorator('hg.admin') |
555 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
|
556 """" |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
557 Get all user groups |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
558 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
559 :param apiuser: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
560 """ |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
561 |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
562 result = [] |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3410
diff
changeset
|
563 for users_group in UserGroupModel().get_all(): |
2526 | 564 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
|
565 return result |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
566 |
1593 | 567 @HasPermissionAllDecorator('hg.admin') |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
568 def create_users_group(self, apiuser, group_name, |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
569 owner=Optional(OAttr('apiuser')), |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
570 active=Optional(True)): |
1500 | 571 """ |
572 Creates an new usergroup | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
573 |
2526 | 574 :param apiuser: |
1843 | 575 :param group_name: |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
576 :param owner: |
1500 | 577 :param active: |
578 """ | |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
579 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3410
diff
changeset
|
580 if UserGroupModel().get_by_name(group_name): |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
581 raise JSONRPCError("user group `%s` already exist" % group_name) |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
582 |
1500 | 583 try: |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
584 if isinstance(owner, Optional): |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
585 owner = apiuser.user_id |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
586 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
587 owner = get_user_or_error(owner) |
2526 | 588 active = Optional.extract(active) |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
589 ug = UserGroupModel().create(name=group_name, |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
590 owner=owner, |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3681
diff
changeset
|
591 active=active) |
2526 | 592 Session().commit() |
593 return dict( | |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
594 msg='created new user group `%s`' % group_name, |
2526 | 595 users_group=ug.get_api_data() |
596 ) | |
1500 | 597 except Exception: |
1593 | 598 log.error(traceback.format_exc()) |
2526 | 599 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
|
600 |
1593 | 601 @HasPermissionAllDecorator('hg.admin') |
2526 | 602 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
|
603 """" |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
604 Add a user to a user group |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
605 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
606 :param apiuser: |
2526 | 607 :param usersgroupid: |
608 :param userid: | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
609 """ |
2526 | 610 user = get_user_or_error(userid) |
611 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
|
612 |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
613 try: |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3410
diff
changeset
|
614 ugm = UserGroupModel().add_user_to_group(users_group, user) |
1989 | 615 success = True if ugm != True else False |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
616 msg = 'added member `%s` to user group `%s`' % ( |
2526 | 617 user.username, users_group.users_group_name |
618 ) | |
1989 | 619 msg = msg if success else 'User is already in that group' |
2526 | 620 Session().commit() |
1989 | 621 |
622 return dict( | |
623 success=success, | |
624 msg=msg | |
625 ) | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
626 except Exception: |
1593 | 627 log.error(traceback.format_exc()) |
2526 | 628 raise JSONRPCError( |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
629 'failed to add member to user group `%s`' % ( |
2526 | 630 users_group.users_group_name |
631 ) | |
632 ) | |
1989 | 633 |
634 @HasPermissionAllDecorator('hg.admin') | |
2526 | 635 def remove_user_from_users_group(self, apiuser, usersgroupid, userid): |
1989 | 636 """ |
637 Remove user from a group | |
638 | |
2526 | 639 :param apiuser: |
640 :param usersgroupid: | |
641 :param userid: | |
1989 | 642 """ |
2526 | 643 user = get_user_or_error(userid) |
644 users_group = get_users_group_or_error(usersgroupid) | |
1989 | 645 |
646 try: | |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3410
diff
changeset
|
647 success = UserGroupModel().remove_user_from_group(users_group, |
2526 | 648 user) |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
649 msg = 'removed member `%s` from user group `%s`' % ( |
2526 | 650 user.username, users_group.users_group_name |
651 ) | |
1989 | 652 msg = msg if success else "User wasn't in group" |
2526 | 653 Session().commit() |
1989 | 654 return dict(success=success, msg=msg) |
655 except Exception: | |
656 log.error(traceback.format_exc()) | |
2526 | 657 raise JSONRPCError( |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
658 'failed to remove member from user group `%s`' % ( |
2526 | 659 users_group.users_group_name |
660 ) | |
661 ) | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
662 |
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
|
663 def get_repo(self, apiuser, repoid): |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
664 """" |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
665 Get repository by name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
666 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
667 :param apiuser: |
2526 | 668 :param repoid: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
669 """ |
2526 | 670 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
|
671 |
3898
c9f5a397c0dc
Updated boolean checks in API permissions calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3884
diff
changeset
|
672 if not HasPermissionAnyApi('hg.admin')(user=apiuser): |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
673 # check if we have admin permission for this repo ! |
3898
c9f5a397c0dc
Updated boolean checks in API permissions calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3884
diff
changeset
|
674 if not HasRepoPermissionAnyApi('repository.admin')(user=apiuser, |
c9f5a397c0dc
Updated boolean checks in API permissions calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3884
diff
changeset
|
675 repo_name=repo.repo_name): |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
676 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
|
677 |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
678 members = [] |
3195
a50901f2108d
Added repository followers to the get_repo api function result.
aparkar <aparkar@icloud.com>
parents:
3168
diff
changeset
|
679 followers = [] |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
680 for user in repo.repo_to_perm: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
681 perm = user.permission.permission_name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
682 user = user.user |
2526 | 683 user_data = user.get_api_data() |
684 user_data['type'] = "user" | |
685 user_data['permission'] = perm | |
686 members.append(user_data) | |
687 | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
688 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
|
689 perm = users_group.permission.permission_name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
690 users_group = users_group.users_group |
2526 | 691 users_group_data = users_group.get_api_data() |
692 users_group_data['type'] = "users_group" | |
693 users_group_data['permission'] = perm | |
694 members.append(users_group_data) | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
695 |
3195
a50901f2108d
Added repository followers to the get_repo api function result.
aparkar <aparkar@icloud.com>
parents:
3168
diff
changeset
|
696 for user in repo.followers: |
a50901f2108d
Added repository followers to the get_repo api function result.
aparkar <aparkar@icloud.com>
parents:
3168
diff
changeset
|
697 followers.append(user.user.get_api_data()) |
a50901f2108d
Added repository followers to the get_repo api function result.
aparkar <aparkar@icloud.com>
parents:
3168
diff
changeset
|
698 |
2526 | 699 data = repo.get_api_data() |
700 data['members'] = members | |
3195
a50901f2108d
Added repository followers to the get_repo api function result.
aparkar <aparkar@icloud.com>
parents:
3168
diff
changeset
|
701 data['followers'] = followers |
2526 | 702 return data |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
703 |
3898
c9f5a397c0dc
Updated boolean checks in API permissions calls
Marcin Kuzminski <marcin@python-works.com>
parents:
3884
diff
changeset
|
704 # permission check inside |
1593 | 705 def get_repos(self, apiuser): |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
706 """" |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
707 Get all repositories |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
708 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
709 :param apiuser: |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
710 """ |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
711 result = [] |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
712 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
|
713 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
|
714 else: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
715 repos = RepoModel().get_all() |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
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 for repo in repos: |
2526 | 718 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
|
719 return result |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
720 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
721 @HasPermissionAllDecorator('hg.admin') |
2526 | 722 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
|
723 ret_type='all'): |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
724 """ |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
725 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
|
726 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
|
727 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
|
728 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
729 :param apiuser: |
2526 | 730 :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
|
731 :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
|
732 :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
|
733 :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
|
734 """ |
2526 | 735 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
|
736 try: |
2526 | 737 _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
|
738 flat=False) |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
739 _map = { |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
740 'all': _d + _f, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
741 'files': _f, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
742 'dirs': _d, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
743 } |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
744 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
|
745 except KeyError: |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
746 raise JSONRPCError('ret_type must be one of %s' % _map.keys()) |
2526 | 747 except Exception: |
748 log.error(traceback.format_exc()) | |
749 raise JSONRPCError( | |
750 'failed to get repo: `%s` nodes' % repo.repo_name | |
751 ) | |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
752 |
1593 | 753 @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
|
754 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
|
755 repo_type=Optional('hg'), |
2526 | 756 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
|
757 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
|
758 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
|
759 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
|
760 enable_downloads=Optional(False)): |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
761 """ |
2006
34d009e5147a
added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents:
2004
diff
changeset
|
762 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
|
763 if repo_name is within a group name the groups will be created |
2526 | 764 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
|
765 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
766 :param apiuser: |
1843 | 767 :param repo_name: |
2526 | 768 :param onwer: |
769 :param repo_type: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
770 :param description: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
771 :param private: |
2006
34d009e5147a
added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents:
2004
diff
changeset
|
772 :param clone_uri: |
2526 | 773 :param landing_rev: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
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 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
|
777 #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
|
778 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
|
779 '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
|
780 ) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
781 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
|
782 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
|
783 |
2526 | 784 owner = get_user_or_error(owner) |
785 | |
786 if RepoModel().get_by_repo_name(repo_name): | |
787 raise JSONRPCError("repo `%s` already exist" % repo_name) | |
788 | |
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
|
789 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
|
790 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
|
791 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
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 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
|
798 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
|
799 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
|
800 |
2526 | 801 clone_uri = Optional.extract(clone_uri) |
802 description = Optional.extract(description) | |
803 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
|
804 |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
805 try: |
2526 | 806 # 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
|
807 group = map_groups(repo_name) |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
808 |
2526 | 809 repo = RepoModel().create_repo( |
810 repo_name=repo_name, | |
811 repo_type=repo_type, | |
812 description=description, | |
813 owner=owner, | |
814 private=private, | |
815 clone_uri=clone_uri, | |
816 repos_group=group, | |
817 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
|
818 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
|
819 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
|
820 enable_locking=enable_locking |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
821 ) |
2526 | 822 |
823 Session().commit() | |
1843 | 824 return dict( |
2526 | 825 msg="Created new repository `%s`" % (repo.repo_name), |
826 repo=repo.get_api_data() | |
1843 | 827 ) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
828 except Exception: |
1593 | 829 log.error(traceback.format_exc()) |
2526 | 830 raise JSONRPCError('failed to create repository `%s`' % repo_name) |
831 | |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
832 @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
|
833 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
|
834 description=Optional(''), copy_permissions=Optional(False), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
835 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
|
836 repo = get_repo_or_error(repoid) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
837 repo_name = repo.repo_name |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
838 |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
839 _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
|
840 if _repo: |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
841 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
|
842 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
|
843 |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
844 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
|
845 pass |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
846 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
|
847 '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
|
848 '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
|
849 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
|
850 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
|
851 #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
|
852 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
|
853 '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
|
854 ) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
855 else: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
856 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
|
857 |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
858 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
|
859 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
|
860 |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
861 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
|
862 |
2653
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
863 try: |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
864 # 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
|
865 group = map_groups(fork_name) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
866 |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
867 form_data = dict( |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
868 repo_name=fork_name, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
869 repo_name_full=fork_name, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
870 repo_group=group, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
871 repo_type=repo.repo_type, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
872 description=Optional.extract(description), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
873 private=Optional.extract(private), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
874 copy_permissions=Optional.extract(copy_permissions), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
875 landing_rev=Optional.extract(landing_rev), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
876 update_after_clone=False, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
877 fork_parent_id=repo.repo_id, |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
878 ) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
879 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
|
880 return dict( |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
881 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
|
882 fork_name), |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
883 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
|
884 # cann be done async |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
885 ) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
886 except Exception: |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
887 log.error(traceback.format_exc()) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
888 raise JSONRPCError( |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
889 '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
|
890 fork_name) |
8be70a4d72c7
Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents:
2526
diff
changeset
|
891 ) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
892 |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
893 # perms handled inside |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
894 def delete_repo(self, apiuser, repoid, forks=Optional(None)): |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
895 """ |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
896 Deletes a given repository |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
897 |
2526 | 898 :param apiuser: |
899 :param repoid: | |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
900 :param forks: detach or delete, what do do with attached forks for repo |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
901 """ |
2526 | 902 repo = get_repo_or_error(repoid) |
903 | |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
904 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
|
905 # 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
|
906 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
|
907 repo_name=repo.repo_name) is False: |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
908 raise JSONRPCError('repository `%s` does not exist' % (repoid)) |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3162
diff
changeset
|
909 |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
910 try: |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
911 handle_forks = Optional.extract(forks) |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
912 _forks_msg = '' |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
913 _forks = [f for f in repo.forks] |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
914 if handle_forks == 'detach': |
3884
31f8c9d76a26
Remove translation calls in API
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
915 _forks_msg = ' ' + 'Detached %s forks' % len(_forks) |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
916 elif handle_forks == 'delete': |
3884
31f8c9d76a26
Remove translation calls in API
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
917 _forks_msg = ' ' + 'Deleted %s forks' % len(_forks) |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
918 elif _forks: |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
919 raise JSONRPCError( |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
920 'Cannot delete `%s` it still contains attached forks' |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
921 % repo.repo_name |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
922 ) |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
923 |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
924 RepoModel().delete(repo, forks=forks) |
2526 | 925 Session().commit() |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
926 return dict( |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3502
diff
changeset
|
927 msg='Deleted repository `%s`%s' % (repo.repo_name, _forks_msg), |
2526 | 928 success=True |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
929 ) |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
930 except Exception: |
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
931 log.error(traceback.format_exc()) |
2526 | 932 raise JSONRPCError( |
933 'failed to delete repository `%s`' % repo.repo_name | |
934 ) | |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2002
diff
changeset
|
935 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
936 @HasPermissionAllDecorator('hg.admin') |
2526 | 937 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
|
938 """ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
939 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
|
940 if found |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
941 |
2526 | 942 :param repoid: |
943 :param userid: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
944 :param perm: |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
945 """ |
2526 | 946 repo = get_repo_or_error(repoid) |
947 user = get_user_or_error(userid) | |
948 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
|
949 |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
950 try: |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
951 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
952 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
|
953 |
2526 | 954 Session().commit() |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
955 return dict( |
2526 | 956 msg='Granted perm: `%s` for user: `%s` in repo: `%s`' % ( |
957 perm.permission_name, user.username, repo.repo_name | |
958 ), | |
959 success=True | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
960 ) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
961 except Exception: |
1593 | 962 log.error(traceback.format_exc()) |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
963 raise JSONRPCError( |
2526 | 964 'failed to edit permission for user: `%s` in repo: `%s`' % ( |
965 userid, repoid | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
966 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
967 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
968 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
969 @HasPermissionAllDecorator('hg.admin') |
2526 | 970 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
|
971 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
972 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
|
973 |
2526 | 974 :param apiuser: |
975 :param repoid: | |
976 :param userid: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
977 """ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
978 |
2526 | 979 repo = get_repo_or_error(repoid) |
980 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
|
981 try: |
2526 | 982 |
983 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
|
984 |
2526 | 985 Session().commit() |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
986 return dict( |
2526 | 987 msg='Revoked perm for user: `%s` in repo: `%s`' % ( |
988 user.username, repo.repo_name | |
989 ), | |
990 success=True | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
991 ) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
992 except Exception: |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
993 log.error(traceback.format_exc()) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
994 raise JSONRPCError( |
2526 | 995 'failed to edit permission for user: `%s` in repo: `%s`' % ( |
996 userid, repoid | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
997 ) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
998 ) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
999 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
1000 @HasPermissionAllDecorator('hg.admin') |
2526 | 1001 def grant_users_group_permission(self, apiuser, repoid, usersgroupid, |
1002 perm): | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1003 """ |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
1004 Grant permission for user group on given repository, or update |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1005 existing one if found |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1006 |
2526 | 1007 :param apiuser: |
1008 :param repoid: | |
1009 :param usersgroupid: | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1010 :param perm: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1011 """ |
2526 | 1012 repo = get_repo_or_error(repoid) |
1013 perm = get_perm_or_error(perm) | |
1014 users_group = get_users_group_or_error(usersgroupid) | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1015 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1016 try: |
2526 | 1017 RepoModel().grant_users_group_permission(repo=repo, |
1018 group_name=users_group, | |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1019 perm=perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1950
diff
changeset
|
1020 |
2526 | 1021 Session().commit() |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1022 return dict( |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
1023 msg='Granted perm: `%s` for user group: `%s` in ' |
2526 | 1024 'repo: `%s`' % ( |
1025 perm.permission_name, users_group.users_group_name, | |
1026 repo.repo_name | |
1027 ), | |
1028 success=True | |
1029 ) | |
1030 except Exception: | |
1031 log.error(traceback.format_exc()) | |
1032 raise JSONRPCError( | |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
1033 'failed to edit permission for user group: `%s` in ' |
2526 | 1034 'repo: `%s`' % ( |
1035 usersgroupid, repo.repo_name | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1036 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1037 ) |
2526 | 1038 |
3161
3563c47e52fd
Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3126
diff
changeset
|
1039 @HasPermissionAllDecorator('hg.admin') |
2526 | 1040 def revoke_users_group_permission(self, apiuser, repoid, usersgroupid): |
1041 """ | |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
1042 Revoke permission for user group on given repository |
2526 | 1043 |
1044 :param apiuser: | |
1045 :param repoid: | |
1046 :param usersgroupid: | |
1047 """ | |
1048 repo = get_repo_or_error(repoid) | |
1049 users_group = get_users_group_or_error(usersgroupid) | |
1050 | |
1051 try: | |
1052 RepoModel().revoke_users_group_permission(repo=repo, | |
1053 group_name=users_group) | |
1054 | |
1055 Session().commit() | |
1056 return dict( | |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
1057 msg='Revoked perm for user group: `%s` in repo: `%s`' % ( |
2526 | 1058 users_group.users_group_name, repo.repo_name |
1059 ), | |
1060 success=True | |
1061 ) | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1062 except Exception: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1063 log.error(traceback.format_exc()) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1064 raise JSONRPCError( |
3410
5f1850e4712a
"Users groups" is grammatically incorrect English - rename to "user groups"
Mads Kiilerich <madski@unity3d.com>
parents:
3235
diff
changeset
|
1065 'failed to edit permission for user group: `%s` in ' |
2526 | 1066 'repo: `%s`' % ( |
1067 users_group.users_group_name, repo.repo_name | |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1068 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
1069 ) |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1070 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1071 def create_gist(self, apiuser, files, owner=Optional(OAttr('apiuser')), |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1072 gist_type=Optional(Gist.GIST_PUBLIC), |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1073 gist_lifetime=Optional(-1), |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1074 gist_description=Optional('')): |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1075 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1076 try: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1077 if isinstance(owner, Optional): |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1078 owner = apiuser.user_id |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1079 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1080 owner = get_user_or_error(owner) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1081 description = Optional.extract(gist_description) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1082 gist_type = Optional.extract(gist_type) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1083 gist_lifetime = Optional.extract(gist_lifetime) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1084 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1085 # files: { |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1086 # 'filename': {'content':'...', 'lexer': null}, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1087 # 'filename2': {'content':'...', 'lexer': null} |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1088 #} |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1089 gist = GistModel().create(description=description, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1090 owner=owner, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1091 gist_mapping=files, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1092 gist_type=gist_type, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1093 lifetime=gist_lifetime) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1094 Session().commit() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1095 return dict( |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1096 msg='created new gist', |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1097 gist_url=gist.gist_url(), |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1098 gist_id=gist.gist_access_id, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1099 gist_type=gist.gist_type, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1100 files=files.keys() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1101 ) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1102 except Exception: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1103 log.error(traceback.format_exc()) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1104 raise JSONRPCError('failed to create gist') |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1105 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1106 def update_gist(self, apiuser): |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1107 pass |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1108 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1109 def delete_gist(self, apiuser): |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3809
diff
changeset
|
1110 pass |