Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1732 | raise 404 if owner is provided in re…
Browse files Browse the repository at this point in the history
…quest URL but not found
  • Loading branch information
snyaggarwal committed Jan 23, 2024
1 parent 995fb8f commit 791f232
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/url_registry/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,11 @@ def test_post(self, lookup_mock):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, RepoListSerializer(source).data)
lookup_mock.assert_called_with('https://foo.com', source.organization)

response = self.client.post(
'/orgs/Foo/url-registry/$lookup/',
{'url': 'https://foo.com'},
HTTP_AUTHORIZATION=f'Token {token}'
)

self.assertEqual(response.status_code, 404)
3 changes: 3 additions & 0 deletions core/url_registry/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def set_parent_resource(self):
self.parent_resource = UserProfile.objects.filter(username=user).first()
self.parent_resource_type = 'user'

if (org or user) and not self.parent_resource:
raise Http404()

self.kwargs['parent_resource'] = self.parent_resource
self.kwargs['parent_resource_type'] = self.parent_resource_type

Expand Down

0 comments on commit 791f232

Please sign in to comment.