From 16c605aaa36783048becf20c87b2a617d9179d7d Mon Sep 17 00:00:00 2001 From: etj Date: Thu, 24 Sep 2020 18:20:31 +0200 Subject: [PATCH] #118 reports improvements --- ckanext/faoclh/plugin.py | 31 +++++++++ ckanext/faoclh/templates/header.html | 9 +++ .../templates/report/broken_links_report.html | 2 +- ckanext/faoclh/templates/report/view.html | 69 +++++++++++++++++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 ckanext/faoclh/templates/report/view.html diff --git a/ckanext/faoclh/plugin.py b/ckanext/faoclh/plugin.py index 645f02e..205ca36 100644 --- a/ckanext/faoclh/plugin.py +++ b/ckanext/faoclh/plugin.py @@ -50,6 +50,7 @@ class FAOCLHGUIPlugin(plugins.SingletonPlugin, plugins.implements(plugins.ITranslation) plugins.implements(plugins.ITemplateHelpers) plugins.implements(plugins.IRoutes) + plugins.implements(plugins.IAuthFunctions) # IPackageController def before_search(self, search_params): @@ -263,6 +264,36 @@ def register_reports(self): log.info('registering reports') return all_reports() + # ------------- IAuthFunctions --------------- # + def get_auth_functions(self): + out = {} + for k in ('report_list', 'report_show', + 'report_data_get', 'report_key_get', + 'report_refresh',): + out[k] = check_if_super + + # monkeypatch report plugin to avoid auth functions conflict + # in authz + from ckanext.report.plugin import ReportPlugin + def fake_get_auth_functions(s): + return {} + + ReportPlugin.get_auth_functions = fake_get_auth_functions + + return out + +def check_if_super(context, data_dict=None): + out = {'success': False, + 'msg': ''} + user = context.get('auth_user_obj') + if not user: + out['msg'] = 'User must be logged in' + return out + if not (user.state == 'active' and user.sysadmin): + out['msg'] = 'Only superuser can use reports' + return out + out['success'] = True + return out def fao_voc(voc_name): try: diff --git a/ckanext/faoclh/templates/header.html b/ckanext/faoclh/templates/header.html index 84777d2..e4fb953 100644 --- a/ckanext/faoclh/templates/header.html +++ b/ckanext/faoclh/templates/header.html @@ -39,6 +39,15 @@

{{ new_activities }} + + {% if c.userobj.sysadmin %} +
  • + + + +
  • + {% endif %} +
  • diff --git a/ckanext/faoclh/templates/report/broken_links_report.html b/ckanext/faoclh/templates/report/broken_links_report.html index ab87590..b971d8c 100644 --- a/ckanext/faoclh/templates/report/broken_links_report.html +++ b/ckanext/faoclh/templates/report/broken_links_report.html @@ -52,7 +52,7 @@ {% set dataset_title = h.gsreport_get_pkg_title(row['dataset_id'], h.lang()) %} {{ dataset_title or row.dataset_title }} - {{ row.resource_name|truncate(50) }} + {{ row.resource_name or '' |truncate(50) }} {{ row.resource_format }} {{ row.res_url or row.resource_url}} {{ _(row.error) }} diff --git a/ckanext/faoclh/templates/report/view.html b/ckanext/faoclh/templates/report/view.html new file mode 100644 index 0000000..2cc16a2 --- /dev/null +++ b/ckanext/faoclh/templates/report/view.html @@ -0,0 +1,69 @@ +{% extends "page.html" %} + +{% block title %}{{ report.title }} - {{ _('Reports') }} - {{ super() }}{% endblock %} + +{% block breadcrumb_content %} + {{ h.build_nav('reports', _('Reports')) }} + {{ h.build_nav('report-org' if '/organization' in request.environ.get('PATH_INFO', '') else 'report', report.title, report_name=report_name) }} +{% endblock%} + +{% block primary_content_inner %} +

    {{ report.title }}

    +

    {{ report.description }}

    +

    + {{ _('Generated') }}: {{ h.report__render_datetime(report_date, '%d/%m/%Y %H:%M') }} +

    + + {% if options %} +

    {{ _('Options') }}

    +
    + {% for key, value in options.items() %} + {% if key in options_html %} + {{ options_html[key]|safe }} + {% else %} + {{ key }}: {{ value }} + + {% endif %} +
    + {% endfor %} +
    + {% endif %} + + {% if are_some_results %} +
    + {{ _('Download') }}: + CSV + JSON +
    + {% endif %} +

    {{ _('Results') }}

    + {% if not are_some_results %} +

    {{ _('No results found.') }}

    + {% else %} +
    + {% snippet report_template, table=data['table'], data=data, report_name=report_name, options=options %} +
    + {% endif %} + +{% endblock%} + +{% block scripts %} + {{ super() }} + + + +{% endblock%} +