From 6bf79a4e43b98616474b3246ccc8e763626c04ce Mon Sep 17 00:00:00 2001 From: Matt Prahl Date: Apr 11 2017 13:41:42 +0000 Subject: Display the users and groups tied to the repo in the API --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 4554bb5..441e7df 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -774,6 +774,26 @@ class Project(BASE): } @property + def access_users_json(self): + json_access_users = {'owner': [self.user.username]} + for access, users in self.access_users.items(): + json_access_users[access] = [] + for user in users: + json_access_users[access].append(user.user) + + return json_access_users + + @property + def access_groups_json(self): + json_access_groups = {} + for access, groups in self.access_groups.items(): + json_access_groups[access] = [] + for group in groups: + json_access_groups[access].append(group.group_name) + + return json_access_groups + + @property def access_groups(self): ''' Return a dictionary with all group access ''' @@ -800,6 +820,8 @@ class Project(BASE): public=public, api=api) if self.parent else None, 'date_created': self.date_created.strftime('%s'), 'user': self.user.to_json(public=public), + 'access_users': self.access_users_json, + 'access_groups': self.access_groups_json, 'tags': self.tags_text, 'priorities': self.priorities, 'custom_keys': custom_keys, diff --git a/tests/test_pagure_flask_api_fork.py b/tests/test_pagure_flask_api_fork.py index 39a33d5..3ecdecf 100644 --- a/tests/test_pagure_flask_api_fork.py +++ b/tests/test_pagure_flask_api_fork.py @@ -93,88 +93,105 @@ class PagureFlaskApiForktests(tests.Modeltests): data['requests'][0]['repo_from']['date_created'] = '1431414800' data['requests'][0]['uid'] = '1431414800' data['requests'][0]['last_updated'] = '1431414800' - self.assertDictEqual( - data, - { - "args": { + expected_data = { + "args": { "assignee": None, "author": None, "status": True - }, - "total_requests": 1, - "requests": [ - { - "assignee": None, - "branch": "master", - "branch_from": "master", - "closed_at": None, - "closed_by": None, - "comments": [], - "commit_start": None, - "commit_stop": None, - "date_created": "1431414800", - "id": 1, - "initial_comment": None, - "last_updated": "1431414800", - "project": { + }, + "requests": [{ + "assignee": None, + "branch": "master", + "branch_from": "master", + "closed_at": None, + "closed_by": None, + "comments": [], + "commit_start": None, + "commit_stop": None, + "date_created": "1431414800", + "id": 1, + "initial_comment": None, + "last_updated": "1431414800", + "project": { + "access_groups": { + "admin": [], + "commit": [], + "ticket": [] + }, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": [] + }, "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate" ], "custom_keys": [], "date_created": "1431414800", "description": "test project #1", + "fullname": "test", "id": 1, "milestones": {}, "name": "test", - "fullname": "test", "namespace": None, "parent": None, "priorities": {}, "tags": [], "user": { - "fullname": "PY C", - "name": "pingou" + "fullname": "PY C", + "name": "pingou" } - }, - "remote_git": None, - "repo_from": { + }, + "remote_git": None, + "repo_from": { + "access_groups": { + "admin": [], + "commit": [], + "ticket": []}, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": [] + }, "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate" ], "custom_keys": [], "date_created": "1431414800", "description": "test project #1", + "fullname": "test", "id": 1, "milestones": {}, "name": "test", - "fullname": "test", "namespace": None, "parent": None, "priorities": {}, "tags": [], "user": { - "fullname": "PY C", - "name": "pingou" + "fullname": "PY C", + "name": "pingou" } - }, - "status": 'Open', - "title": "test pull-request", - "uid": "1431414800", - "updated_on": "1431414800", - "user": { + }, + "status": "Open", + "title": "test pull-request", + "uid": "1431414800", + "updated_on": "1431414800", + "user": { "fullname": "PY C", "name": "pingou" - } } - ] - } - ) + }], + "total_requests": 1 + } + self.assertDictEqual(data, expected_data) headers = {'Authorization': 'token aaabbbcccddd'} @@ -249,78 +266,95 @@ class PagureFlaskApiForktests(tests.Modeltests): data['repo_from']['date_created'] = '1431414800' data['uid'] = '1431414800' data['last_updated'] = '1431414800' - self.assertDictEqual( - data, - { - "assignee": None, - "branch": "master", - "branch_from": "master", - "closed_at": None, - "closed_by": None, - "comments": [], - "commit_start": None, - "commit_stop": None, - "date_created": "1431414800", - "id": 1, - "initial_comment": None, - "last_updated": "1431414800", - "project": { + expected_data = { + "assignee": None, + "branch": "master", + "branch_from": "master", + "closed_at": None, + "closed_by": None, + "comments": [], + "commit_start": None, + "commit_stop": None, + "date_created": "1431414800", + "id": 1, + "initial_comment": None, + "last_updated": "1431414800", + "project": { + "access_groups": { + "admin": [], + "commit": [], + "ticket": [] + }, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": [] + }, "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate" ], "custom_keys": [], "date_created": "1431414800", "description": "test project #1", - "id": 1, - "milestones": {}, - "name": "test", "fullname": "test", - "namespace": None, - "parent": None, - "priorities": {}, - "tags": [], - "user": { - "fullname": "PY C", - "name": "pingou" - } - }, - "remote_git": None, - "repo_from": { - "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" - ], - "custom_keys": [], - "date_created": "1431414800", - "description": "test project #1", "id": 1, "milestones": {}, "name": "test", - "fullname": "test", "namespace": None, "parent": None, "priorities": {}, "tags": [], "user": { - "fullname": "PY C", - "name": "pingou" + "fullname": "PY C", + "name": "pingou" } - }, - "status": 'Open', - "title": "test pull-request", - "uid": "1431414800", - "updated_on": "1431414800", - "user": { + }, + "remote_git": None, + "repo_from": { + "access_groups": { + "admin": [], + "commit": [], + "ticket": []}, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": []}, + "close_status": [ + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate"], + "custom_keys": [], + "date_created": "1431414800", + "description": "test project #1", + "fullname": "test", + "id": 1, + "milestones": {}, + "name": "test", + "namespace": None, + "parent": None, + "priorities": {}, + "tags": [], + "user": { + "fullname": "PY C", + "name": "pingou" + } + }, + "status": "Open", + "title": "test pull-request", + "uid": "1431414800", + "updated_on": "1431414800", + "user": { "fullname": "PY C", "name": "pingou" - } } - ) + } + self.assertDictEqual(data, expected_data) headers = {'Authorization': 'token aaabbbcccddd'} diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index f80a0ee..6bfb9b5 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -141,177 +141,213 @@ class PagureFlaskApiProjecttests(tests.Modeltests): self.assertEqual(output.status_code, 200) data = json.loads(output.data) data['projects'][0]['date_created'] = "1436527638" - self.assertDictEqual( - data, - { - "args": { - "fork": None, - "pattern": None, - "tags": [ - "infra" + expected_data = { + 'args': { + 'fork': None, + 'pattern': None, + 'tags': ['infra'], + 'username': None + }, + 'projects': [{ + 'access_groups': { + 'admin': [], + 'commit': [], + 'ticket': []}, + 'access_users': { + 'admin': [], + 'commit': [], + 'owner': ['pingou'], + 'ticket': []}, + 'close_status': [ + 'Invalid', + 'Insufficient data', + 'Fixed', + 'Duplicate' ], - "username": None - }, - "total_projects": 1, - "projects": [ - { - "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" - ], - "custom_keys": [], - "date_created": "1436527638", - "description": "test project #1", - "id": 1, - "milestones": {}, - "name": "test", - "fullname": "test", - "namespace": None, - "parent": None, - "priorities": {}, - "tags": ["infra"], - "user": { - "fullname": "PY C", - "name": "pingou" - } + 'custom_keys': [], + 'date_created': '1436527638', + 'description': 'test project #1', + 'fullname': 'test', + 'id': 1, + 'milestones': {}, + 'name': 'test', + 'namespace': None, + 'parent': None, + 'priorities': {}, + 'tags': ['infra'], + 'user': { + 'fullname': 'PY C', + 'name': 'pingou' } - ] - } - ) + }], + 'total_projects': 1 + } + self.assertDictEqual(data, expected_data) + output = self.app.get('/api/0/projects?username=pingou') self.assertEqual(output.status_code, 200) data = json.loads(output.data) data['projects'][0]['date_created'] = "1436527638" data['projects'][1]['date_created'] = "1436527638" data['projects'][2]['date_created'] = "1436527638" - self.assertDictEqual( - data, - { - "args": { + expected_data = { + "args": { "fork": None, "pattern": None, "tags": [], - "username": "pingou", - }, - "total_projects": 3, - "projects": [ + "username": "pingou" + }, + "projects": [ { - "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" + "access_groups": { + "admin": [], + "commit": [], + "ticket": []}, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": [] + }, + "close_status": [ + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate" ], - "custom_keys": [], - "date_created": "1436527638", - "description": "test project #1", - "id": 1, - "milestones": {}, - "name": "test", - "fullname": "test", - "namespace": None, - "parent": None, - "priorities": {}, - "tags": ["infra"], - "user": { - "fullname": "PY C", - "name": "pingou" - } + "custom_keys": [], + "date_created": "1436527638", + "description": "test project #1", + "fullname": "test", + "id": 1, + "milestones": {}, + "name": "test", + "namespace": None, + "parent": None, + "priorities": {}, + "tags": ["infra"], + "user": { + "fullname": "PY C", + "name": "pingou" + } }, { - "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" + "access_groups": { + "admin": [], + "commit": [], + "ticket": [] + }, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": [] + }, + "close_status": [ + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate" ], - "custom_keys": [], - "date_created": "1436527638", - "description": "test project #2", - "id": 2, - "milestones": {}, - "name": "test2", - "fullname": "test2", - "namespace": None, - "parent": None, - "priorities": {}, - "tags": [], - "user": { - "fullname": "PY C", - "name": "pingou" - } + "custom_keys": [], + "date_created": "1436527638", + "description": "test project #2", + "fullname": "test2", + "id": 2, + "milestones": {}, + "name": "test2", + "namespace": None, + "parent": None, + "priorities": {}, + "tags": [], + "user": { + "fullname": "PY C", + "name": "pingou" + } }, { - "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" + "access_groups": { + "admin": [], + "commit": [], + "ticket": []}, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": []}, + "close_status": [ + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate" ], - "custom_keys": [], - "date_created": "1436527638", - "description": "namespaced test project", - "id": 3, - "milestones": {}, - "name": "test3", - "fullname": "somenamespace/test3", - "namespace": "somenamespace", - "parent": None, - "priorities": {}, - "tags": [], - "user": { - "fullname": "PY C", - "name": "pingou" - } + "custom_keys": [], + "date_created": "1436527638", + "description": "namespaced test project", + "fullname": "somenamespace/test3", + "id": 3, + "milestones": {}, + "name": "test3", + "namespace": "somenamespace", + "parent": None, + "priorities": {}, + "tags": [], + "user": { + "fullname": "PY C", + "name": "pingou" + } } - ] - } - ) + ], + "total_projects": 3 + } + self.assertDictEqual(data, expected_data) + output = self.app.get('/api/0/projects?username=pingou&tags=infra') self.assertEqual(output.status_code, 200) data = json.loads(output.data) data['projects'][0]['date_created'] = "1436527638" - self.assertDictEqual( - data, - { - "args": { + expected_data = { + "args": { "fork": None, "pattern": None, - "tags": [ - "infra" - ], + "tags": ["infra"], "username": "pingou" - }, - "total_projects": 1, - "projects": [ - { - "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" - ], - "custom_keys": [], - "date_created": "1436527638", - "description": "test project #1", - "id": 1, - "milestones": {}, - "name": "test", - "fullname": "test", - "namespace": None, - "parent": None, - "priorities": {}, - "tags": ["infra"], - "user": { + }, + "projects": [{ + "access_groups": { + "admin": [], + "commit": [], + "ticket": [] + }, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": []}, + "close_status": [ + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate"], + "custom_keys": [], + "date_created": "1436527638", + "description": "test project #1", + "fullname": "test", + "id": 1, + "milestones": {}, + "name": "test", + "namespace": None, + "parent": None, + "priorities": {}, + "tags": ["infra"], + "user": { "fullname": "PY C", "name": "pingou" - } } - ] - } - ) + }], + "total_projects": 1 + } + self.assertDictEqual(data, expected_data) def test_api_project(self): """ Test the api_project method of the flask api. """ @@ -348,32 +384,40 @@ class PagureFlaskApiProjecttests(tests.Modeltests): self.assertEqual(output.status_code, 200) data = json.loads(output.data) data['date_created'] = "1436527638" - self.assertDictEqual( - data, - { - "close_status": [ + expected_data ={ + "access_groups": { + "admin": [], + "commit": [], + "ticket": [] + }, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": []}, + "close_status": [ "Invalid", "Insufficient data", "Fixed", "Duplicate" - ], - "custom_keys": [], - "date_created": "1436527638", - "description": "test project #1", - "id": 1, - "milestones": {}, - "name": "test", - "fullname": "test", - "namespace": None, - "parent": None, - "priorities": {}, - "tags": ["infra"], - "user": { + ], + "custom_keys": [], + "date_created": "1436527638", + "description": "test project #1", + "fullname": "test", + "id": 1, + "milestones": {}, + "name": "test", + "namespace": None, + "parent": None, + "priorities": {}, + "tags": ["infra"], + "user": { "fullname": "PY C", "name": "pingou" - } } - ) + } + self.assertDictEqual(data, expected_data) @patch('pagure.lib.git.generate_gitolite_acls') def test_api_new_project(self, p_gga): diff --git a/tests/test_pagure_flask_api_user.py b/tests/test_pagure_flask_api_user.py index a4f3254..b427636 100644 --- a/tests/test_pagure_flask_api_user.py +++ b/tests/test_pagure_flask_api_user.py @@ -91,116 +91,148 @@ class PagureFlaskApiUSertests(tests.Modeltests): data['repos'][0]['date_created'] = "1490272832" data['repos'][1]['date_created'] = "1490272832" data['repos'][2]['date_created'] = "1490272832" - exp = { + expected_data = { "forks": [], "repos": [ { - "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" - ], - "custom_keys": [], - "date_created": "1490272832", - "description": "test project #1", - "fullname": "test", - "id": 1, - "milestones": {}, - "name": "test", - "namespace": None, - "parent": None, - "priorities": {}, - "settings": { - "Enforce_signed-off_commits_in_pull-request": False, - "Minimum_score_to_merge_pull-request": -1, - "Only_assignee_can_merge_pull-request": False, - "Web-hooks": None, - "always_merge": False, - "fedmsg_notifications": True, - "issue_tracker": True, - "issues_default_to_private": False, - "project_documentation": False, - "pull_request_access_only": False, - "pull_requests": True - }, - "tags": [], - "user": { - "fullname": "PY C", - "name": "pingou" - } + "access_groups": { + "admin": [], + "commit": [], + "ticket": [] + }, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": [] + }, + "close_status": [ + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate" + ], + "custom_keys": [], + "date_created": "1490272832", + "description": "test project #1", + "fullname": "test", + "id": 1, + "milestones": {}, + "name": "test", + "namespace": None, + "parent": None, + "priorities": {}, + "settings": { + "Enforce_signed-off_commits_in_pull-request": False, + "Minimum_score_to_merge_pull-request": -1, + "Only_assignee_can_merge_pull-request": False, + "Web-hooks": None, + "always_merge": False, + "fedmsg_notifications": True, + "issue_tracker": True, + "issues_default_to_private": False, + "pull_request_access_only": False, + "project_documentation": False, + "pull_requests": True + }, + "tags": [], + "user": { + "fullname": "PY C", + "name": "pingou" + } }, { - "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" - ], - "custom_keys": [], - "date_created": "1490272832", - "description": "test project #2", - "fullname": "test2", - "id": 2, - "milestones": {}, - "name": "test2", - "namespace": None, - "parent": None, - "priorities": {}, - "settings": { - "Enforce_signed-off_commits_in_pull-request": False, - "Minimum_score_to_merge_pull-request": -1, - "Only_assignee_can_merge_pull-request": False, - "Web-hooks": None, - "always_merge": False, - "fedmsg_notifications": True, - "issue_tracker": True, - "issues_default_to_private": False, - "project_documentation": False, - "pull_request_access_only": False, - "pull_requests": True - }, - "tags": [], - "user": { - "fullname": "PY C", - "name": "pingou" - } + "access_groups": { + "admin": [], + "commit": [], + "ticket": [] + }, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": [] + }, + "close_status": [ + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate" + ], + "custom_keys": [], + "date_created": "1490272832", + "description": "test project #2", + "fullname": "test2", + "id": 2, + "milestones": {}, + "name": "test2", + "namespace": None, + "parent": None, + "priorities": {}, + "settings": { + "Enforce_signed-off_commits_in_pull-request": False, + "Minimum_score_to_merge_pull-request": -1, + "Only_assignee_can_merge_pull-request": False, + "Web-hooks": None, + "always_merge": False, + "fedmsg_notifications": True, + "issue_tracker": True, + "issues_default_to_private": False, + "pull_request_access_only": False, + "project_documentation": False, + "pull_requests": True + }, + "tags": [], + "user": { + "fullname": "PY C", + "name": "pingou" + } }, { - "close_status": [ - "Invalid", - "Insufficient data", - "Fixed", - "Duplicate" - ], - "custom_keys": [], - "date_created": "1490272832", - "description": "namespaced test project", - "fullname": "somenamespace/test3", - "id": 3, - "milestones": {}, - "name": "test3", - "namespace": "somenamespace", - "parent": None, - "priorities": {}, - "settings": { - "Enforce_signed-off_commits_in_pull-request": False, - "Minimum_score_to_merge_pull-request": -1, - "Only_assignee_can_merge_pull-request": False, - "Web-hooks": None, - "always_merge": False, - "fedmsg_notifications": True, - "issue_tracker": True, - "issues_default_to_private": False, - "project_documentation": False, - "pull_request_access_only": False, - "pull_requests": True - }, - "tags": [], - "user": { - "fullname": "PY C", - "name": "pingou" - } + "access_groups": { + "admin": [], + "commit": [], + "ticket": []}, + "access_users": { + "admin": [], + "commit": [], + "owner": ["pingou"], + "ticket": [] + }, + "close_status": [ + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate" + ], + "custom_keys": [], + "date_created": "1490272832", + "description": "namespaced test project", + "fullname": "somenamespace/test3", + "id": 3, + "milestones": {}, + "name": "test3", + "namespace": "somenamespace", + "parent": None, + "priorities": {}, + "settings": { + "Enforce_signed-off_commits_in_pull-request": False, + "Minimum_score_to_merge_pull-request": -1, + "Only_assignee_can_merge_pull-request": False, + "Web-hooks": None, + "always_merge": False, + "fedmsg_notifications": True, + "issue_tracker": True, + "issues_default_to_private": False, + "project_documentation": False, + "pull_request_access_only": False, + "pull_requests": True + }, + "tags": [], + "user": { + "fullname": "PY C", + "name": "pingou" + } } ], "user": { @@ -208,8 +240,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): "name": "pingou" } } - - self.assertEqual(data, exp) + self.assertEqual(data, expected_data) @patch('pagure.lib.notify.send_email') def test_api_view_user_activity_stats(self, mockemail): diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index c972124..ea521e7 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -1607,7 +1607,7 @@ new file mode 100644 index 0000000..60f7480 --- /dev/null +++ b/456 -@@ -0,0 +1,100 @@ +@@ -0,0 +1,126 @@ +{ + "assignee": null, + "branch": "master", @@ -1622,6 +1622,19 @@ index 0000000..60f7480 + "initial_comment": null, + "last_updated": null, + "project": { ++ "access_groups": { ++ "admin": [], ++ "commit": [], ++ "ticket": [] ++ }, ++ "access_users": { ++ "admin": [], ++ "commit": [], ++ "owner": [ ++ "pingou" ++ ], ++ "ticket": [] ++ }, + "close_status": [], + "custom_keys": [], + "date_created": null, @@ -1659,6 +1672,19 @@ index 0000000..60f7480 + }, + "remote_git": null, + "repo_from": { ++ "access_groups": { ++ "admin": [], ++ "commit": [], ++ "ticket": [] ++ }, ++ "access_users": { ++ "admin": [], ++ "commit": [], ++ "owner": [ ++ "pingou" ++ ], ++ "ticket": [] ++ }, + "close_status": [], + "custom_keys": [], + "date_created": null, @@ -1741,7 +1767,7 @@ index 0000000..60f7480 row = '+++ b/456' npatch.append(row) patch = '\n'.join(npatch) - #print patch + # print patch self.assertEqual(patch, exp) def test_update_ticket_from_git_no_priority(self):