Show More
@@ -35,12 +35,12 b' from rhodecode.lib.auth import PasswordG' | |||||
35 | HasPermissionAnyApi, HasRepoPermissionAnyApi |
|
35 | HasPermissionAnyApi, HasRepoPermissionAnyApi | |
36 | from rhodecode.lib.utils import map_groups, repo2db_mapper |
|
36 | from rhodecode.lib.utils import map_groups, repo2db_mapper | |
37 | from rhodecode.lib.utils2 import str2bool, time_to_datetime, safe_int |
|
37 | from rhodecode.lib.utils2 import str2bool, time_to_datetime, safe_int | |
38 | from rhodecode.lib import helpers as h |
|
|||
39 | from rhodecode.model.meta import Session |
|
38 | from rhodecode.model.meta import Session | |
40 | from rhodecode.model.scm import ScmModel |
|
39 | from rhodecode.model.scm import ScmModel | |
41 | from rhodecode.model.repo import RepoModel |
|
40 | from rhodecode.model.repo import RepoModel | |
42 | from rhodecode.model.user import UserModel |
|
41 | from rhodecode.model.user import UserModel | |
43 | from rhodecode.model.users_group import UserGroupModel |
|
42 | from rhodecode.model.users_group import UserGroupModel | |
|
43 | from rhodecode.model.repos_group import ReposGroupModel | |||
44 | from rhodecode.model.db import Repository, RhodeCodeSetting, UserIpMap,\ |
|
44 | from rhodecode.model.db import Repository, RhodeCodeSetting, UserIpMap,\ | |
45 | Permission, User, Gist |
|
45 | Permission, User, Gist | |
46 | from rhodecode.lib.compat import json |
|
46 | from rhodecode.lib.compat import json | |
@@ -50,6 +50,15 b' from rhodecode.model.gist import GistMod' | |||||
50 | log = logging.getLogger(__name__) |
|
50 | log = logging.getLogger(__name__) | |
51 |
|
51 | |||
52 |
|
52 | |||
|
53 | def store_update(updates, attr, name): | |||
|
54 | """ | |||
|
55 | Stores param in updates dict if it's not instance of Optional | |||
|
56 | allows easy updates of passed in params | |||
|
57 | """ | |||
|
58 | if not isinstance(attr, Optional): | |||
|
59 | updates[name] = attr | |||
|
60 | ||||
|
61 | ||||
53 | class OptionalAttr(object): |
|
62 | class OptionalAttr(object): | |
54 | """ |
|
63 | """ | |
55 | Special Optional Option that defines other attribute |
|
64 | Special Optional Option that defines other attribute | |
@@ -124,6 +133,19 b' def get_repo_or_error(repoid):' | |||||
124 | return repo |
|
133 | return repo | |
125 |
|
134 | |||
126 |
|
135 | |||
|
136 | def get_repo_group_or_error(repogroupid): | |||
|
137 | """ | |||
|
138 | Get repo group by id or name or return JsonRPCError if not found | |||
|
139 | ||||
|
140 | :param repogroupid: | |||
|
141 | """ | |||
|
142 | repo_group = ReposGroupModel()._get_repo_group(repogroupid) | |||
|
143 | if repo_group is None: | |||
|
144 | raise JSONRPCError( | |||
|
145 | 'repository group `%s` does not exist' % (repogroupid,)) | |||
|
146 | return repo_group | |||
|
147 | ||||
|
148 | ||||
127 | def get_users_group_or_error(usersgroupid): |
|
149 | def get_users_group_or_error(usersgroupid): | |
128 | """ |
|
150 | """ | |
129 | Get user group by id or name or return JsonRPCError if not found |
|
151 | Get user group by id or name or return JsonRPCError if not found | |
@@ -829,6 +851,71 b' class ApiController(JSONRPCController):' | |||||
829 | log.error(traceback.format_exc()) |
|
851 | log.error(traceback.format_exc()) | |
830 | raise JSONRPCError('failed to create repository `%s`' % repo_name) |
|
852 | raise JSONRPCError('failed to create repository `%s`' % repo_name) | |
831 |
|
853 | |||
|
854 | # permission check inside | |||
|
855 | def update_repo(self, apiuser, repoid, name=Optional(None), | |||
|
856 | owner=Optional(OAttr('apiuser')), | |||
|
857 | group=Optional(None), | |||
|
858 | description=Optional(''), private=Optional(False), | |||
|
859 | clone_uri=Optional(None), landing_rev=Optional('tip'), | |||
|
860 | enable_statistics=Optional(False), | |||
|
861 | enable_locking=Optional(False), | |||
|
862 | enable_downloads=Optional(False)): | |||
|
863 | ||||
|
864 | """ | |||
|
865 | Updates repo | |||
|
866 | ||||
|
867 | :param apiuser: filled automatically from apikey | |||
|
868 | :type apiuser: AuthUser | |||
|
869 | :param repoid: repository name or repository id | |||
|
870 | :type repoid: str or int | |||
|
871 | :param name: | |||
|
872 | :param owner: | |||
|
873 | :param group: | |||
|
874 | :param description: | |||
|
875 | :param private: | |||
|
876 | :param clone_uri: | |||
|
877 | :param landing_rev: | |||
|
878 | :param enable_statistics: | |||
|
879 | :param enable_locking: | |||
|
880 | :param enable_downloads: | |||
|
881 | """ | |||
|
882 | repo = get_repo_or_error(repoid) | |||
|
883 | if not HasPermissionAnyApi('hg.admin')(user=apiuser): | |||
|
884 | # check if we have admin permission for this repo ! | |||
|
885 | if not HasRepoPermissionAnyApi('repository.admin')(user=apiuser, | |||
|
886 | repo_name=repo.repo_name): | |||
|
887 | raise JSONRPCError('repository `%s` does not exist' % (repoid,)) | |||
|
888 | ||||
|
889 | updates = { | |||
|
890 | # update function requires this. | |||
|
891 | 'repo_name': repo.repo_name | |||
|
892 | } | |||
|
893 | repo_group = group | |||
|
894 | if not isinstance(repo_group, Optional): | |||
|
895 | repo_group = get_repo_group_or_error(repo_group) | |||
|
896 | repo_group = repo_group.group_id | |||
|
897 | try: | |||
|
898 | store_update(updates, name, 'repo_name') | |||
|
899 | store_update(updates, repo_group, 'repo_group') | |||
|
900 | store_update(updates, owner, 'user') | |||
|
901 | store_update(updates, description, 'repo_description') | |||
|
902 | store_update(updates, private, 'repo_private') | |||
|
903 | store_update(updates, clone_uri, 'clone_uri') | |||
|
904 | store_update(updates, landing_rev, 'repo_landing_rev') | |||
|
905 | store_update(updates, enable_statistics, 'repo_enable_statistics') | |||
|
906 | store_update(updates, enable_locking, 'repo_enable_locking') | |||
|
907 | store_update(updates, enable_downloads, 'repo_enable_downloads') | |||
|
908 | ||||
|
909 | RepoModel().update(repo, **updates) | |||
|
910 | Session().commit() | |||
|
911 | return dict( | |||
|
912 | msg='updated repo ID:%s %s' % (repo.repo_id, repo.repo_name), | |||
|
913 | repository=repo.get_api_data() | |||
|
914 | ) | |||
|
915 | except Exception: | |||
|
916 | log.error(traceback.format_exc()) | |||
|
917 | raise JSONRPCError('failed to update repo `%s`' % repoid) | |||
|
918 | ||||
832 | @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository') |
|
919 | @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository') | |
833 | def fork_repo(self, apiuser, repoid, fork_name, owner=Optional(OAttr('apiuser')), |
|
920 | def fork_repo(self, apiuser, repoid, fork_name, owner=Optional(OAttr('apiuser')), | |
834 | description=Optional(''), copy_permissions=Optional(False), |
|
921 | description=Optional(''), copy_permissions=Optional(False), |
General Comments 0
You need to be logged in to leave comments.
Login now