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

Use projects from whitelist if none are passed to the API #30

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions esgf_wget/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ def generate_wget_script(request):
'{project}, is not allowed to be accessed by this site. ' \
'Please redo your query with unrestricted data only, ' \
'and request {project} data from another site.'
projects_lower = [x.lower() for x in allowed_projects]
# Check project parameter
if param in [FIELD_PROJECT]:
for v in split_value_list:
if v.lower() not in projects_lower:
if v not in allowed_projects:
return HttpResponseBadRequest(msg.format(project=v))
# Check ID parameters
projects_lower = [x.lower() for x in allowed_projects]
if param in ID_FIELDS:
for v in split_value_list:
p = v.split('.')[0]
Expand All @@ -228,6 +228,15 @@ def generate_wget_script(request):
fq = '{}:({})'.format(param, ' || '.join(split_value_list))
file_query.append(fq)

# If the projects were not passed and the allowed projects list exists,
# then use the allowed projects as the project query
if not url_params.get(FIELD_PROJECT) and allowed_projects:
if len(allowed_projects) == 1:
fq = '{}:{}'.format(FIELD_PROJECT, allowed_projects[0])
else:
fq = '{}:({})'.format(FIELD_PROJECT, ' || '.join(allowed_projects))
file_query.append(fq)

# Get facets for the file name, URL, checksum
file_attribute_set = set(['title', 'url', 'checksum_type', 'checksum'])

Expand Down