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

Develop to master #11

Merged
merged 2 commits into from
Jul 29, 2022
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
26 changes: 13 additions & 13 deletions ckanext/report/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def report_index():
try:
reports = t.get_action('report_list')({}, {})
except t.NotAuthorized:
t.abort(401)
return t.abort(401)

return t.render('report/index.html', extra_vars={'reports': reports})

Expand All @@ -35,26 +35,26 @@ def report_view(report_name, organization=None, refresh=False):
try:
report = t.get_action('report_show')({}, {'id': report_name})
except t.NotAuthorized:
t.abort(401)
return t.abort(401)
except t.ObjectNotFound:
t.abort(404)
return t.abort(404)
except Exception as e:
log.error("Failed to get report: %s", e)
raise

# ensure correct url is being used
if 'organization' in _get_routing_rule()\
and 'organization' not in report['option_defaults']:
t.redirect_to(helpers.relative_url_for(organization=None))
return t.redirect_to(helpers.relative_url_for(organization=None))
elif 'organization' not in _get_routing_rule()\
and 'organization' in report['option_defaults']\
and report['option_defaults']['organization']:
org = report['option_defaults']['organization']
t.redirect_to(helpers.relative_url_for(organization=org))
return t.redirect_to(helpers.relative_url_for(organization=org))
if 'organization' in t.request.params:
# organization should only be in the url - let the param overwrite
# the url.
t.redirect_to(helpers.relative_url_for())
return t.redirect_to(helpers.relative_url_for())

# options
options = Report.add_defaults_to_options(t.request.params, report['option_defaults'])
Expand Down Expand Up @@ -100,21 +100,21 @@ def report_view(report_name, organization=None, refresh=False):
try:
t.get_action('report_refresh')({}, {'id': report_name, 'options': options})
except t.NotAuthorized:
t.abort(401)
return t.abort(401)
# Don't want the refresh=1 in the url once it is done
t.redirect_to(helpers.relative_url_for(refresh=None))
return t.redirect_to(helpers.relative_url_for(refresh=None))

# Check for any options not allowed by the report
for key in options:
if key not in report['option_defaults']:
t.abort(400, 'Option not allowed by report: %s' % key)
return t.abort(400, 'Option not allowed by report: %s' % key)

try:
data, report_date = t.get_action('report_data_get')({}, {'id': report_name, 'options': options})
except t.ObjectNotFound:
t.abort(404)
return t.abort(404)
except t.NotAuthorized:
t.abort(401)
return t.abort(401)

if format and format != 'html':
ensure_data_is_dicts(data)
Expand All @@ -123,7 +123,7 @@ def report_view(report_name, organization=None, refresh=False):
try:
key = t.get_action('report_key_get')({}, {'id': report_name, 'options': options})
except t.NotAuthorized:
t.abort(401)
return t.abort(401)
filename = 'report_%s.csv' % key
response_headers = {
'Content-Type': 'application/csv',
Expand All @@ -134,7 +134,7 @@ def report_view(report_name, organization=None, refresh=False):
data['generated_at'] = report_date
return json.dumps(data), {'Content-Type': 'application/json'}
else:
t.abort(400, 'Format not known - try html, json or csv')
return t.abort(400, 'Format not known - try html, json or csv')

are_some_results = bool(data['table'] if 'table' in data
else data)
Expand Down