Show More
@@ -1,3 +1,30 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | """ | |||
|
3 | rhodecode.controllers.api | |||
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | |||
|
5 | ||||
|
6 | API controller for RhodeCode | |||
|
7 | ||||
|
8 | :created_on: Aug 20, 2011 | |||
|
9 | :author: marcink | |||
|
10 | :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> | |||
|
11 | :license: GPLv3, see COPYING for more details. | |||
|
12 | """ | |||
|
13 | # This program is free software; you can redistribute it and/or | |||
|
14 | # modify it under the terms of the GNU General Public License | |||
|
15 | # as published by the Free Software Foundation; version 2 | |||
|
16 | # of the License or (at your opinion) any later version of the license. | |||
|
17 | # | |||
|
18 | # This program is distributed in the hope that it will be useful, | |||
|
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
21 | # GNU General Public License for more details. | |||
|
22 | # | |||
|
23 | # You should have received a copy of the GNU General Public License | |||
|
24 | # along with this program; if not, write to the Free Software | |||
|
25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |||
|
26 | # MA 02110-1301, USA. | |||
|
27 | ||||
1 | import traceback |
|
28 | import traceback | |
2 | import logging |
|
29 | import logging | |
3 |
|
30 | |||
@@ -15,6 +42,7 b' from rhodecode.model import users_group' | |||||
15 | from rhodecode.model.repos_group import ReposGroupModel |
|
42 | from rhodecode.model.repos_group import ReposGroupModel | |
16 | from sqlalchemy.orm.exc import NoResultFound |
|
43 | from sqlalchemy.orm.exc import NoResultFound | |
17 |
|
44 | |||
|
45 | ||||
18 | log = logging.getLogger(__name__) |
|
46 | log = logging.getLogger(__name__) | |
19 |
|
47 | |||
20 |
|
48 | |||
@@ -58,41 +86,47 b' class ApiController(JSONRPCController):' | |||||
58 | """" |
|
86 | """" | |
59 | Get a user by username |
|
87 | Get a user by username | |
60 |
|
88 | |||
61 | :param apiuser |
|
89 | :param apiuser: | |
62 | :param username |
|
90 | :param username: | |
63 | """ |
|
91 | """ | |
64 |
|
92 | |||
65 | user = User.get_by_username(username) |
|
93 | user = User.get_by_username(username) | |
66 | if not user: |
|
94 | if not user: | |
67 | return None |
|
95 | return None | |
68 |
|
96 | |||
69 |
return dict( |
|
97 | return dict( | |
70 |
|
|
98 | id=user.user_id, | |
71 |
|
|
99 | username=user.username, | |
72 |
|
|
100 | firstname=user.name, | |
73 | email=user.email, |
|
101 | lastname=user.lastname, | |
74 |
|
|
102 | email=user.email, | |
75 |
|
|
103 | active=user.active, | |
76 | ldap=user.ldap_dn) |
|
104 | admin=user.admin, | |
|
105 | ldap=user.ldap_dn | |||
|
106 | ) | |||
77 |
|
107 | |||
78 | @HasPermissionAllDecorator('hg.admin') |
|
108 | @HasPermissionAllDecorator('hg.admin') | |
79 | def get_users(self, apiuser): |
|
109 | def get_users(self, apiuser): | |
80 | """" |
|
110 | """" | |
81 | Get all users |
|
111 | Get all users | |
82 |
|
112 | |||
83 | :param apiuser |
|
113 | :param apiuser: | |
84 | """ |
|
114 | """ | |
85 |
|
115 | |||
86 | result = [] |
|
116 | result = [] | |
87 | for user in User.getAll(): |
|
117 | for user in User.getAll(): | |
88 |
result.append( |
|
118 | result.append( | |
89 | username=user.username, |
|
119 | dict( | |
90 |
|
|
120 | id=user.user_id, | |
91 |
|
|
121 | username=user.username, | |
92 |
|
|
122 | firstname=user.name, | |
93 |
|
|
123 | lastname=user.lastname, | |
94 |
|
|
124 | email=user.email, | |
95 |
|
|
125 | active=user.active, | |
|
126 | admin=user.admin, | |||
|
127 | ldap=user.ldap_dn | |||
|
128 | ) | |||
|
129 | ) | |||
96 | return result |
|
130 | return result | |
97 |
|
131 | |||
98 | @HasPermissionAllDecorator('hg.admin') |
|
132 | @HasPermissionAllDecorator('hg.admin') | |
@@ -112,7 +146,7 b' class ApiController(JSONRPCController):' | |||||
112 | :param ldap_dn: |
|
146 | :param ldap_dn: | |
113 | """ |
|
147 | """ | |
114 |
|
148 | |||
115 |
if |
|
149 | if User.get_by_username(username): | |
116 | raise JSONRPCError("user %s already exist" % username) |
|
150 | raise JSONRPCError("user %s already exist" % username) | |
117 |
|
151 | |||
118 | try: |
|
152 | try: | |
@@ -135,8 +169,8 b' class ApiController(JSONRPCController):' | |||||
135 | """" |
|
169 | """" | |
136 | Get users group by name |
|
170 | Get users group by name | |
137 |
|
171 | |||
138 | :param apiuser |
|
172 | :param apiuser: | |
139 | :param group_name |
|
173 | :param group_name: | |
140 | """ |
|
174 | """ | |
141 |
|
175 | |||
142 | users_group = UsersGroup.get_by_group_name(group_name) |
|
176 | users_group = UsersGroup.get_by_group_name(group_name) | |
@@ -165,7 +199,7 b' class ApiController(JSONRPCController):' | |||||
165 | """" |
|
199 | """" | |
166 | Get all users groups |
|
200 | Get all users groups | |
167 |
|
201 | |||
168 | :param apiuser |
|
202 | :param apiuser: | |
169 | """ |
|
203 | """ | |
170 |
|
204 | |||
171 | result = [] |
|
205 | result = [] | |
@@ -239,7 +273,7 b' class ApiController(JSONRPCController):' | |||||
239 | raise JSONRPCError('failed to create users group member') |
|
273 | raise JSONRPCError('failed to create users group member') | |
240 |
|
274 | |||
241 | @HasPermissionAnyDecorator('hg.admin') |
|
275 | @HasPermissionAnyDecorator('hg.admin') | |
242 |
def get_repo(self, apiuser, |
|
276 | def get_repo(self, apiuser, name): | |
243 | """" |
|
277 | """" | |
244 | Get repository by name |
|
278 | Get repository by name | |
245 |
|
279 | |||
@@ -248,7 +282,7 b' class ApiController(JSONRPCController):' | |||||
248 | """ |
|
282 | """ | |
249 |
|
283 | |||
250 | try: |
|
284 | try: | |
251 |
repo = Repository.get_by_repo_name( |
|
285 | repo = Repository.get_by_repo_name(name) | |
252 | except NoResultFound: |
|
286 | except NoResultFound: | |
253 | return None |
|
287 | return None | |
254 |
|
288 | |||
@@ -256,30 +290,40 b' class ApiController(JSONRPCController):' | |||||
256 | for user in repo.repo_to_perm: |
|
290 | for user in repo.repo_to_perm: | |
257 | perm = user.permission.permission_name |
|
291 | perm = user.permission.permission_name | |
258 | user = user.user |
|
292 | user = user.user | |
259 |
members.append( |
|
293 | members.append( | |
260 | id=user.user_id, |
|
294 | dict( | |
261 | username=user.username, |
|
295 | type_="user", | |
262 |
|
|
296 | id=user.user_id, | |
263 |
|
|
297 | username=user.username, | |
264 |
|
|
298 | firstname=user.name, | |
265 |
|
|
299 | lastname=user.lastname, | |
266 |
|
|
300 | email=user.email, | |
267 |
|
|
301 | active=user.active, | |
268 | permission=perm)) |
|
302 | admin=user.admin, | |
|
303 | ldap=user.ldap_dn, | |||
|
304 | permission=perm | |||
|
305 | ) | |||
|
306 | ) | |||
269 | for users_group in repo.users_group_to_perm: |
|
307 | for users_group in repo.users_group_to_perm: | |
270 | perm = users_group.permission.permission_name |
|
308 | perm = users_group.permission.permission_name | |
271 | users_group = users_group.users_group |
|
309 | users_group = users_group.users_group | |
272 |
members.append( |
|
310 | members.append( | |
273 | id=users_group.users_group_id, |
|
311 | dict( | |
274 |
|
|
312 | type_="users_group", | |
275 |
|
|
313 | id=users_group.users_group_id, | |
276 | permission=perm)) |
|
314 | name=users_group.users_group_name, | |
|
315 | active=users_group.users_group_active, | |||
|
316 | permission=perm | |||
|
317 | ) | |||
|
318 | ) | |||
277 |
|
319 | |||
278 |
return dict( |
|
320 | return dict( | |
279 |
|
|
321 | id=repo.repo_id, | |
280 |
|
|
322 | name=repo.repo_name, | |
281 | description=repo.description, |
|
323 | type=repo.repo_type, | |
282 | members=members) |
|
324 | description=repo.description, | |
|
325 | members=members | |||
|
326 | ) | |||
283 |
|
327 | |||
284 | @HasPermissionAnyDecorator('hg.admin') |
|
328 | @HasPermissionAnyDecorator('hg.admin') | |
285 | def get_repos(self, apiuser): |
|
329 | def get_repos(self, apiuser): | |
@@ -291,10 +335,14 b' class ApiController(JSONRPCController):' | |||||
291 |
|
335 | |||
292 | result = [] |
|
336 | result = [] | |
293 | for repository in Repository.getAll(): |
|
337 | for repository in Repository.getAll(): | |
294 |
result.append( |
|
338 | result.append( | |
295 | name=repository.repo_name, |
|
339 | dict( | |
296 |
|
|
340 | id=repository.repo_id, | |
297 |
|
|
341 | name=repository.repo_name, | |
|
342 | type=repository.repo_type, | |||
|
343 | description=repository.description | |||
|
344 | ) | |||
|
345 | ) | |||
298 | return result |
|
346 | return result | |
299 |
|
347 | |||
300 | @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') |
|
348 | @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') |
General Comments 0
You need to be logged in to leave comments.
Login now