diff --git a/swh/web/api/urls.py b/swh/web/api/urls.py --- a/swh/web/api/urls.py +++ b/swh/web/api/urls.py @@ -8,7 +8,6 @@ import swh.web.api.views.identifiers # noqa import swh.web.api.views.origin # noqa import swh.web.api.views.origin_save # noqa -import swh.web.api.views.person # noqa import swh.web.api.views.release # noqa import swh.web.api.views.revision # noqa import swh.web.api.views.snapshot # noqa diff --git a/swh/web/api/utils.py b/swh/web/api/utils.py --- a/swh/web/api/utils.py +++ b/swh/web/api/utils.py @@ -70,11 +70,6 @@ reverse('api-1-snapshot', url_args={'snapshot_id': obj['target']}) - if 'author' in obj: - author = obj['author'] - obj['author_url'] = reverse('api-1-person', - url_args={'person_id': author['id']}) - return obj @@ -172,16 +167,6 @@ revision['history_url'] = reverse('api-1-revision-log', url_args={'sha1_git': revision['id']}) - if 'author' in revision: - author = revision['author'] - revision['author_url'] = reverse('api-1-person', - url_args={'person_id': author['id']}) - - if 'committer' in revision: - committer = revision['committer'] - revision['committer_url'] = reverse( - 'api-1-person', url_args={'person_id': committer['id']}) - if 'directory' in revision: revision['directory_url'] = reverse( 'api-1-directory', url_args={'sha1_git': revision['directory']}) diff --git a/swh/web/api/views/person.py b/swh/web/api/views/person.py deleted file mode 100644 --- a/swh/web/api/views/person.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (C) 2015-2019 The Software Heritage developers -# See the AUTHORS file at the top-level directory of this distribution -# License: GNU Affero General Public License version 3, or any later version -# See top-level LICENSE file for more information - -from swh.web.common import service -from swh.web.api.apidoc import api_doc, format_docstring -from swh.web.api.apiurls import api_route -from swh.web.api.views.utils import api_lookup - - -@api_route(r'/person/(?P[0-9]+)/', 'api-1-person') -@api_doc('/person/') -@format_docstring() -def api_person(request, person_id): - """ - .. http:get:: /api/1/person/(person_id)/ - - Get information about a person in the archive. - - :param int person_id: a person identifier - - {common_headers} - - :>json string email: the email of the person - :>json string fullname: the full name of the person: combination of its - name and email - :>json number id: the unique identifier of the person - :>json string name: the name of the person - - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - - :statuscode 200: no error - :statuscode 404: requested person can not be found in the archive - - **Example:** - - .. parsed-literal:: - - :swh_web_api:`person/8275/` - """ - return api_lookup( - service.lookup_person, person_id, - notfound_msg='Person with id {} not found.'.format(person_id)) diff --git a/swh/web/api/views/release.py b/swh/web/api/views/release.py --- a/swh/web/api/views/release.py +++ b/swh/web/api/views/release.py @@ -29,9 +29,6 @@ {common_headers} :>json object author: information about the author of the release - :>json string author_url: link to - :http:get:`/api/1/person/(person_id)/` to get information about the - author of the release :>json string date: ISO representation of the release date (in UTC) :>json string id: the release unique identifier :>json string message: the message associated to the release diff --git a/swh/web/api/views/revision.py b/swh/web/api/views/revision.py --- a/swh/web/api/views/revision.py +++ b/swh/web/api/views/revision.py @@ -16,14 +16,8 @@ DOC_RETURN_REVISION = ''' :>json object author: information about the author of the revision - :>json string author_url: link to - :http:get:`/api/1/person/(person_id)/` to get information about the - author of the revision :>json object committer: information about the committer of the revision - :>json string committer_url: link to - :http:get:`/api/1/person/(person_id)/` to get information about the - committer of the revision :>json string committer_date: ISO representation of the commit date (in UTC) :>json string date: ISO representation of the revision date (in UTC) diff --git a/swh/web/browse/urls.py b/swh/web/browse/urls.py --- a/swh/web/browse/urls.py +++ b/swh/web/browse/urls.py @@ -9,7 +9,6 @@ import swh.web.browse.views.directory # noqa import swh.web.browse.views.content # noqa import swh.web.browse.views.origin # noqa -import swh.web.browse.views.person # noqa import swh.web.browse.views.release # noqa import swh.web.browse.views.revision # noqa import swh.web.browse.views.snapshot # noqa diff --git a/swh/web/browse/utils.py b/swh/web/browse/utils.py --- a/swh/web/browse/utils.py +++ b/swh/web/browse/utils.py @@ -528,28 +528,6 @@ return query_params -def gen_person_link(person_id, person_name, snapshot_context=None, - link_attrs=None): - """ - Utility function for generating a link to a person HTML view - to insert in Django templates. - - Args: - person_id (int): a person id - person_name (str): the associated person name - link_attrs (dict): optional attributes (e.g. class) - to add to the link - - Returns: - An HTML link in the form 'person_name' - - """ - query_params = _snapshot_context_query_params(snapshot_context) - person_url = reverse('browse-person', url_args={'person_id': person_id}, - query_params=query_params) - return gen_link(person_url, person_name or 'None', link_attrs) - - def gen_revision_url(revision_id, snapshot_context=None): """ Utility function for generating an url to a revision. diff --git a/swh/web/browse/views/person.py b/swh/web/browse/views/person.py deleted file mode 100644 --- a/swh/web/browse/views/person.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (C) 2017-2018 The Software Heritage developers -# See the AUTHORS file at the top-level directory of this distribution -# License: GNU Affero General Public License version 3, or any later version -# See top-level LICENSE file for more information - - -from django.shortcuts import render -from swh.web.common import service -from swh.web.common.exc import handle_view_exception -from swh.web.browse.browseurls import browse_route -from swh.web.browse.utils import get_snapshot_context - - -@browse_route(r'person/(?P[0-9]+)/', - view_name='browse-person') -def person_browse(request, person_id): - """ - Django view that produces an HTML display of a swh person - identified by its id. - - The url that points to it is :http:get:`/browse/person/(person_id)/`. - """ - try: - snapshot_context = None - origin_type = request.GET.get('origin_type', None) - origin_url = request.GET.get('origin_url', None) - if not origin_url: - origin_url = request.GET.get('origin', None) - snapshot_id = request.GET.get('snapshot_id', None) - if origin_url: - snapshot_context = get_snapshot_context(None, origin_type, - origin_url) - elif snapshot_id: - snapshot_context = get_snapshot_context(snapshot_id) - person = service.lookup_person(person_id) - except Exception as exc: - return handle_view_exception(request, exc) - - heading = 'Person - %s' % person['fullname'] - if snapshot_context: - context_found = 'snapshot: %s' % snapshot_context['snapshot_id'] - if origin_url: - context_found = 'origin: %s' % origin_url - heading += ' - %s' % context_found - - return render(request, 'browse/person.html', - {'heading': heading, - 'swh_object_name': 'Person', - 'swh_object_metadata': person, - 'snapshot_context': snapshot_context, - 'vault_cooking': None, - 'show_actions_menu': False}) diff --git a/swh/web/browse/views/release.py b/swh/web/browse/views/release.py --- a/swh/web/browse/views/release.py +++ b/swh/web/browse/views/release.py @@ -12,7 +12,7 @@ from swh.web.common.exc import NotFoundExc, handle_view_exception from swh.web.browse.browseurls import browse_route from swh.web.browse.utils import ( - gen_person_link, gen_revision_link, get_snapshot_context, gen_link, + gen_revision_link, get_snapshot_context, gen_link, gen_snapshot_link, get_swh_persistent_ids, gen_directory_link, gen_content_link, gen_release_link ) @@ -71,9 +71,7 @@ if release['author']: author_name = release['author']['name'] or \ release['author']['fullname'] - release_data['author'] = \ - gen_person_link(release['author']['id'], author_name, - snapshot_context) + release_data['author'] = author_name, release_data['date'] = format_utc_iso_date(release['date']) release_data['release'] = sha1_git release_data['name'] = release['name'] diff --git a/swh/web/browse/views/revision.py b/swh/web/browse/views/revision.py --- a/swh/web/browse/views/revision.py +++ b/swh/web/browse/views/revision.py @@ -21,7 +21,7 @@ from swh.web.common.exc import NotFoundExc, handle_view_exception from swh.web.browse.browseurls import browse_route from swh.web.browse.utils import ( - gen_link, gen_person_link, gen_revision_link, gen_revision_url, + gen_link, gen_revision_link, gen_revision_url, get_snapshot_context, get_revision_log_url, get_directory_entries, gen_directory_link, request_content, prepare_content_for_display, content_display_max_size, gen_snapshot_link, get_readme_to_display, @@ -326,14 +326,12 @@ if revision['author']: author_name = revision['author']['name'] or \ revision['author']['fullname'] - revision_data['author'] = \ - gen_person_link(revision['author']['id'], author_name, - snapshot_context) + revision_data['author'] = author_name, revision_data['committer'] = 'None' if revision['committer']: - revision_data['committer'] = \ - gen_person_link(revision['committer']['id'], - revision['committer']['name'], snapshot_context) + committer_name = revision['committer']['name'] or \ + revision['committer']['fullname'] + revision_data['committer'] = committer_name revision_data['committer date'] = \ format_utc_iso_date(revision['committer_date']) revision_data['date'] = format_utc_iso_date(revision['date']) diff --git a/swh/web/common/converters.py b/swh/web/common/converters.py --- a/swh/web/common/converters.py +++ b/swh/web/common/converters.py @@ -353,7 +353,7 @@ def from_directory_entry(dir_entry): - """Convert swh person to serializable person dictionary. + """Convert swh directory to serializable directory dictionary. """ return from_swh(dir_entry, @@ -367,7 +367,8 @@ def from_filetype(content_entry): - """Convert swh person to serializable person dictionary. + """Convert swh content to serializable dictionary containing keys + 'id', 'encoding', and 'mimetype'. """ return from_swh(content_entry, diff --git a/swh/web/common/service.py b/swh/web/common/service.py --- a/swh/web/common/service.py +++ b/swh/web/common/service.py @@ -311,25 +311,6 @@ return result -def lookup_person(person_id): - """Return information about the person with id person_id. - - Args: - person_id as string - - Returns: - person information as dict. - - Raises: - NotFoundExc if there is no person with the provided id. - - """ - person = _first_element(storage.person_get([int(person_id)])) - if not person: - raise NotFoundExc('Person with id %s not found' % person_id) - return converters.from_person(person) - - def _to_sha1_bin(sha1_hex): _, sha1_git_bin = query.parse_hash_with_algorithms_or_throws( sha1_hex, diff --git a/swh/web/tests/api/test_apidoc.py b/swh/web/tests/api/test_apidoc.py --- a/swh/web/tests/api/test_apidoc.py +++ b/swh/web/tests/api/test_apidoc.py @@ -27,11 +27,7 @@ :resheader Content-Type: this depends on :http:header:`Accept` header of request :>json object author: information about the author of the revision - :>json string author_url: link to :http:get:`/api/1/person/(person_id)/` to get - information about the author of the revision :>json object committer: information about the committer of the revision - :>json string committer_url: link to :http:get:`/api/1/person/(person_id)/` to get - information about the committer of the revision :>json string committer_date: ISO representation of the commit date (in UTC) :>json string date: ISO representation of the revision date (in UTC) :>json string directory: the unique identifier that revision points to @@ -209,21 +205,11 @@ 'doc': 'information about the author of the revision' }, { - 'name': 'author_url', - 'type': 'string', - 'doc': 'link to ``_ to get information about the author of the revision' - }, - { 'name': 'committer', 'type': 'object', 'doc': 'information about the committer of the revision' }, { - 'name': 'committer_url', - 'type': 'string', - 'doc': 'link to ``_ to get information about the committer of the revision' - }, - { 'name': 'committer_date', 'type': 'string', 'doc': 'ISO representation of the commit date (in UTC)' diff --git a/swh/web/tests/api/test_utils.py b/swh/web/tests/api/test_utils.py --- a/swh/web/tests/api/test_utils.py +++ b/swh/web/tests/api/test_utils.py @@ -116,9 +116,6 @@ if view_name == 'api-1-content': id = url_args['q'] return '/api/1/content/%s/' % id - elif view_name == 'api-1-person': - id = url_args['person_id'] - return '/api/1/person/%s/' % id else: raise ValueError( 'This should not happened so fail if it does.') @@ -141,7 +138,6 @@ 'target': '123', 'target_type': 'content', 'target_url': '/api/1/content/sha1_git:123/', - 'author_url': '/api/1/person/100/', 'author': { 'id': 100, 'name': 'author release name', @@ -151,7 +147,6 @@ mock_django_reverse.assert_has_calls([ call('api-1-content', url_args={'q': 'sha1_git:123'}), - call('api-1-person', url_args={'person_id': 100}) ]) @patch('swh.web.api.utils.reverse') @@ -419,8 +414,6 @@ return '/api/revision/' + url_args['sha1_git'] + '/log/' elif view_name == 'api-1-directory': return '/api/directory/' + url_args['sha1_git'] + '/' - elif view_name == 'api-1-person': - return '/api/person/' + url_args['person_id'] + '/' mock_django_reverse.side_effect = reverse_test @@ -439,9 +432,7 @@ 'history_url': '/api/revision/rev-id/log/', 'directory_url': '/api/directory/123/', 'author': {'id': '1'}, - 'author_url': '/api/person/1/', 'committer': {'id': '2'}, - 'committer_url': '/api/person/2/' } # then @@ -450,8 +441,6 @@ mock_django_reverse.assert_has_calls( [call('api-1-revision', url_args={'sha1_git': 'rev-id'}), call('api-1-revision-log', url_args={'sha1_git': 'rev-id'}), - call('api-1-person', url_args={'person_id': '1'}), - call('api-1-person', url_args={'person_id': '2'}), call('api-1-directory', url_args={'sha1_git': '123'})]) @patch('swh.web.api.utils.reverse') diff --git a/swh/web/tests/api/views/test_person.py b/swh/web/tests/api/views/test_person.py deleted file mode 100644 --- a/swh/web/tests/api/views/test_person.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (C) 2015-2019 The Software Heritage developers -# See the AUTHORS file at the top-level directory of this distribution -# License: GNU Affero General Public License version 3, or any later version -# See top-level LICENSE file for more information - -import random - -from hypothesis import given -from rest_framework.test import APITestCase - -from swh.web.common.utils import reverse -from swh.web.tests.strategies import person -from swh.web.tests.testcase import WebTestCase - - -class PersonApiTestCase(WebTestCase, APITestCase): - - @given(person()) - def test_api_person(self, person): - - url = reverse('api-1-person', url_args={'person_id': person}) - - rv = self.client.get(url) - - expected_person = self.person_get(person) - - self.assertEqual(rv.status_code, 200, rv.data) - self.assertEqual(rv['Content-Type'], 'application/json') - self.assertEqual(rv.data, expected_person) - - def test_api_person_not_found(self): - unknown_person_ = random.randint(1000, 10000000) - - url = reverse('api-1-person', url_args={'person_id': unknown_person_}) - - rv = self.client.get(url) - - self.assertEqual(rv.status_code, 404, rv.data) - self.assertEqual(rv['Content-Type'], 'application/json') - self.assertEqual(rv.data, { - 'exception': 'NotFoundExc', - 'reason': 'Person with id %s not found' % unknown_person_}) diff --git a/swh/web/tests/api/views/test_release.py b/swh/web/tests/api/views/test_release.py --- a/swh/web/tests/api/views/test_release.py +++ b/swh/web/tests/api/views/test_release.py @@ -26,13 +26,9 @@ rv = self.client.get(url) expected_release = self.release_get(release) - author_id = expected_release['author']['id'] target_revision = expected_release['target'] - author_url = reverse('api-1-person', - url_args={'person_id': author_id}) target_url = reverse('api-1-revision', url_args={'sha1_git': target_revision}) - expected_release['author_url'] = author_url expected_release['target_url'] = target_url self.assertEqual(rv.status_code, 200, rv.data) @@ -79,10 +75,6 @@ expected_release = self.release_get(new_rel_id) - author_id = expected_release['author']['id'] - author_url = reverse('api-1-person', - url_args={'person_id': author_id}) - if target_type == 'content': url_args = {'q': 'sha1_git:%s' % target} else: @@ -90,7 +82,6 @@ target_url = reverse('api-1-%s' % target_type, url_args=url_args) - expected_release['author_url'] = author_url expected_release['target_url'] = target_url self.assertEqual(rv.status_code, 200, rv.data) diff --git a/swh/web/tests/api/views/test_revision.py b/swh/web/tests/api/views/test_revision.py --- a/swh/web/tests/api/views/test_revision.py +++ b/swh/web/tests/api/views/test_revision.py @@ -522,14 +522,6 @@ {'sha1_git': '666'}, 'some/other/path', url, with_data=False) def _enrich_revision(self, revision): - author_url = reverse( - 'api-1-person', - url_args={'person_id': revision['author']['id']}) - - committer_url = reverse( - 'api-1-person', - url_args={'person_id': revision['committer']['id']}) - directory_url = reverse( 'api-1-directory', url_args={'sha1_git': revision['directory']}) @@ -547,8 +539,6 @@ revision_url = reverse('api-1-revision', url_args={'sha1_git': revision['id']}) - revision['author_url'] = author_url - revision['committer_url'] = committer_url revision['directory_url'] = directory_url revision['history_url'] = history_url revision['url'] = revision_url diff --git a/swh/web/tests/browse/test_utils.py b/swh/web/tests/browse/test_utils.py --- a/swh/web/tests/browse/test_utils.py +++ b/swh/web/tests/browse/test_utils.py @@ -66,16 +66,6 @@ utils.gen_link('https://www.softwareheritage.org/', 'swh'), 'swh') - def test_gen_person_link(self): - person_id = 8221896 - person_name = 'Antoine Lambert' - person_url = reverse('browse-person', - url_args={'person_id': person_id}) - - self.assertEqual(utils.gen_person_link(person_id, person_name, - link_attrs=None), - '%s' % (person_url, person_name)) - def test_gen_revision_link(self): revision_id = '28a0bc4120d38a394499382ba21d6965a67a3703' revision_url = reverse('browse-revision', diff --git a/swh/web/tests/browse/views/test_person.py b/swh/web/tests/browse/views/test_person.py deleted file mode 100644 --- a/swh/web/tests/browse/views/test_person.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (C) 2017-2019 The Software Heritage developers -# See the AUTHORS file at the top-level directory of this distribution -# License: GNU Affero General Public License version 3, or any later version -# See top-level LICENSE file for more information - -from hypothesis import given - -from swh.web.common.utils import reverse -from swh.web.tests.strategies import person, unknown_person -from swh.web.tests.testcase import WebTestCase - - -class SwhBrowsePersonTest(WebTestCase): - - @given(person()) - def test_person_browse(self, person): - test_person_data = self.person_get(person) - - url = reverse('browse-person', url_args={'person_id': person}) - - resp = self.client.get(url) - - self.assertEqual(resp.status_code, 200) - self.assertTemplateUsed('browse/person.html') - self.assertContains(resp, '
%s
' % test_person_data['id']) - self.assertContains(resp, '
%s
' % test_person_data['name']) - self.assertContains(resp, '
%s
' % - (test_person_data['email'], - test_person_data['email'])) - self.assertContains(resp, '
%s <%s>
' % # noqa - (test_person_data['name'], - test_person_data['email'], - test_person_data['email'])) - - @given(unknown_person()) - def test_person_request_error(self, unknown_person): - url = reverse('browse-person', url_args={'person_id': unknown_person}) - resp = self.client.get(url) - self.assertEqual(resp.status_code, 404) - self.assertTemplateUsed('error.html') - self.assertContains(resp, - 'Person with id %s not found' % unknown_person, - status_code=404) diff --git a/swh/web/tests/browse/views/test_release.py b/swh/web/tests/browse/views/test_release.py --- a/swh/web/tests/browse/views/test_release.py +++ b/swh/web/tests/browse/views/test_release.py @@ -63,11 +63,7 @@ release_id = release_data['id'] release_name = release_data['name'] - author_id = release_data['author']['id'] author_name = release_data['author']['name'] - author_url = reverse('browse-person', - url_args={'person_id': author_id}, - query_params=query_params) release_date = release_data['date'] message = release_data['message'] @@ -81,8 +77,7 @@ self.assertEqual(resp.status_code, 200) self.assertTemplateUsed('browse/release.html') - self.assertContains(resp, '%s' % - (author_url, author_name)) + self.assertContains(resp, author_name) self.assertContains(resp, format_utc_iso_date(release_date)) self.assertContains(resp, '
%s
%s' % (message_lines[0] or 'None', diff --git a/swh/web/tests/browse/views/test_revision.py b/swh/web/tests/browse/views/test_revision.py --- a/swh/web/tests/browse/views/test_revision.py +++ b/swh/web/tests/browse/views/test_revision.py @@ -26,17 +26,10 @@ revision_data = self.revision_get(revision) - author_id = revision_data['author']['id'] author_name = revision_data['author']['name'] - committer_id = revision_data['committer']['id'] committer_name = revision_data['committer']['name'] dir_id = revision_data['directory'] - author_url = reverse('browse-person', - url_args={'person_id': author_id}) - committer_url = reverse('browse-person', - url_args={'person_id': committer_id}) - directory_url = reverse('browse-directory', url_args={'sha1_git': dir_id}) @@ -47,10 +40,8 @@ self.assertEqual(resp.status_code, 200) self.assertTemplateUsed('browse/revision.html') - self.assertContains(resp, '%s' % - (author_url, author_name)) - self.assertContains(resp, '%s' % - (committer_url, committer_name)) + self.assertContains(resp, author_name) + self.assertContains(resp, committer_name) self.assertContains(resp, directory_url) self.assertContains(resp, history_url) diff --git a/swh/web/tests/common/test_service.py b/swh/web/tests/common/test_service.py --- a/swh/web/tests/common/test_service.py +++ b/swh/web/tests/common/test_service.py @@ -663,15 +663,6 @@ self.assertEqual(actual_content, expected_content) - @given(revision()) - def test_lookup_person(self, revision): - - rev_data = self.revision_get(revision) - - actual_person = service.lookup_person(rev_data['author']['id']) - - self.assertEqual(actual_person, rev_data['author']) - def test_lookup_directory_bad_checksum(self): with self.assertRaises(BadInputExc): diff --git a/swh/web/tests/testcase.py b/swh/web/tests/testcase.py --- a/swh/web/tests/testcase.py +++ b/swh/web/tests/testcase.py @@ -147,7 +147,3 @@ hash_to_bytes(snapshot_id), branches_from.encode(), branches_count, target_types) return converters.from_snapshot(snp) - - def person_get(self, person_id): - person = next(self.storage.person_get([person_id])) - return converters.from_person(person)