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