annotate rhodecode/controllers/api/api.py @ 2165:dc2584ba5fbc

merged beta into default branch
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 28 Mar 2012 19:54:16 +0200
parents 82a88013a3fd 12ceeda33339
children 63e58ef80ef1
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
1734
48d4fcf04a29 another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
34
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
2151
12ceeda33339 #404 API extensions for showing permission for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2146
diff changeset
37 from rhodecode.model.db import User, UsersGroup, Repository
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
38 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
39 from rhodecode.model.user import UserModel
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
40 from rhodecode.model.users_group import UsersGroupModel
2120
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2010
diff changeset
41 from rhodecode.lib.utils import map_groups
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
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
46 class ApiController(JSONRPCController):
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 """
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 API Controller
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
49
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
50
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 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
52 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
53
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 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
55
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
56
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
57 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
58 errors that happens
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
59
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 """
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
62 @HasPermissionAllDecorator('hg.admin')
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
63 def pull(self, apiuser, repo_name):
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 """
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 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
66
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
67
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
68 :param user:
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
69 :param repo_name:
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 """
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
72 if Repository.is_valid(repo_name) is False:
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
73 raise JSONRPCError('Unknown repo "%s"' % repo_name)
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
74
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 try:
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
76 ScmModel().pull_changes(repo_name, self.rhodecode_user.username)
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
77 return 'Pulled from %s' % repo_name
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 except Exception:
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
79 raise JSONRPCError('Unable to pull changes from "%s"' % repo_name)
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
81 @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
82 def get_user(self, apiuser, userid):
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
83 """"
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
84 Get a user by username
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
85
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
86 :param apiuser:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
87 :param username:
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
88 """
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89
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
90 user = UserModel().get_user(userid)
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
91 if user is None:
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
92 return user
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
93
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
94 return dict(
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
95 id=user.user_id,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
96 username=user.username,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
97 firstname=user.name,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
98 lastname=user.lastname,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
99 email=user.email,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
100 active=user.active,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
101 admin=user.admin,
2151
12ceeda33339 #404 API extensions for showing permission for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2146
diff changeset
102 ldap_dn=user.ldap_dn,
12ceeda33339 #404 API extensions for showing permission for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2146
diff changeset
103 last_login=user.last_login,
12ceeda33339 #404 API extensions for showing permission for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2146
diff changeset
104 permissions=AuthUser(user_id=user.user_id).permissions
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
105 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
106
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
107 @HasPermissionAllDecorator('hg.admin')
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
108 def get_users(self, apiuser):
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
109 """"
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
110 Get all users
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
111
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
112 :param apiuser:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
113 """
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
114
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
115 result = []
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
116 for user in User.getAll():
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
117 result.append(
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
118 dict(
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
119 id=user.user_id,
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1649
diff changeset
120 username=user.username,
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1649
diff changeset
121 firstname=user.name,
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1649
diff changeset
122 lastname=user.lastname,
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1649
diff changeset
123 email=user.email,
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1649
diff changeset
124 active=user.active,
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1649
diff changeset
125 admin=user.admin,
2151
12ceeda33339 #404 API extensions for showing permission for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2146
diff changeset
126 ldap_dn=user.ldap_dn,
12ceeda33339 #404 API extensions for showing permission for users
Marcin Kuzminski <marcin@python-works.com>
parents: 2146
diff changeset
127 last_login=user.last_login,
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
128 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
129 )
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
130 return result
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
131
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
132 @HasPermissionAllDecorator('hg.admin')
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
133 def create_user(self, apiuser, username, email, password, firstname=None,
1950
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1909
diff changeset
134 lastname=None, active=True, admin=False, ldap_dn=None):
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
135 """
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
136 Create new user
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
137
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
138 :param apiuser:
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
139 :param username:
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
140 :param password:
1950
4ae17f819ee8 #344 optional firstname lastname on user creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1909
diff changeset
141 :param email:
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
142 :param name:
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
143 :param lastname:
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
144 :param active:
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
145 :param admin:
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
146 :param ldap_dn:
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
147 """
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1649
diff changeset
148 if User.get_by_username(username):
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
149 raise JSONRPCError("user %s already exist" % username)
1589
307ec693bdf2 [API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1587
diff changeset
150
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
151 if User.get_by_email(email, case_insensitive=True):
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
152 raise JSONRPCError("email %s already exist" % email)
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
153
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
154 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
155 # 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
156 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
157
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
158 try:
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
159 usr = UserModel().create_or_update(
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
160 username, password, email, firstname,
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
161 lastname, active, admin, ldap_dn
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
162 )
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
163 Session.commit()
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
164 return dict(
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
165 id=usr.user_id,
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
166 msg='created new user %s' % username
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
167 )
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
168 except Exception:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
169 log.error(traceback.format_exc())
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
170 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
171
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
172 @HasPermissionAllDecorator('hg.admin')
2009
b63adad7c4af API updates
Marcin Kuzminski <marcin@python-works.com>
parents: 2008
diff changeset
173 def update_user(self, apiuser, userid, username, password, email,
b63adad7c4af API updates
Marcin Kuzminski <marcin@python-works.com>
parents: 2008
diff changeset
174 firstname, lastname, active, admin, ldap_dn):
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
175 """
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
176 Updates given user
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
177
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
178 :param apiuser:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
179 :param username:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
180 :param password:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
181 :param email:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
182 :param name:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
183 :param lastname:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
184 :param active:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
185 :param admin:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
186 :param ldap_dn:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
187 """
2009
b63adad7c4af API updates
Marcin Kuzminski <marcin@python-works.com>
parents: 2008
diff changeset
188 if not UserModel().get_user(userid):
2002
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
189 raise JSONRPCError("user %s does not exist" % username)
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
190
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
191 try:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
192 usr = UserModel().create_or_update(
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
193 username, password, email, firstname,
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
194 lastname, active, admin, ldap_dn
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
195 )
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
196 Session.commit()
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
197 return dict(
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
198 id=usr.user_id,
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
199 msg='updated user %s' % username
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
200 )
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
201 except Exception:
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
202 log.error(traceback.format_exc())
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
203 raise JSONRPCError('failed to update user %s' % username)
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
204
bdc0ad168006 API added explicit method for updating user account
Marcin Kuzminski <marcin@python-works.com>
parents: 1989
diff changeset
205 @HasPermissionAllDecorator('hg.admin')
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
206 def get_users_group(self, apiuser, group_name):
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
207 """"
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
208 Get users group by name
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
209
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
210 :param apiuser:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
211 :param group_name:
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
212 """
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
213
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
214 users_group = UsersGroup.get_by_group_name(group_name)
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
215 if not users_group:
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
216 return None
1445
c78f6bf52e9c Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
217
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
218 members = []
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
219 for user in users_group.members:
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
220 user = user.user
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
221 members.append(dict(id=user.user_id,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
222 username=user.username,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
223 firstname=user.name,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
224 lastname=user.lastname,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
225 email=user.email,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
226 active=user.active,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
227 admin=user.admin,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
228 ldap=user.ldap_dn))
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
229
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
230 return dict(id=users_group.users_group_id,
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
231 group_name=users_group.users_group_name,
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
232 active=users_group.users_group_active,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
233 members=members)
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
234
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
235 @HasPermissionAllDecorator('hg.admin')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
236 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
237 """"
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
238 Get all users groups
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
239
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
240 :param apiuser:
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
241 """
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
242
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
243 result = []
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
244 for users_group in UsersGroup.getAll():
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
245 members = []
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
246 for user in users_group.members:
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
247 user = user.user
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
248 members.append(dict(id=user.user_id,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
249 username=user.username,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
250 firstname=user.name,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
251 lastname=user.lastname,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
252 email=user.email,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
253 active=user.active,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
254 admin=user.admin,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
255 ldap=user.ldap_dn))
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
256
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
257 result.append(dict(id=users_group.users_group_id,
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
258 group_name=users_group.users_group_name,
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
259 active=users_group.users_group_active,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
260 members=members))
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
261 return result
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
262
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
263 @HasPermissionAllDecorator('hg.admin')
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
264 def create_users_group(self, apiuser, group_name, active=True):
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
265 """
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
266 Creates an new usergroup
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
267
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
268 :param group_name:
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
269 :param active:
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
270 """
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
271
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
272 if self.get_users_group(apiuser, group_name):
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
273 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
274
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
275 try:
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
276 ug = UsersGroupModel().create(name=group_name, active=active)
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
277 Session.commit()
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1593
diff changeset
278 return dict(id=ug.users_group_id,
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
279 msg='created new users group %s' % group_name)
1500
256e729a94cd Extended API
Marcin Kuzminski <marcin@python-works.com>
parents: 1445
diff changeset
280 except Exception:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
281 log.error(traceback.format_exc())
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
282 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
283
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
284 @HasPermissionAllDecorator('hg.admin')
1810
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
285 def add_user_to_users_group(self, apiuser, group_name, username):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
286 """"
2146
ee45677c4edc Api docs fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2120
diff changeset
287 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
288
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
289 :param apiuser:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
290 :param group_name:
1810
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
291 :param username:
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
292 """
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
293
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
294 try:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
295 users_group = UsersGroup.get_by_group_name(group_name)
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
296 if not users_group:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
297 raise JSONRPCError('unknown users group %s' % group_name)
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
298
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
299 user = User.get_by_username(username)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
300 if user is None:
1810
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
301 raise JSONRPCError('unknown user %s' % username)
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
302
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
303 ugm = UsersGroupModel().add_user_to_group(users_group, user)
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
304 success = True if ugm != True else False
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
305 msg = 'added member %s to users group %s' % (username, group_name)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
306 msg = msg if success else 'User is already in that group'
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
307 Session.commit()
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
308
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
309 return dict(
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
310 id=ugm.users_group_member_id if ugm != True else None,
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
311 success=success,
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
312 msg=msg
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
313 )
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
314 except Exception:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
315 log.error(traceback.format_exc())
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
316 raise JSONRPCError('failed to add users group member')
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
317
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
318 @HasPermissionAllDecorator('hg.admin')
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
319 def remove_user_from_users_group(self, apiuser, group_name, username):
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
320 """
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
321 Remove user from a group
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
322
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
323 :param apiuser
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
324 :param group_name
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
325 :param username
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
326 """
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
327
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
328 try:
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
329 users_group = UsersGroup.get_by_group_name(group_name)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
330 if not users_group:
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
331 raise JSONRPCError('unknown users group %s' % group_name)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
332
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
333 user = User.get_by_username(username)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
334 if user is None:
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
335 raise JSONRPCError('unknown user %s' % username)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
336
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
337 success = UsersGroupModel().remove_user_from_group(users_group, user)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
338 msg = 'removed member %s from users group %s' % (username, group_name)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
339 msg = msg if success else "User wasn't in group"
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
340 Session.commit()
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
341 return dict(success=success, msg=msg)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
342 except Exception:
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
343 log.error(traceback.format_exc())
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
344 raise JSONRPCError('failed to remove user from group')
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
345
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
346 @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
347 def get_repo(self, apiuser, repoid):
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
348 """"
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
349 Get repository by name
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
350
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
351 :param apiuser:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
352 :param repo_name:
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
353 """
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
354
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
355 repo = RepoModel().get_repo(repoid)
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
356 if repo is None:
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
357 raise JSONRPCError('unknown repository %s' % repo)
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
358
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
359 members = []
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
360 for user in repo.repo_to_perm:
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
361 perm = user.permission.permission_name
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
362 user = user.user
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
363 members.append(
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
364 dict(
2146
ee45677c4edc Api docs fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2120
diff changeset
365 type="user",
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
366 id=user.user_id,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
367 username=user.username,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
368 firstname=user.name,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
369 lastname=user.lastname,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
370 email=user.email,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
371 active=user.active,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
372 admin=user.admin,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
373 ldap=user.ldap_dn,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
374 permission=perm
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
375 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
376 )
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
377 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
378 perm = users_group.permission.permission_name
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
379 users_group = users_group.users_group
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
380 members.append(
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
381 dict(
2146
ee45677c4edc Api docs fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 2120
diff changeset
382 type="users_group",
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
383 id=users_group.users_group_id,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
384 name=users_group.users_group_name,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
385 active=users_group.users_group_active,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
386 permission=perm
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
387 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
388 )
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 return dict(
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
391 id=repo.repo_id,
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
392 repo_name=repo.repo_name,
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
393 type=repo.repo_type,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
394 description=repo.description,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
395 members=members
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
396 )
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
397
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
398 @HasPermissionAnyDecorator('hg.admin')
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
399 def get_repos(self, apiuser):
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
400 """"
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
401 Get all repositories
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
402
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
403 :param apiuser:
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
404 """
1587
8898a79ac628 Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1586
diff changeset
405
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
406 result = []
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
407 for repository in Repository.getAll():
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
408 result.append(
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
409 dict(
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
410 id=repository.repo_id,
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
411 repo_name=repository.repo_name,
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
412 type=repository.repo_type,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
413 description=repository.description
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
414 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
415 )
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
416 return result
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
417
1810
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
418 @HasPermissionAnyDecorator('hg.admin')
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
419 def get_repo_nodes(self, apiuser, repo_name, revision, root_path,
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
420 ret_type='all'):
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
421 """
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
422 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
423 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
424 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
425
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
426 :param apiuser:
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
427 :param repo_name: name of repository
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
428 :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
429 :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
430 :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
431 """
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
432 try:
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
433 _d, _f = ScmModel().get_nodes(repo_name, revision, root_path,
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
434 flat=False)
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
435 _map = {
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
436 'all': _d + _f,
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
437 'files': _f,
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
438 'dirs': _d,
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
439 }
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
440 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
441 except KeyError:
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
442 raise JSONRPCError('ret_type must be one of %s' % _map.keys())
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
443 except Exception, e:
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
444 raise JSONRPCError(e)
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
445
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
446 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
447 def create_repo(self, apiuser, repo_name, owner_name, description='',
2006
34d009e5147a added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents: 2004
diff changeset
448 repo_type='hg', private=False, clone_uri=None):
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
449 """
2006
34d009e5147a added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents: 2004
diff changeset
450 Create repository, if clone_url is given it makes a remote clone
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
451
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
452 :param apiuser:
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
453 :param repo_name:
2006
34d009e5147a added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents: 2004
diff changeset
454 :param owner_name:
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
455 :param description:
2006
34d009e5147a added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents: 2004
diff changeset
456 :param repo_type:
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
457 :param private:
2006
34d009e5147a added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents: 2004
diff changeset
458 :param clone_uri:
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
459 """
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
460
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
461 try:
1989
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
462 owner = User.get_by_username(owner_name)
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
463 if owner is None:
0f87c784756e API changes
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
464 raise JSONRPCError('unknown user %s' % owner_name)
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
465
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
466 if Repository.get_by_repo_name(repo_name):
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
467 raise JSONRPCError("repo %s already exist" % repo_name)
1589
307ec693bdf2 [API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1587
diff changeset
468
2120
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2010
diff changeset
469 groups = repo_name.split(Repository.url_sep())
1589
307ec693bdf2 [API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1587
diff changeset
470 real_name = groups[-1]
2120
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2010
diff changeset
471 # create structure of groups
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2010
diff changeset
472 group = map_groups(repo_name)
1589
307ec693bdf2 [API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents: 1587
diff changeset
473
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
474 repo = RepoModel().create(
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
475 dict(
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
476 repo_name=real_name,
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
477 repo_name_full=repo_name,
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
478 description=description,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
479 private=private,
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
480 repo_type=repo_type,
2120
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2010
diff changeset
481 repo_group=group.group_id if group else None,
2006
34d009e5147a added clone_uri to API method for creating users
Marcin Kuzminski <marcin@python-works.com>
parents: 2004
diff changeset
482 clone_uri=clone_uri
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
483 ),
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
484 owner
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
485 )
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
486 Session.commit()
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
487
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
488 return dict(
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
489 id=repo.repo_id,
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
490 msg="Created new repository %s" % repo.repo_name
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
491 )
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
492
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
493 except Exception:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
494 log.error(traceback.format_exc())
1843
0771f0f5ab28 api review
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
495 raise JSONRPCError('failed to create repository %s' % repo_name)
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
496
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
497 @HasPermissionAnyDecorator('hg.admin')
2003
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
498 def delete_repo(self, apiuser, repo_name):
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
499 """
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
500 Deletes a given repository
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
501
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
502 :param repo_name:
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
503 """
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
504 if not Repository.get_by_repo_name(repo_name):
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
505 raise JSONRPCError("repo %s does not exist" % repo_name)
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
506 try:
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
507 RepoModel().delete(repo_name)
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
508 Session.commit()
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
509 return dict(
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
510 msg='Deleted repository %s' % repo_name
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
511 )
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
512 except Exception:
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
513 log.error(traceback.format_exc())
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
514 raise JSONRPCError('failed to delete repository %s' % repo_name)
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
515
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2002
diff changeset
516 @HasPermissionAnyDecorator('hg.admin')
2004
f2b7bebc6790 enabled grant/revoke api functions for users and users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 2003
diff changeset
517 def grant_user_permission(self, apiuser, repo_name, username, perm):
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
518 """
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
519 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
520 if found
1584
3338a0994472 Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents: 1508
diff changeset
521
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
522 :param repo_name:
1810
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
523 :param username:
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
524 :param perm:
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
525 """
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
526
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
527 try:
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
528 repo = Repository.get_by_repo_name(repo_name)
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
529 if repo is None:
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
530 raise JSONRPCError('unknown repository %s' % repo)
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
531
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
532 user = User.get_by_username(username)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
533 if user is None:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
534 raise JSONRPCError('unknown user %s' % username)
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
535
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
536 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
537
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
538 Session.commit()
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
539 return dict(
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
540 msg='Granted perm: %s for user: %s in repo: %s' % (
1810
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
541 perm, username, repo_name
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
542 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
543 )
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
544 except Exception:
1593
92a4f7c496a5 Correct code style
Nicolas VINOT <aeris@imirhil.fr>
parents: 1591
diff changeset
545 log.error(traceback.format_exc())
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
546 raise JSONRPCError(
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
547 'failed to edit permission %(repo)s for %(user)s' % dict(
1810
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1793
diff changeset
548 user=username, repo=repo_name
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
549 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
550 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
551
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
552 @HasPermissionAnyDecorator('hg.admin')
2004
f2b7bebc6790 enabled grant/revoke api functions for users and users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 2003
diff changeset
553 def revoke_user_permission(self, apiuser, repo_name, username):
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
554 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
555 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
556
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
557 :param repo_name:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
558 :param username:
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
559 """
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
560
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
561 try:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
562 repo = Repository.get_by_repo_name(repo_name)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
563 if repo is None:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
564 raise JSONRPCError('unknown repository %s' % repo)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
565
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
566 user = User.get_by_username(username)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
567 if user is None:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
568 raise JSONRPCError('unknown user %s' % username)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
569
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
570 RepoModel().revoke_user_permission(repo=repo_name, user=username)
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
571
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
572 Session.commit()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
573 return dict(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
574 msg='Revoked perm for user: %s in repo: %s' % (
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
575 username, repo_name
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
576 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
577 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
578 except Exception:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
579 log.error(traceback.format_exc())
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
580 raise JSONRPCError(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
581 'failed to edit permission %(repo)s for %(user)s' % dict(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
582 user=username, repo=repo_name
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
583 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
584 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
585
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
586 @HasPermissionAnyDecorator('hg.admin')
2004
f2b7bebc6790 enabled grant/revoke api functions for users and users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 2003
diff changeset
587 def grant_users_group_permission(self, apiuser, repo_name, group_name, perm):
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
588 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
589 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
590 existing one if found
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
591
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
592 :param repo_name:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
593 :param group_name:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
594 :param perm:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
595 """
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
596
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
597 try:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
598 repo = Repository.get_by_repo_name(repo_name)
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
599 if repo is None:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
600 raise JSONRPCError('unknown repository %s' % repo)
1586
2ccb32ddcfd7 Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents: 1584
diff changeset
601
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
602 user_group = UsersGroup.get_by_group_name(group_name)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
603 if user_group is None:
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
604 raise JSONRPCError('unknown users group %s' % user_group)
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
605
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
606 RepoModel().grant_users_group_permission(repo=repo_name,
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
607 group_name=group_name,
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
608 perm=perm)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
609
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
610 Session.commit()
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
611 return dict(
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
612 msg='Granted perm: %s for group: %s in repo: %s' % (
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
613 perm, group_name, repo_name
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
614 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
615 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
616 except Exception:
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
617 log.error(traceback.format_exc())
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
618 raise JSONRPCError(
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
619 'failed to edit permission %(repo)s for %(usersgr)s' % dict(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
620 usersgr=group_name, repo=repo_name
1793
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
621 )
631caf880b87 implements #329
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
622 )
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
623
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
624 @HasPermissionAnyDecorator('hg.admin')
2004
f2b7bebc6790 enabled grant/revoke api functions for users and users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 2003
diff changeset
625 def revoke_users_group_permission(self, apiuser, repo_name, group_name):
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
626 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
627 Revoke permission for users group on given repository
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
628
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
629 :param repo_name:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
630 :param group_name:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
631 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
632
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
633 try:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
634 repo = Repository.get_by_repo_name(repo_name)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
635 if repo is None:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
636 raise JSONRPCError('unknown repository %s' % repo)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
637
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
638 user_group = UsersGroup.get_by_group_name(group_name)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
639 if user_group is None:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
640 raise JSONRPCError('unknown users group %s' % user_group)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
641
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
642 RepoModel().revoke_users_group_permission(repo=repo_name,
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
643 group_name=group_name)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
644
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
645 Session.commit()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
646 return dict(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
647 msg='Revoked perm for group: %s in repo: %s' % (
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
648 group_name, repo_name
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
649 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
650 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
651 except Exception:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
652 log.error(traceback.format_exc())
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
653 raise JSONRPCError(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
654 'failed to edit permission %(repo)s for %(usersgr)s' % dict(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
655 usersgr=group_name, repo=repo_name
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
656 )
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1950
diff changeset
657 )