annotate rhodecode/controllers/api/api.py @ 2008:9ddbfaeefb73 beta

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