Show More
@@ -750,10 +750,12 b' OUTPUT::' | |||||
750 | create_repo |
|
750 | create_repo | |
751 | ----------- |
|
751 | ----------- | |
752 |
|
752 | |||
753 |
Create a repository. If the repository name contains "/", |
|
753 | Create a repository. If the repository name contains "/", the repository will be | |
754 | groups will be created. For example "foo/bar/baz" will create repository groups |
|
754 | created in the repository group indicated by that path. Any such repository | |
755 | "foo", "bar" (with "foo" as parent), and create "baz" repository with |
|
755 | groups need to exist before calling this method, or the call will fail. | |
756 | "bar" as group. |
|
756 | For example "foo/bar/baz" will create a repository "baz" inside the repository | |
|
757 | group "bar" which itself is in a repository group "foo", but both "foo" and | |||
|
758 | "bar" already need to exist before calling this method. | |||
757 | This command can only be executed using the api_key of a user with admin rights, |
|
759 | This command can only be executed using the api_key of a user with admin rights, | |
758 | or that of a regular user with create repository permission. |
|
760 | or that of a regular user with create repository permission. | |
759 | Regular users cannot specify owner parameter. |
|
761 | Regular users cannot specify owner parameter. |
@@ -1401,9 +1401,9 b' class ApiController(JSONRPCController):' | |||||
1401 | enable_downloads=Optional(False), |
|
1401 | enable_downloads=Optional(False), | |
1402 | copy_permissions=Optional(False)): |
|
1402 | copy_permissions=Optional(False)): | |
1403 | """ |
|
1403 | """ | |
1404 |
Creates a repository. |
|
1404 | Creates a repository. The repository name contains the full path, but the | |
1405 |
|
|
1405 | parent repository group must exist. For example "foo/bar/baz" require the groups | |
1406 |
"foo" |
|
1406 | "foo" and "bar" (with "foo" as parent), and create "baz" repository with | |
1407 | "bar" as group. This command can be executed only using api_key |
|
1407 | "bar" as group. This command can be executed only using api_key | |
1408 | belonging to user with admin rights or regular user that have create |
|
1408 | belonging to user with admin rights or regular user that have create | |
1409 | repository permission. Regular users cannot specify owner parameter |
|
1409 | repository permission. Regular users cannot specify owner parameter | |
@@ -1485,11 +1485,15 b' class ApiController(JSONRPCController):' | |||||
1485 | copy_permissions = Optional.extract(copy_permissions) |
|
1485 | copy_permissions = Optional.extract(copy_permissions) | |
1486 |
|
1486 | |||
1487 | try: |
|
1487 | try: | |
1488 |
repo_name_ |
|
1488 | repo_name_parts = repo_name.split('/') | |
1489 | # create structure of groups and return the last group |
|
1489 | repo_group = None | |
1490 | repo_group = map_groups(repo_name) |
|
1490 | if len(repo_name_parts) > 1: | |
|
1491 | group_name = '/'.join(repo_name_parts[:-1]) | |||
|
1492 | repo_group = RepoGroup.get_by_group_name(group_name) | |||
|
1493 | if repo_group is None: | |||
|
1494 | raise JSONRPCError("repo group `%s` not found" % group_name) | |||
1491 | data = dict( |
|
1495 | data = dict( | |
1492 |
repo_name=repo_name_ |
|
1496 | repo_name=repo_name_parts[-1], | |
1493 | repo_name_full=repo_name, |
|
1497 | repo_name_full=repo_name, | |
1494 | repo_type=repo_type, |
|
1498 | repo_type=repo_type, | |
1495 | repo_description=description, |
|
1499 | repo_description=description, | |
@@ -1673,14 +1677,18 b' class ApiController(JSONRPCController):' | |||||
1673 | owner = get_user_or_error(owner) |
|
1677 | owner = get_user_or_error(owner) | |
1674 |
|
1678 | |||
1675 | try: |
|
1679 | try: | |
1676 | # create structure of groups and return the last group |
|
1680 | fork_name_parts = fork_name.split('/') | |
1677 |
group = |
|
1681 | repo_group = None | |
1678 | fork_base_name = fork_name.rsplit('/', 1)[-1] |
|
1682 | if len(fork_name_parts) > 1: | |
|
1683 | group_name = '/'.join(fork_name_parts[:-1]) | |||
|
1684 | repo_group = RepoGroup.get_by_group_name(group_name) | |||
|
1685 | if repo_group is None: | |||
|
1686 | raise JSONRPCError("repo group `%s` not found" % group_name) | |||
1679 |
|
1687 | |||
1680 | form_data = dict( |
|
1688 | form_data = dict( | |
1681 |
repo_name=fork_ |
|
1689 | repo_name=fork_name_parts[-1], | |
1682 | repo_name_full=fork_name, |
|
1690 | repo_name_full=fork_name, | |
1683 | repo_group=group, |
|
1691 | repo_group=repo_group, | |
1684 | repo_type=repo.repo_type, |
|
1692 | repo_type=repo.repo_type, | |
1685 | description=Optional.extract(description), |
|
1693 | description=Optional.extract(description), | |
1686 | private=Optional.extract(private), |
|
1694 | private=Optional.extract(private), |
@@ -1018,6 +1018,20 b' class _BaseTestApi(object):' | |||||
1018 | repo_group_name = 'my_gr' |
|
1018 | repo_group_name = 'my_gr' | |
1019 | repo_name = '%s/api-repo' % repo_group_name |
|
1019 | repo_name = '%s/api-repo' % repo_group_name | |
1020 |
|
1020 | |||
|
1021 | # repo creation can no longer also create repo group | |||
|
1022 | id_, params = _build_data(self.apikey, 'create_repo', | |||
|
1023 | repo_name=repo_name, | |||
|
1024 | owner=TEST_USER_ADMIN_LOGIN, | |||
|
1025 | repo_type=self.REPO_TYPE,) | |||
|
1026 | response = api_call(self, params) | |||
|
1027 | expected = u'repo group `%s` not found' % repo_group_name | |||
|
1028 | self._compare_error(id_, expected, given=response.body) | |||
|
1029 | assert RepoModel().get_by_repo_name(repo_name) is None | |||
|
1030 | ||||
|
1031 | # create group before creating repo | |||
|
1032 | rg = fixture.create_repo_group(repo_group_name) | |||
|
1033 | Session().commit() | |||
|
1034 | ||||
1021 | id_, params = _build_data(self.apikey, 'create_repo', |
|
1035 | id_, params = _build_data(self.apikey, 'create_repo', | |
1022 | repo_name=repo_name, |
|
1036 | repo_name=repo_name, | |
1023 | owner=TEST_USER_ADMIN_LOGIN, |
|
1037 | owner=TEST_USER_ADMIN_LOGIN, | |
@@ -1144,7 +1158,7 b' class _BaseTestApi(object):' | |||||
1144 | self._compare_error(id_, expected, given=response.body) |
|
1158 | self._compare_error(id_, expected, given=response.body) | |
1145 |
|
1159 | |||
1146 | def test_api_create_repo_dot_dot(self): |
|
1160 | def test_api_create_repo_dot_dot(self): | |
1147 |
# |
|
1161 | # it is only possible to create repositories in existing repo groups - and '..' can't be used | |
1148 | group_name = '%s/..' % TEST_REPO_GROUP |
|
1162 | group_name = '%s/..' % TEST_REPO_GROUP | |
1149 | repo_name = '%s/%s' % (group_name, 'could-be-outside') |
|
1163 | repo_name = '%s/%s' % (group_name, 'could-be-outside') | |
1150 | id_, params = _build_data(self.apikey, 'create_repo', |
|
1164 | id_, params = _build_data(self.apikey, 'create_repo', | |
@@ -1152,12 +1166,8 b' class _BaseTestApi(object):' | |||||
1152 | owner=TEST_USER_ADMIN_LOGIN, |
|
1166 | owner=TEST_USER_ADMIN_LOGIN, | |
1153 | repo_type=self.REPO_TYPE,) |
|
1167 | repo_type=self.REPO_TYPE,) | |
1154 | response = api_call(self, params) |
|
1168 | response = api_call(self, params) | |
1155 | expected = { |
|
1169 | expected = u'repo group `%s` not found' % group_name | |
1156 | u'msg': u"Created new repository `%s`" % repo_name, |
|
1170 | self._compare_error(id_, expected, given=response.body) | |
1157 | u'success': True, |
|
|||
1158 | u'task': None, |
|
|||
1159 | } |
|
|||
1160 | self._compare_ok(id_, expected, given=response.body) |
|
|||
1161 | fixture.destroy_repo(repo_name) |
|
1171 | fixture.destroy_repo(repo_name) | |
1162 |
|
1172 | |||
1163 | @mock.patch.object(RepoModel, 'create', crash) |
|
1173 | @mock.patch.object(RepoModel, 'create', crash) |
General Comments 0
You need to be logged in to leave comments.
Login now