Mercurial > kallithea
annotate rhodecode/controllers/api/api.py @ 1909:f2bd5b0c1094 beta
create user api_doc update
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 17 Jan 2012 20:51:42 +0200 |
parents | 0771f0f5ab28 |
children | 4ae17f819ee8 |
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 | 28 import traceback |
29 import logging | |
30 | |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
31 from sqlalchemy.orm.exc import NoResultFound |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
32 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 from rhodecode.controllers.api import JSONRPCController, JSONRPCError |
1594 | 34 from rhodecode.lib.auth import HasPermissionAllDecorator, \ |
35 HasPermissionAnyDecorator | |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
36 |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
37 from rhodecode.model.meta import Session |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 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
|
39 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
|
40 from rhodecode.model.repo import RepoModel |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
41 from rhodecode.model.user import UserModel |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
42 from rhodecode.model.repo_permission import RepositoryPermissionModel |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
43 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
|
44 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
|
45 |
1500 | 46 |
1593 | 47 log = logging.getLogger(__name__) |
1500 | 48 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 |
1593 | 50 class ApiController(JSONRPCController): |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 API Controller |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
53 |
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 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
|
56 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
|
57 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 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
|
59 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
60 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
61 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
|
62 errors that happens |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
63 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 |
1593 | 66 @HasPermissionAllDecorator('hg.admin') |
1843 | 67 def pull(self, apiuser, repo_name): |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 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
|
70 |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
71 |
1500 | 72 :param user: |
1843 | 73 :param repo_name: |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 """ |
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 |
1843 | 76 if Repository.is_valid(repo_name) is False: |
77 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
|
78 |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 try: |
1843 | 80 ScmModel().pull_changes(repo_name, self.rhodecode_user.username) |
81 return 'Pulled from %s' % repo_name | |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 except Exception: |
1843 | 83 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
|
84 |
1593 | 85 @HasPermissionAllDecorator('hg.admin') |
86 def get_user(self, apiuser, username): | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
87 """" |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
88 Get a user by username |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
89 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
90 :param apiuser: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
91 :param username: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
92 """ |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 |
1593 | 94 user = User.get_by_username(username) |
1591 | 95 if not user: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
96 return None |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
97 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
98 return dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
99 id=user.user_id, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
100 username=user.username, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
101 firstname=user.name, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
102 lastname=user.lastname, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
103 email=user.email, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
104 active=user.active, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
105 admin=user.admin, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
106 ldap=user.ldap_dn |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
107 ) |
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 @HasPermissionAllDecorator('hg.admin') |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
110 def get_users(self, apiuser): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
111 """" |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
112 Get all users |
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 :param apiuser: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
115 """ |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
116 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
117 result = [] |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
118 for user in User.getAll(): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
119 result.append( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
120 dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
121 id=user.user_id, |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1649
diff
changeset
|
122 username=user.username, |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1649
diff
changeset
|
123 firstname=user.name, |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1649
diff
changeset
|
124 lastname=user.lastname, |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1649
diff
changeset
|
125 email=user.email, |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1649
diff
changeset
|
126 active=user.active, |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1649
diff
changeset
|
127 admin=user.admin, |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
128 ldap=user.ldap_dn |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
129 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
130 ) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
131 return result |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
132 |
1593 | 133 @HasPermissionAllDecorator('hg.admin') |
134 def create_user(self, apiuser, username, password, firstname, | |
1594 | 135 lastname, email, active=True, admin=False, ldap_dn=None): |
1500 | 136 """ |
1909
f2bd5b0c1094
create user api_doc update
Marcin Kuzminski <marcin@python-works.com>
parents:
1843
diff
changeset
|
137 Create new user or updates current one |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
138 |
1500 | 139 :param apiuser: |
140 :param username: | |
141 :param password: | |
142 :param name: | |
143 :param lastname: | |
144 :param email: | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
145 :param active: |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
146 :param admin: |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
147 :param ldap_dn: |
1500 | 148 """ |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
149 |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1649
diff
changeset
|
150 if User.get_by_username(username): |
1593 | 151 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
|
152 |
1500 | 153 try: |
1843 | 154 usr = UserModel().create_or_update( |
155 username, password, email, firstname, | |
156 lastname, active, admin, ldap_dn | |
157 ) | |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
158 Session.commit() |
1843 | 159 return dict( |
160 id=usr.user_id, | |
161 msg='created new user %s' % username | |
162 ) | |
1500 | 163 except Exception: |
1593 | 164 log.error(traceback.format_exc()) |
165 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
|
166 |
1593 | 167 @HasPermissionAllDecorator('hg.admin') |
168 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
|
169 """" |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
170 Get users group by name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
171 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
172 :param apiuser: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
173 :param group_name: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
174 """ |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
175 |
1593 | 176 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
|
177 if not users_group: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
178 return None |
1445
c78f6bf52e9c
Beginning of API implementation for rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
179 |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
180 members = [] |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
181 for user in users_group.members: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
182 user = user.user |
1594 | 183 members.append(dict(id=user.user_id, |
184 username=user.username, | |
185 firstname=user.name, | |
186 lastname=user.lastname, | |
187 email=user.email, | |
188 active=user.active, | |
189 admin=user.admin, | |
190 ldap=user.ldap_dn)) | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
191 |
1594 | 192 return dict(id=users_group.users_group_id, |
1843 | 193 group_name=users_group.users_group_name, |
1594 | 194 active=users_group.users_group_active, |
195 members=members) | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
196 |
1593 | 197 @HasPermissionAllDecorator('hg.admin') |
198 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
|
199 """" |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
200 Get all users groups |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
201 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
202 :param apiuser: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
203 """ |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
204 |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
205 result = [] |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
206 for users_group in UsersGroup.getAll(): |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
207 members = [] |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
208 for user in users_group.members: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
209 user = user.user |
1594 | 210 members.append(dict(id=user.user_id, |
211 username=user.username, | |
212 firstname=user.name, | |
213 lastname=user.lastname, | |
214 email=user.email, | |
215 active=user.active, | |
216 admin=user.admin, | |
217 ldap=user.ldap_dn)) | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
218 |
1594 | 219 result.append(dict(id=users_group.users_group_id, |
1843 | 220 group_name=users_group.users_group_name, |
1594 | 221 active=users_group.users_group_active, |
222 members=members)) | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
223 return result |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
224 |
1593 | 225 @HasPermissionAllDecorator('hg.admin') |
1843 | 226 def create_users_group(self, apiuser, group_name, active=True): |
1500 | 227 """ |
228 Creates an new usergroup | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
229 |
1843 | 230 :param group_name: |
1500 | 231 :param active: |
232 """ | |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
233 |
1843 | 234 if self.get_users_group(apiuser, group_name): |
235 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
|
236 |
1500 | 237 try: |
1843 | 238 ug = UsersGroupModel().create(name=group_name, active=active) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
239 Session.commit() |
1594 | 240 return dict(id=ug.users_group_id, |
1843 | 241 msg='created new users group %s' % group_name) |
1500 | 242 except Exception: |
1593 | 243 log.error(traceback.format_exc()) |
1843 | 244 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
|
245 |
1593 | 246 @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
|
247 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
|
248 """" |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
249 Add a user to a group |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
250 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
251 :param apiuser: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
252 :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
|
253 :param username: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
254 """ |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
255 |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
256 try: |
1593 | 257 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
|
258 if not users_group: |
1593 | 259 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
|
260 |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
261 try: |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
262 user = User.get_by_username(username) |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
263 except NoResultFound: |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
264 raise JSONRPCError('unknown user %s' % username) |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
265 |
1593 | 266 ugm = UsersGroupModel().add_user_to_group(users_group, user) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
267 Session.commit() |
1594 | 268 return dict(id=ugm.users_group_member_id, |
269 msg='created new users group member') | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
270 except Exception: |
1593 | 271 log.error(traceback.format_exc()) |
272 raise JSONRPCError('failed to create users group member') | |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
273 |
1593 | 274 @HasPermissionAnyDecorator('hg.admin') |
275 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
|
276 """" |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
277 Get repository by name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
278 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
279 :param apiuser: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
280 :param repo_name: |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
281 """ |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
282 |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
283 repo = Repository.get_by_repo_name(repo_name) |
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
284 if repo is None: |
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
285 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
|
286 |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
287 members = [] |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
288 for user in repo.repo_to_perm: |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
289 perm = user.permission.permission_name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
290 user = user.user |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
291 members.append( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
292 dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
293 type_="user", |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
294 id=user.user_id, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
295 username=user.username, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
296 firstname=user.name, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
297 lastname=user.lastname, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
298 email=user.email, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
299 active=user.active, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
300 admin=user.admin, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
301 ldap=user.ldap_dn, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
302 permission=perm |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
303 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
304 ) |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
305 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
|
306 perm = users_group.permission.permission_name |
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
307 users_group = users_group.users_group |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
308 members.append( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
309 dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
310 type_="users_group", |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
311 id=users_group.users_group_id, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
312 name=users_group.users_group_name, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
313 active=users_group.users_group_active, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
314 permission=perm |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
315 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
316 ) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
317 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
318 return dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
319 id=repo.repo_id, |
1843 | 320 repo_name=repo.repo_name, |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
321 type=repo.repo_type, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
322 description=repo.description, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
323 members=members |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
324 ) |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
325 |
1593 | 326 @HasPermissionAnyDecorator('hg.admin') |
327 def get_repos(self, apiuser): | |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
328 """" |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
329 Get all repositories |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
330 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
331 :param apiuser: |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
332 """ |
1587
8898a79ac628
Implement all CRUD API operation for repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1586
diff
changeset
|
333 |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
334 result = [] |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
335 for repository in Repository.getAll(): |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
336 result.append( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
337 dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
338 id=repository.repo_id, |
1843 | 339 repo_name=repository.repo_name, |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
340 type=repository.repo_type, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
341 description=repository.description |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
342 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
343 ) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
344 return result |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
345 |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
346 @HasPermissionAnyDecorator('hg.admin') |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
347 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
|
348 ret_type='all'): |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
349 """ |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
354 :param apiuser: |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
355 :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
|
356 :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
|
357 :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
|
358 :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
|
359 """ |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
360 try: |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
361 _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
|
362 flat=False) |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
363 _map = { |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
364 'all': _d + _f, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
365 'files': _f, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
366 'dirs': _d, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
367 } |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
368 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
|
369 except KeyError: |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
370 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
|
371 except Exception, e: |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
372 raise JSONRPCError(e) |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
373 |
1593 | 374 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') |
1843 | 375 def create_repo(self, apiuser, repo_name, owner_name, description='', |
1594 | 376 repo_type='hg', private=False): |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
377 """ |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
378 Create a repository |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
379 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
380 :param apiuser: |
1843 | 381 :param repo_name: |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
382 :param description: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
383 :param type: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
384 :param private: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
385 :param owner_name: |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
386 """ |
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
387 |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
388 try: |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
389 try: |
1593 | 390 owner = User.get_by_username(owner_name) |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
391 except NoResultFound: |
1593 | 392 raise JSONRPCError('unknown user %s' % owner) |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
393 |
1843 | 394 if Repository.get_by_repo_name(repo_name): |
395 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
|
396 |
1843 | 397 groups = repo_name.split('/') |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
398 real_name = groups[-1] |
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
399 groups = groups[:-1] |
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
400 parent_id = None |
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
401 for g in groups: |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
402 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
|
403 if not group: |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
404 group = ReposGroupModel().create( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
405 dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
406 group_name=g, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
407 group_description='', |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
408 group_parent_id=parent_id |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
409 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
410 ) |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
411 parent_id = group.group_id |
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
412 |
1843 | 413 repo = RepoModel().create( |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
414 dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
415 repo_name=real_name, |
1843 | 416 repo_name_full=repo_name, |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
417 description=description, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
418 private=private, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
419 repo_type=repo_type, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
420 repo_group=parent_id, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
421 clone_uri=None |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
422 ), |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
423 owner |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
424 ) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
425 Session.commit() |
1843 | 426 |
427 return dict( | |
428 id=repo.repo_id, | |
429 msg="Created new repository %s" % repo.repo_name | |
430 ) | |
431 | |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
432 except Exception: |
1593 | 433 log.error(traceback.format_exc()) |
1843 | 434 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
|
435 |
1593 | 436 @HasPermissionAnyDecorator('hg.admin') |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
437 def add_user_to_repo(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
|
438 """ |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
439 Add permission for a user to a repository |
1584
3338a0994472
Improve API with user/group/repo CRUD methods
Nicolas VINOT <aeris@imirhil.fr>
parents:
1508
diff
changeset
|
440 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
441 :param apiuser: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
442 :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
|
443 :param username: |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
444 :param perm: |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
445 """ |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
446 |
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
447 try: |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
448 repo = Repository.get_by_repo_name(repo_name) |
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
449 if repo is None: |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
450 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
|
451 |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
452 try: |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
453 user = User.get_by_username(username) |
1589
307ec693bdf2
[API] Create groups needed when creating repo
Nicolas VINOT <aeris@imirhil.fr>
parents:
1587
diff
changeset
|
454 except NoResultFound: |
1593 | 455 raise JSONRPCError('unknown user %s' % user) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
456 |
1594 | 457 RepositoryPermissionModel()\ |
458 .update_or_delete_user_permission(repo, user, perm) | |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
459 Session.commit() |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
460 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
461 return dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
462 msg='Added perm: %s for %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
|
463 perm, username, repo_name |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
464 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
465 ) |
1586
2ccb32ddcfd7
Add API for repositories and groups (creation, permission)
Nicolas VINOT <aeris@imirhil.fr>
parents:
1584
diff
changeset
|
466 except Exception: |
1593 | 467 log.error(traceback.format_exc()) |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
468 raise JSONRPCError( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
469 '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
|
470 user=username, repo=repo_name |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
471 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
472 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
473 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
474 @HasPermissionAnyDecorator('hg.admin') |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
475 def add_users_group_to_repo(self, apiuser, repo_name, group_name, perm): |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
476 """ |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
477 Add permission for a users group to a repository |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
478 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
479 :param apiuser: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
480 :param repo_name: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
481 :param group_name: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
482 :param perm: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
483 """ |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
484 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
485 try: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
486 repo = Repository.get_by_repo_name(repo_name) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
487 if repo is None: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
488 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
|
489 |
1793
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
490 try: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
491 user_group = UsersGroup.get_by_group_name(group_name) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
492 except NoResultFound: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
493 raise JSONRPCError('unknown users group %s' % user_group) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
494 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
495 RepositoryPermissionModel()\ |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
496 .update_or_delete_users_group_permission(repo, user_group, |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
497 perm) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
498 Session.commit() |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
499 return dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
500 msg='Added perm: %s for %s in repo: %s' % ( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
501 perm, group_name, repo_name |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
502 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
503 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
504 except Exception: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
505 log.error(traceback.format_exc()) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
506 raise JSONRPCError( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
507 'failed to edit permission %(repo)s for %(usergr)s' % dict( |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
508 usergr=group_name, repo=repo_name |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
509 ) |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
510 ) |