annotate rhodecode/controllers/api/api.py @ 3115:ebd76deee70d beta

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