Show More
@@ -26,7 +26,8 b' import collections' | |||||
26 | import logging |
|
26 | import logging | |
27 |
|
27 | |||
28 | from rhodecode.api.exc import JSONRPCError |
|
28 | from rhodecode.api.exc import JSONRPCError | |
29 | from rhodecode.lib.auth import HasPermissionAnyApi, HasRepoPermissionAnyApi |
|
29 | from rhodecode.lib.auth import HasPermissionAnyApi, HasRepoPermissionAnyApi, \ | |
|
30 | HasRepoGroupPermissionAnyApi | |||
30 | from rhodecode.lib.utils import safe_unicode |
|
31 | from rhodecode.lib.utils import safe_unicode | |
31 | from rhodecode.controllers.utils import get_commit_from_ref_name |
|
32 | from rhodecode.controllers.utils import get_commit_from_ref_name | |
32 | from rhodecode.lib.vcs.exceptions import RepositoryError |
|
33 | from rhodecode.lib.vcs.exceptions import RepositoryError | |
@@ -170,6 +171,36 b' def has_repo_permissions(apiuser, repoid' | |||||
170 | return True |
|
171 | return True | |
171 |
|
172 | |||
172 |
|
173 | |||
|
174 | def validate_repo_group_permissions(apiuser, repogroupid, repo_group, perms): | |||
|
175 | """ | |||
|
176 | Raise JsonRPCError if apiuser is not authorized or return True | |||
|
177 | ||||
|
178 | :param apiuser: | |||
|
179 | :param repogroupid: just the id of repository group | |||
|
180 | :param repo_group: instance of repo_group | |||
|
181 | :param perms: | |||
|
182 | """ | |||
|
183 | if not HasRepoGroupPermissionAnyApi(*perms)( | |||
|
184 | user=apiuser, group_name=repo_group.group_name): | |||
|
185 | raise JSONRPCError( | |||
|
186 | 'repository group `%s` does not exist' % repogroupid) | |||
|
187 | ||||
|
188 | return True | |||
|
189 | ||||
|
190 | ||||
|
191 | def has_set_owner_permissions(apiuser, owner): | |||
|
192 | if isinstance(owner, Optional): | |||
|
193 | owner = get_user_or_error(apiuser.user_id) | |||
|
194 | else: | |||
|
195 | if has_superadmin_permission(apiuser): | |||
|
196 | owner = get_user_or_error(owner) | |||
|
197 | else: | |||
|
198 | # forbid setting owner for non-admins | |||
|
199 | raise JSONRPCError( | |||
|
200 | 'Only RhodeCode super-admin can specify `owner` param') | |||
|
201 | return owner | |||
|
202 | ||||
|
203 | ||||
173 | def get_user_or_error(userid): |
|
204 | def get_user_or_error(userid): | |
174 | """ |
|
205 | """ | |
175 | Get user by id or name or return JsonRPCError if not found |
|
206 | Get user by id or name or return JsonRPCError if not found |
General Comments 0
You need to be logged in to leave comments.
Login now