Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error when user object is not found. #3312

Merged
merged 3 commits into from
Apr 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions refinery/user_files_manager/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from django.contrib.auth.models import User
from django.http import Http404
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, replace the line above with:

from guardian.compat import get_user_model

then:

User = get_user_model()

as described here: https://django-guardian.readthedocs.io/en/latest/configuration.html


from guardian.compat import get_user_model
from guardian.shortcuts import get_objects_for_user

from core.utils import accept_global_perms
from data_set_manager.models import Assay, Study
from data_set_manager.utils import generate_solr_params

User = get_user_model()


def generate_solr_params_for_user(params, user_id):
"""Creates the encoded solr params limiting results to one user.
Expand All @@ -23,11 +26,13 @@ def generate_solr_params_for_user(params, user_id):
sort - Ordering include field name, whitespace, & asc or desc.
fq - filter query
"""

try:
user = User.objects.get(id=user_id)
except User.DoesNotExist:
user = User.get_anonymous()
except:
try: # catches when guardian anon user is not created
user = User.get_anonymous()
except User.DoesNotExist:
raise Http404

# will update to allow users to view read_meta datasets then we can
# update to use get_resources_for_user method in core/utils
Expand Down