Skip to content

Commit

Permalink
Merge branch 'uat'
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCalvert committed May 30, 2023
2 parents 366d337 + 25b21cf commit 19655f4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
36 changes: 12 additions & 24 deletions ckanext/clone_dataset/blueprint.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import ckan.logic as logic
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
import logging
import datetime

from pprint import pformat
from flask import Blueprint
from ckan.plugins.toolkit import get_action
from ckanext.clone_dataset.helpers import get_incremental_package_name
from ckanext.clone_dataset.interfaces import IClone

clean_dict = logic.clean_dict
h = toolkit.h
log = logging.getLogger(__name__)
parse_params = logic.parse_params
h = toolkit.h
request = toolkit.request
tuplize_dict = logic.tuplize_dict
NotAuthorized = toolkit.NotAuthorized
get_action = toolkit.get_action
check_access = toolkit.check_access

clone_dataset = Blueprint('clone_dataset', __name__, url_prefix=u'/ckan-admin')
clone_dataset = Blueprint('clone_dataset', __name__)


def clone(id):
# Get current dataset.
try:
# Need to set the user info in the context for check_access
context = {'user': toolkit.g.user, 'userobj': toolkit.g.userobj}
context = {'user': toolkit.g.user, 'auth_user_obj': toolkit.g.userobj}
dataset_dict = get_action('package_show')(context.copy(), {'id': id})
# Check the user has permission to clone the dataset
toolkit.check_access('package_update', context, {'id': id})

dataset_dict = get_action('package_show')({}, {'id': id})
check_access('package_create', context.copy(), dataset_dict)
except NotAuthorized as e:
log.error(str(e))
h.flash_error(str(e))
Expand All @@ -49,18 +46,12 @@ def clone(id):

dataset_dict.pop('id')

if 'identifiers' in dataset_dict:
dataset_dict['identifiers'] = None

if 'revision_id' in dataset_dict:
dataset_dict.pop('revision_id')

if 'revision_timestamp' in dataset_dict:
dataset_dict.pop('revision_timestamp')

if 'metadata_review_date' in dataset_dict:
dataset_dict.pop('metadata_review_date')

# Drop resources.
if 'resources' in dataset_dict:
dataset_dict.pop('resources')
Expand All @@ -70,14 +61,11 @@ def clone(id):
dataset_dict.pop('relationships_as_object')
if 'relationships_as_subject' in dataset_dict:
dataset_dict.pop('relationships_as_subject')
# Also drop any specific fields that may contain references that trigger relationship creation
if 'series_or_collection' in dataset_dict:
dataset_dict.pop('series_or_collection')
if 'related_resources' in dataset_dict:
dataset_dict.pop('related_resources')

try:
get_action('package_create')({}, dataset_dict)
for plugin in plugins.PluginImplementations(IClone):
plugin.clone_modify_dataset(context, dataset_dict)
get_action('package_create')(context, dataset_dict)
h.flash_success('Dataset %s is created.' % dataset_dict['title'])
return h.redirect_to('/dataset')
except Exception as e:
Expand Down
19 changes: 19 additions & 0 deletions ckanext/clone_dataset/interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

from ckan.plugins.interfaces import Interface


class IClone(Interface):
u'''
This interface allows plugins to hook into the Clone workflow
'''
def clone_modify_dataset(self, context, dataset_dict):
u'''
Allow extensions to modify the dataset dictionary before the new cloned dataset is created
:param context: The context object of the current request, this
includes for example access to the ``model`` and the ``user``.
:type context: dictionary
:param dataset_dict: Dataset dictionary from source dataset via package_show action that can be modified before it is created via the package_create action.
:type resource: dictionary
'''
pass
2 changes: 1 addition & 1 deletion ckanext/clone_dataset/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _check_group_auth(context, data_dict):
groups = groups - set(pkg_groups)

for group in groups:
# QDES Modification.
# Modification.
# Only check user permission if group is not an organisation and is not coming from clone_dataset
# When we a cloning a dataset we need to ignore group (categories)
# Any user can add their organisation datasets to a category
Expand Down
2 changes: 1 addition & 1 deletion ckanext/clone_dataset/templates/snippets/package_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
{% asset 'clone_dataset/clone-dataset' %}
{{ super() }}
{% if h.check_access('package_update', {'id':package.id }) %}
{% if h.check_access('package_create', {'id':package.id, 'type': package.type }) %}
<div class="clone-dataset" style="display: none">
<a href="{{ h.url_for('clone_dataset.clone', id=package.id) }}" data-module="confirm-action" data-module-content="Are you sure you want to clone this dataset?" class="btn btn-sm btn-primary">Clone</a>
</div>
Expand Down

0 comments on commit 19655f4

Please sign in to comment.