From 18e39cc83ea5e601fff7ea4ddcd0f9df7a88ec7d Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 12 Jun 2024 18:23:16 +0000 Subject: [PATCH 01/27] feat(views): activity view; - Activity view for recombinant datasets, uses activity plugin view method. --- .../templates/recombinant/resource_edit.html | 2 +- ckanext/recombinant/views.py | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/ckanext/recombinant/templates/recombinant/resource_edit.html b/ckanext/recombinant/templates/recombinant/resource_edit.html index ddfdf82..d7dbba9 100644 --- a/ckanext/recombinant/templates/recombinant/resource_edit.html +++ b/ckanext/recombinant/templates/recombinant/resource_edit.html @@ -84,7 +84,7 @@ {{ _("Activity Stream") }} {% block activity_stream %} - + {{ _('Activity Stream') }} {% endblock %} diff --git a/ckanext/recombinant/views.py b/ckanext/recombinant/views.py index dcfc245..f076023 100644 --- a/ckanext/recombinant/views.py +++ b/ckanext/recombinant/views.py @@ -22,6 +22,7 @@ from ckan.authz import has_user_permission_for_group_or_org from ckan.views.dataset import _get_package_type +from ckanext.activity.views import package_activity from ckanext.recombinant.errors import RecombinantException, BadExcelData from ckanext.recombinant.read_excel import read_excel, get_records @@ -610,3 +611,40 @@ def _process_upload_file(lc, dataset, upload_file, geno, dry_run): pgerror)) if not total_records: raise BadExcelData(_("The template uploaded is empty")) + + +@recombinant.route('/recombinant///activity', methods=['GET']) +def activity(resource_name, owner_org): + if not g.user: + return h.redirect_to('user.login') + + org_object = Group.get(owner_org) + if org_object.name != owner_org: + return h.redirect_to( + 'recombinant.preview_table', + resource_name=resource_name, + owner_org=org_object.name, + ) + + lc = ckanapi.LocalCKAN(username=g.user, context={'ignore_auth':True}) + try: + chromo = get_chromo(resource_name) + except RecombinantException: + abort(404, _('Recombinant resource_name not found')) + + try: + dataset = lc.action.recombinant_show( + dataset_type=chromo['dataset_type'], owner_org=owner_org) + except ckanapi.NotFound: + dataset = None + + if dataset: + for r in dataset['resources']: + if r['name'] == resource_name: + break + else: + abort(404, _('Resource not found')) + else: + abort(404, _('Dataset not found')) + + return package_activity(id=dataset.get('id')) From ee7c5f338ab358e426b7c5e3979a26f68705ca60 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 12 Jun 2024 18:38:56 +0000 Subject: [PATCH 02/27] revert(views): simplify activity; - Just link to the new activity route. --- .../templates/recombinant/resource_edit.html | 2 +- ckanext/recombinant/views.py | 37 ------------------- 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/ckanext/recombinant/templates/recombinant/resource_edit.html b/ckanext/recombinant/templates/recombinant/resource_edit.html index d7dbba9..a0c425d 100644 --- a/ckanext/recombinant/templates/recombinant/resource_edit.html +++ b/ckanext/recombinant/templates/recombinant/resource_edit.html @@ -84,7 +84,7 @@ {{ _("Activity Stream") }} {% block activity_stream %} - + {{ _('Activity Stream') }} {% endblock %} diff --git a/ckanext/recombinant/views.py b/ckanext/recombinant/views.py index f076023..299dc56 100644 --- a/ckanext/recombinant/views.py +++ b/ckanext/recombinant/views.py @@ -611,40 +611,3 @@ def _process_upload_file(lc, dataset, upload_file, geno, dry_run): pgerror)) if not total_records: raise BadExcelData(_("The template uploaded is empty")) - - -@recombinant.route('/recombinant///activity', methods=['GET']) -def activity(resource_name, owner_org): - if not g.user: - return h.redirect_to('user.login') - - org_object = Group.get(owner_org) - if org_object.name != owner_org: - return h.redirect_to( - 'recombinant.preview_table', - resource_name=resource_name, - owner_org=org_object.name, - ) - - lc = ckanapi.LocalCKAN(username=g.user, context={'ignore_auth':True}) - try: - chromo = get_chromo(resource_name) - except RecombinantException: - abort(404, _('Recombinant resource_name not found')) - - try: - dataset = lc.action.recombinant_show( - dataset_type=chromo['dataset_type'], owner_org=owner_org) - except ckanapi.NotFound: - dataset = None - - if dataset: - for r in dataset['resources']: - if r['name'] == resource_name: - break - else: - abort(404, _('Resource not found')) - else: - abort(404, _('Dataset not found')) - - return package_activity(id=dataset.get('id')) From 78382df71124800413eedee88e745d9ae39aa0a4 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 12 Jun 2024 21:18:02 +0000 Subject: [PATCH 03/27] feat(templates): 2.10 thangs; - Activity and Dashboard template fixes. --- .../templates/snippets/{activity_stream.html => stream.html} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ckanext/recombinant/templates/snippets/{activity_stream.html => stream.html} (100%) diff --git a/ckanext/recombinant/templates/snippets/activity_stream.html b/ckanext/recombinant/templates/snippets/stream.html similarity index 100% rename from ckanext/recombinant/templates/snippets/activity_stream.html rename to ckanext/recombinant/templates/snippets/stream.html From b5007398cc573aa65728b189b5f52f57f7faea81 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Thu, 13 Jun 2024 18:13:05 +0000 Subject: [PATCH 04/27] feat(templates): csrf input; - Added `csrf_input` to all forms. --- ckanext/recombinant/templates/recombinant/confirm_delete.html | 1 + ckanext/recombinant/templates/recombinant/resource_edit.html | 2 ++ ckanext/recombinant/templates/recombinant/snippets/delete.html | 2 +- .../recombinant/templates/recombinant/snippets/xls_base.html | 1 + .../templates/recombinant/snippets/xls_download.html | 1 + .../recombinant/templates/recombinant/snippets/xls_upload.html | 1 + 6 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ckanext/recombinant/templates/recombinant/confirm_delete.html b/ckanext/recombinant/templates/recombinant/confirm_delete.html index 52757bb..3e08668 100644 --- a/ckanext/recombinant/templates/recombinant/confirm_delete.html +++ b/ckanext/recombinant/templates/recombinant/confirm_delete.html @@ -10,6 +10,7 @@ num).format(num=num) }}

+ {{ h.csrf_input() }} diff --git a/ckanext/recombinant/templates/recombinant/resource_edit.html b/ckanext/recombinant/templates/recombinant/resource_edit.html index a0c425d..804ad5b 100644 --- a/ckanext/recombinant/templates/recombinant/resource_edit.html +++ b/ckanext/recombinant/templates/recombinant/resource_edit.html @@ -104,6 +104,7 @@

{{_("Error loading your records")}}

{% if g.userobj.sysadmin %} {# only let sysadmins refresh the recombinant record via UI #} + {{ h.csrf_input() }}
{% endif %} @@ -123,6 +124,7 @@

{{_("Create and update records")}}

{{_("No records have been created for this organization")}}

+ {{ h.csrf_input() }}
{{ self.notices() }} diff --git a/ckanext/recombinant/templates/recombinant/snippets/delete.html b/ckanext/recombinant/templates/recombinant/snippets/delete.html index b87778a..858b1e2 100644 --- a/ckanext/recombinant/templates/recombinant/snippets/delete.html +++ b/ckanext/recombinant/templates/recombinant/snippets/delete.html @@ -3,7 +3,7 @@

{{_('Delete existing records')}}

- + {{ h.csrf_input() }}