annotate rhodecode/controllers/api/api.py @ 3125:9b92cf5a0cca beta

Added UserIpMap interface for allowed IP addresses and IP restriction access ref #264 IP restriction for users and user groups
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 30 Dec 2012 23:06:03 +0100
parents ebd76deee70d
children 703070153bc1
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 """
3125
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
143 def _get_ip_addr(self, environ):
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
144 from rhodecode.lib.base import _get_ip_addr
9b92cf5a0cca Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents: 3115
diff changeset
145 return _get_ip_addr(environ)
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
147 @HasPermissionAllDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
148 def pull(self, apiuser, repoid):
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 """
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 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
151
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
152 :param apiuser:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
153 :param repoid:
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 """
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
156 repo = get_repo_or_error(repoid)
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
157
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158 try:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
159 ScmModel().pull_changes(repo.repo_name,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
160 self.rhodecode_user.username)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
161 return 'Pulled from `%s`' % repo.repo_name
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162 except Exception:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
163 log.error(traceback.format_exc())
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
164 raise JSONRPCError(
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
165 'Unable to pull changes from `%s`' % repo.repo_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
166 )
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
168 @HasPermissionAllDecorator('hg.admin')
2697
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
169 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
170 """
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
171 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
172 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
173 aka "clean zombies"
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 :param apiuser:
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
176 :param remove_obsolete:
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
177 """
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
178
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
179 try:
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
180 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
181 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
182 remove_obsolete=rm_obsolete)
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
183 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
184 except Exception:
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
185 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
186 raise JSONRPCError(
2737
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
187 'Error occurred during rescan repositories action'
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
188 )
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 @HasPermissionAllDecorator('hg.admin')
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
191 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
192 """
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
193 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
194
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
195 :param apiuser:
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
196 :param repoid:
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
197 :param userid:
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
198 :param locked:
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
199 """
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
200 repo = get_repo_or_error(repoid)
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
201 user = get_user_or_error(userid)
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
202 locked = bool(locked)
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
203 try:
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
204 if locked:
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
205 Repository.lock(repo, user.user_id)
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
206 else:
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
207 Repository.unlock(repo)
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
208
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
209 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
210 % (user.username, repo.repo_name, locked))
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
211 except Exception:
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
212 log.error(traceback.format_exc())
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
213 raise JSONRPCError(
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
214 '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
215 )
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
216
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2657
diff changeset
217 @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
218 def get_user(self, apiuser, userid):
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
219 """"
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
220 Get a user by username
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
221
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
222 :param apiuser:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
223 :param userid:
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
224 """
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
226 user = get_user_or_error(userid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
227 data = user.get_api_data()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
228 data['permissions'] = AuthUser(user_id=user.user_id).permissions
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
229 return data
1793
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 @HasPermissionAllDecorator('hg.admin')
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
232 def get_users(self, apiuser):
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
233 """"
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
234 Get all users
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 :param apiuser:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
237 """
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
238
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
239 result = []
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
240 for user in UserModel().get_all():
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
241 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
242 return result
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
243
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
244 @HasPermissionAllDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
245 def create_user(self, apiuser, username, email, password,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
246 firstname=Optional(None), lastname=Optional(None),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
247 active=Optional(True), admin=Optional(False),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
248 ldap_dn=Optional(None)):
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
249 """
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
250 Create new user
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
251
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
252 :param apiuser:
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
253 :param username:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
254 :param email:
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
255 :param password:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
256 :param firstname:
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
257 :param lastname:
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
258 :param active:
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
259 :param admin:
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
260 :param ldap_dn:
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
261 """
1589
307ec693bdf2 [API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1587
diff changeset
262
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
263 if UserModel().get_by_username(username):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
264 raise JSONRPCError("user `%s` already exist" % username)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
265
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
266 if UserModel().get_by_email(email, case_insensitive=True):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
267 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
268
2758
dc4709e7da51 fixed passing password via API create_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
269 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
270 # 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
271 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
272
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
273 try:
2365
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
274 user = UserModel().create_or_update(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
275 username=Optional.extract(username),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
276 password=Optional.extract(password),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
277 email=Optional.extract(email),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
278 firstname=Optional.extract(firstname),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
279 lastname=Optional.extract(lastname),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
280 active=Optional.extract(active),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
281 admin=Optional.extract(admin),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
282 ldap_dn=Optional.extract(ldap_dn)
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
283 )
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
284 Session().commit()
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
285 return dict(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
286 msg='created new user `%s`' % username,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
287 user=user.get_api_data()
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
288 )
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
289 except Exception:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
290 log.error(traceback.format_exc())
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
291 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
292
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
293 @HasPermissionAllDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
294 def update_user(self, apiuser, userid, username=Optional(None),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
295 email=Optional(None), firstname=Optional(None),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
296 lastname=Optional(None), active=Optional(None),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
297 admin=Optional(None), ldap_dn=Optional(None),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
298 password=Optional(None)):
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
299 """
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
300 Updates given user
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
301
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
302 :param apiuser:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
303 :param userid:
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
304 :param username:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
305 :param email:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
306 :param firstname:
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
307 :param lastname:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
308 :param active:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
309 :param admin:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
310 :param ldap_dn:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
311 :param password:
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
312 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
313
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
314 user = get_user_or_error(userid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
315
2657
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
316 # 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
317 updates = {}
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
318
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
319 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
320 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
321 updates[name] = attr
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
322
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
323 try:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
324
2657
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
325 store_update(username, 'username')
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
326 store_update(password, 'password')
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
327 store_update(email, 'email')
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
328 store_update(firstname, 'name')
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
329 store_update(lastname, 'lastname')
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
330 store_update(active, 'active')
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
331 store_update(admin, 'admin')
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
332 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
333
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
334 user = UserModel().update_user(user, **updates)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
335 Session().commit()
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
336 return dict(
2507
374693af2849 API: update_user returns new updated user data
Marcin Kuzminski <marcin@python-works.com>
parents: 2506
diff changeset
337 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
338 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
339 )
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
340 except Exception:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
341 log.error(traceback.format_exc())
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
342 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
343
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
344 @HasPermissionAllDecorator('hg.admin')
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
345 def delete_user(self, apiuser, userid):
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
346 """"
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
347 Deletes an user
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
348
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
349 :param apiuser:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
350 :param userid:
2365
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
351 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
352 user = get_user_or_error(userid)
2365
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
353
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
354 try:
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
355 UserModel().delete(userid)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
356 Session().commit()
2365
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
357 return dict(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
358 msg='deleted user ID:%s %s' % (user.user_id, user.username),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
359 user=None
2365
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
360 )
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
361 except Exception:
b902baeaa494 API, added delete_user method.
Marcin Kuzminski <marcin@python-works.com>
parents: 2338
diff changeset
362 log.error(traceback.format_exc())
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
363 raise JSONRPCError('failed to delete ID:%s %s' % (user.user_id,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
364 user.username))
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
365
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
366 @HasPermissionAllDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
367 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
368 """"
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
369 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
370
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
371 :param apiuser:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
372 :param usersgroupid:
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
373 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
374 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
375
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
376 data = users_group.get_api_data()
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
377
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
378 members = []
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
379 for user in users_group.members:
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
380 user = user.user
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
381 members.append(user.get_api_data())
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
382 data['members'] = members
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
383 return data
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
384
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
385 @HasPermissionAllDecorator('hg.admin')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
386 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
387 """"
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
388 Get all users groups
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
389
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
390 :param apiuser:
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
391 """
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
392
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
393 result = []
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
394 for users_group in UsersGroupModel().get_all():
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
395 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
396 return result
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
397
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
398 @HasPermissionAllDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
399 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
400 """
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
401 Creates an new usergroup
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
402
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
403 :param apiuser:
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
404 :param group_name:
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
405 :param active:
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
406 """
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
407
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
408 if UsersGroupModel().get_by_name(group_name):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
409 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
410
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
411 try:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
412 active = Optional.extract(active)
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
413 ug = UsersGroupModel().create(name=group_name, active=active)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
414 Session().commit()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
415 return dict(
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
416 msg='created new users group `%s`' % group_name,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
417 users_group=ug.get_api_data()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
418 )
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
419 except Exception:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
420 log.error(traceback.format_exc())
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
421 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
422
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
423 @HasPermissionAllDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
424 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
425 """"
2146
ee45677c4edc Api docs fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2120
diff changeset
426 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
427
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
428 :param apiuser:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
429 :param usersgroupid:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
430 :param userid:
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
431 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
432 user = get_user_or_error(userid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
433 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
434
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
435 try:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
436 ugm = UsersGroupModel().add_user_to_group(users_group, user)
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
437 success = True if ugm != True else False
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
438 msg = 'added member `%s` to users group `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
439 user.username, users_group.users_group_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
440 )
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
441 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
442 Session().commit()
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
443
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
444 return dict(
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
445 success=success,
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
446 msg=msg
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
447 )
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
448 except Exception:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
449 log.error(traceback.format_exc())
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
450 raise JSONRPCError(
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
451 'failed to add member to users group `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
452 users_group.users_group_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
453 )
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
454 )
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 @HasPermissionAllDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
457 def remove_user_from_users_group(self, apiuser, usersgroupid, userid):
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
458 """
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
459 Remove user from a group
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
460
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
461 :param apiuser:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
462 :param usersgroupid:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
463 :param userid:
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
464 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
465 user = get_user_or_error(userid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
466 users_group = get_users_group_or_error(usersgroupid)
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
467
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
468 try:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
469 success = UsersGroupModel().remove_user_from_group(users_group,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
470 user)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
471 msg = 'removed member `%s` from users group `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
472 user.username, users_group.users_group_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
473 )
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
474 msg = msg if success else "User wasn't in group"
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
475 Session().commit()
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
476 return dict(success=success, msg=msg)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
477 except Exception:
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
478 log.error(traceback.format_exc())
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
479 raise JSONRPCError(
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
480 'failed to remove member from users group `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
481 users_group.users_group_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
482 )
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
483 )
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
484
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
485 @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
486 def get_repo(self, apiuser, repoid):
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
487 """"
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
488 Get repository by name
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
489
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
490 :param apiuser:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
491 :param repoid:
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
492 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
493 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
494
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
495 members = []
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
496 for user in repo.repo_to_perm:
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
497 perm = user.permission.permission_name
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
498 user = user.user
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
499 user_data = user.get_api_data()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
500 user_data['type'] = "user"
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
501 user_data['permission'] = perm
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
502 members.append(user_data)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
503
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
504 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
505 perm = users_group.permission.permission_name
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
506 users_group = users_group.users_group
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
507 users_group_data = users_group.get_api_data()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
508 users_group_data['type'] = "users_group"
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
509 users_group_data['permission'] = perm
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
510 members.append(users_group_data)
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
511
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
512 data = repo.get_api_data()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
513 data['members'] = members
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
514 return data
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
515
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
516 @HasPermissionAnyDecorator('hg.admin')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
517 def get_repos(self, apiuser):
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
518 """"
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
519 Get all repositories
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
520
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
521 :param apiuser:
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
522 """
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
523
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
524 result = []
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
525 for repo in RepoModel().get_all():
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
526 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
527 return result
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
528
1810
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
529 @HasPermissionAnyDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
530 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
531 ret_type='all'):
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
532 """
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
533 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
534 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
535 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
536
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
537 :param apiuser:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
538 :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
539 :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
540 :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
541 :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
542 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
543 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
544 try:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
545 _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
546 flat=False)
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
547 _map = {
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
548 'all': _d + _f,
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
549 'files': _f,
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
550 'dirs': _d,
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
551 }
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
552 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
553 except KeyError:
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
554 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
555 except Exception:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
556 log.error(traceback.format_exc())
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
557 raise JSONRPCError(
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
558 'failed to get repo: `%s` nodes' % repo.repo_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
559 )
1810
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
560
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
561 @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
562 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
563 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
564 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
565 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
566 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
567 enable_downloads=Optional(False)):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
568 """
2006
34d009e5147a added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents: 2004
diff changeset
569 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
570 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
571 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
572
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
573 :param apiuser:
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
574 :param repo_name:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
575 :param onwer:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
576 :param repo_type:
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
577 :param description:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
578 :param private:
2006
34d009e5147a added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents: 2004
diff changeset
579 :param clone_uri:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
580 :param landing_rev:
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
581 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
582 owner = get_user_or_error(owner)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
583
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
584 if RepoModel().get_by_repo_name(repo_name):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
585 raise JSONRPCError("repo `%s` already exist" % repo_name)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
586
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
587 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
588 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
589 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
590 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
591 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
592 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
593 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
594 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
595 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
596 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
597 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
598
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
599 clone_uri = Optional.extract(clone_uri)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
600 description = Optional.extract(description)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
601 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
602
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
603 try:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
604 # 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
605 group = map_groups(repo_name)
1589
307ec693bdf2 [API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1587
diff changeset
606
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
607 repo = RepoModel().create_repo(
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
608 repo_name=repo_name,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
609 repo_type=repo_type,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
610 description=description,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
611 owner=owner,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
612 private=private,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
613 clone_uri=clone_uri,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
614 repos_group=group,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
615 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
616 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
617 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
618 enable_locking=enable_locking
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
619 )
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
620
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
621 Session().commit()
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
622
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
623 return dict(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
624 msg="Created new repository `%s`" % (repo.repo_name),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
625 repo=repo.get_api_data()
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
626 )
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
627
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
628 except Exception:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
629 log.error(traceback.format_exc())
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
630 raise JSONRPCError('failed to create repository `%s`' % repo_name)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
631
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
632 @HasPermissionAnyDecorator('hg.admin')
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
633 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
634 description=Optional(''), copy_permissions=Optional(False),
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
635 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
636 repo = get_repo_or_error(repoid)
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
637 repo_name = repo.repo_name
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
638 owner = get_user_or_error(owner)
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
639
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
640 _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
641 if _repo:
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
642 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
643 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
644
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
645 try:
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
646 # 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
647 group = map_groups(fork_name)
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
648
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
649 form_data = dict(
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
650 repo_name=fork_name,
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
651 repo_name_full=fork_name,
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
652 repo_group=group,
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
653 repo_type=repo.repo_type,
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
654 description=Optional.extract(description),
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
655 private=Optional.extract(private),
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
656 copy_permissions=Optional.extract(copy_permissions),
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
657 landing_rev=Optional.extract(landing_rev),
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
658 update_after_clone=False,
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
659 fork_parent_id=repo.repo_id,
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
660 )
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
661 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
662 return dict(
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
663 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
664 fork_name),
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
665 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
666 # cann be done async
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
667 )
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
668 except Exception:
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
669 log.error(traceback.format_exc())
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
670 raise JSONRPCError(
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
671 '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
672 fork_name)
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
673 )
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
674
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
675 @HasPermissionAnyDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
676 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
677 """
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
678 Deletes a given repository
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 :param apiuser:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
681 :param repoid:
2003
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
682 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
683 repo = get_repo_or_error(repoid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
684
2003
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
685 try:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
686 RepoModel().delete(repo)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
687 Session().commit()
2003
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
688 return dict(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
689 msg='Deleted repository `%s`' % repo.repo_name,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
690 success=True
2003
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
691 )
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
692 except Exception:
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
693 log.error(traceback.format_exc())
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
694 raise JSONRPCError(
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
695 'failed to delete repository `%s`' % repo.repo_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
696 )
2003
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
697
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
698 @HasPermissionAnyDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
699 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
700 """
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
701 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
702 if found
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
703
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
704 :param repoid:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
705 :param userid:
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
706 :param perm:
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
707 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
708 repo = get_repo_or_error(repoid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
709 user = get_user_or_error(userid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
710 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
711
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
712 try:
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
713
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
714 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
715
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
716 Session().commit()
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
717 return dict(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
718 msg='Granted perm: `%s` for user: `%s` in repo: `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
719 perm.permission_name, user.username, repo.repo_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
720 ),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
721 success=True
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
722 )
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
723 except Exception:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
724 log.error(traceback.format_exc())
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
725 raise JSONRPCError(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
726 'failed to edit permission for user: `%s` in repo: `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
727 userid, repoid
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
728 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
729 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
730
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
731 @HasPermissionAnyDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
732 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
733 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
734 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
735
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
736 :param apiuser:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
737 :param repoid:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
738 :param userid:
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
739 """
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
740
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
741 repo = get_repo_or_error(repoid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
742 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
743 try:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
744
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
745 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
746
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
747 Session().commit()
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
748 return dict(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
749 msg='Revoked perm for user: `%s` in repo: `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
750 user.username, repo.repo_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
751 ),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
752 success=True
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
753 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
754 except Exception:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
755 log.error(traceback.format_exc())
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
756 raise JSONRPCError(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
757 'failed to edit permission for user: `%s` in repo: `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
758 userid, repoid
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
759 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
760 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
761
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
762 @HasPermissionAnyDecorator('hg.admin')
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
763 def grant_users_group_permission(self, apiuser, repoid, usersgroupid,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
764 perm):
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
765 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
766 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
767 existing one if found
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
768
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
769 :param apiuser:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
770 :param repoid:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
771 :param usersgroupid:
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
772 :param perm:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
773 """
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
774 repo = get_repo_or_error(repoid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
775 perm = get_perm_or_error(perm)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
776 users_group = get_users_group_or_error(usersgroupid)
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
777
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
778 try:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
779 RepoModel().grant_users_group_permission(repo=repo,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
780 group_name=users_group,
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
781 perm=perm)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
782
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
783 Session().commit()
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
784 return dict(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
785 msg='Granted perm: `%s` for users group: `%s` in '
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
786 'repo: `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
787 perm.permission_name, users_group.users_group_name,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
788 repo.repo_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
789 ),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
790 success=True
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
791 )
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
792 except Exception:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
793 log.error(traceback.format_exc())
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
794 raise JSONRPCError(
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
795 'failed to edit permission for users group: `%s` in '
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
796 'repo: `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
797 usersgroupid, repo.repo_name
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
798 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
799 )
2526
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 @HasPermissionAnyDecorator('hg.admin')
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
802 def revoke_users_group_permission(self, apiuser, repoid, usersgroupid):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
803 """
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
804 Revoke permission for users group on given repository
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
805
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
806 :param apiuser:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
807 :param repoid:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
808 :param 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 repo = get_repo_or_error(repoid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
811 users_group = get_users_group_or_error(usersgroupid)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
812
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
813 try:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
814 RepoModel().revoke_users_group_permission(repo=repo,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
815 group_name=users_group)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
816
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
817 Session().commit()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
818 return dict(
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
819 msg='Revoked perm for users group: `%s` in repo: `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
820 users_group.users_group_name, repo.repo_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
821 ),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
822 success=True
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
823 )
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
824 except Exception:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
825 log.error(traceback.format_exc())
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
826 raise JSONRPCError(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
827 'failed to edit permission for users group: `%s` in '
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
828 'repo: `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents: 2507
diff changeset
829 users_group.users_group_name, repo.repo_name
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
830 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
831 )