Skip to content

Commit

Permalink
Merge pull request #477 from jbernal0019/master
Browse files Browse the repository at this point in the history
Make CUBE's homepage browsable by unauthenticated users
  • Loading branch information
jbernal0019 authored Jan 4, 2023
2 parents 8bce851 + 2bd52d1 commit 59d6b98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions chris_backend/feeds/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ def test_feed_list_success_chris_user_lists_all_users_feeds(self):
self.assertContains(response, "Feed1")
self.assertContains(response, "Feed2")

def test_feed_list_failure_unauthenticated(self):
def test_feed_list_success_unauthenticated(self):
response = self.client.get(self.list_url)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertNotContains(response, "Feed1")
self.assertNotContains(response, "Feed2")

def test_feed_list_from_other_users_not_listed(self):
self.client.login(username=self.other_username, password=self.other_password)
Expand Down
18 changes: 12 additions & 6 deletions chris_backend/feeds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,19 @@ class TaggingDetail(generics.RetrieveDestroyAPIView):

class FeedList(generics.ListAPIView):
"""
A view for the collection of feeds.
A view for the collection of feeds. This is also the API's "homepage".
"""
http_method_names = ['get']
serializer_class = FeedSerializer
permission_classes = (permissions.IsAuthenticated,)

def get_queryset(self):
"""
Overriden to return a custom queryset that is only comprised by the feeds
owned by the currently authenticated user.
"""
user = self.request.user
if not user.is_authenticated:
return []
# if the user is chris then return all the feeds in the system
if user.username == 'chris':
return Feed.objects.all()
Expand All @@ -287,14 +288,14 @@ def list(self, request, *args, **kwargs):
Overriden to append document-level link relations.
"""
response = super(FeedList, self).list(request, *args, **kwargs)

# append query list
query_list = [reverse('feed-list-query-search', request=request)]
response = services.append_collection_querylist(response, query_list)

# append document-level link relations
user = self.request.user
links = {'chrisinstance': reverse('chrisinstance-detail', request=request,
kwargs={"pk": 1}),
'admin': reverse('admin-plugin-list', request=request),
'files': reverse('allplugininstancefile-list', request=request),
'compute_resources': reverse('computeresource-list', request=request),
'plugin_metas': reverse('pluginmeta-list', request=request),
Expand All @@ -308,8 +309,13 @@ def list(self, request, *args, **kwargs):
'uploadedfiles': reverse('uploadedfile-list', request=request),
'pacsfiles': reverse('pacsfile-list', request=request),
'servicefiles': reverse('servicefile-list', request=request),
'filebrowser': reverse('filebrowserpath-list', request=request),
'user': reverse('user-detail', request=request, kwargs={"pk": user.id})}
'filebrowser': reverse('filebrowserpath-list', request=request)}

user = self.request.user
if user.is_authenticated:
links['user'] = reverse('user-detail', request=request, kwargs={"pk": user.id})
if user.is_staff:
links['admin'] = reverse('admin-plugin-list', request=request)
return services.append_collection_links(response, links)


Expand Down

0 comments on commit 59d6b98

Please sign in to comment.