diff --git a/.docker/test.ini b/.docker/test.ini index 0011ddc..04da9ec 100644 --- a/.docker/test.ini +++ b/.docker/test.ini @@ -86,6 +86,7 @@ ckan.auth.create_user_via_api = false ckan.auth.create_user_via_web = true ckan.auth.roles_that_cascade_to_sub_groups = admin ckan.auth.public_user_details = True +ckan.auth.reveal_private_datasets = True ## Plugins Settings diff --git a/ckanext/qgov/common/plugin.py b/ckanext/qgov/common/plugin.py index 2e9dc86..455cd9f 100644 --- a/ckanext/qgov/common/plugin.py +++ b/ckanext/qgov/common/plugin.py @@ -22,9 +22,6 @@ from .user_creation import validators as user_creation_validators from .user_creation.logic.actions import create as user_creation_create_actions -# workaround for https://github.com/ckan/ckan/issues/6678 -from ckan.views import dataset as dataset_view, resource # noqa: F401 - LOG = getLogger(__name__) IP_ADDRESS = re.compile(r'^({0}[.]){{3}}{0}$'.format(r'[0-9]{1,3}')) @@ -179,9 +176,8 @@ def get_blueprint(self): user to the `came_from` URL if they are logged in. :return: """ - from .views import user, dataset, assets + from .views import user, assets blueprints = user.get_blueprints() - blueprints.extend(dataset.get_blueprints()) blueprints.extend(assets.get_blueprints()) return blueprints diff --git a/ckanext/qgov/common/views/dataset.py b/ckanext/qgov/common/views/dataset.py deleted file mode 100644 index db4d7eb..0000000 --- a/ckanext/qgov/common/views/dataset.py +++ /dev/null @@ -1,91 +0,0 @@ -# encoding: utf-8 - -import logging - -from flask import Blueprint - -from ckan import model -from ckan.plugins.toolkit import check_ckan_version, g, get_action, \ - redirect_to, url_for, ObjectNotFound, NotAuthorized -from ckan.views import dataset, resource - -from ckanext.qgov.common.helpers import make_uncached_response - -LOG = logging.getLogger(__name__) - -_dataset = Blueprint( - u'qgov_dataset', - __name__, - url_prefix=u'/dataset/', - url_defaults={u'package_type': u'dataset'} -) - - -def _get_context(): - return {'model': model, 'session': model.Session, - 'user': g.user, 'for_view': True, - 'auth_user_obj': g.userobj} - - -def _get_errors_summary(errors): - return ', '.join([error for key, error in errors.items()]) - - -def _is_dataset_public(id): - try: - get_action('package_show')(_get_context(), {'id': id}) - return True - except ObjectNotFound: - LOG.debug("Package %s does not exist", id) - return True - except NotAuthorized: - LOG.debug("Package %s is not visible", id) - return False - - -def dataset_read(package_type, id): - """ - Override the default CKAN behaviour for private Dataset visibility. - Instead of displaying "404 Dataset not found" message, - give unauthenticated users a chance to log in. - :param id: Package id/name - :return: - """ - if not g.user and not _is_dataset_public(id): - return make_uncached_response(redirect_to( - url_for('user.login', came_from=url_for('dataset.read', id=id)) - )) - - return dataset.read(package_type, id) - - -def resource_read(package_type, id, resource_id): - """ - Override the default CKAN behaviour for private Dataset Resource visibility. - Instead of displaying "404 Dataset not found" message, - give unauthenticated users a chance to log in. - :param id: Package id/name - :param resource_id: Resource id - :return: - """ - if not g.user and not _is_dataset_public(id): - return make_uncached_response(redirect_to( - url_for('user.login', - came_from=url_for('resource.read', id=id, resource_id=resource_id)) - )) - - return resource.read(package_type, id, resource_id) - - -# Any core routes that would match an pattern, such as 'new', -# must be repeated here, or else they will be overridden. -_dataset.add_url_rule(u'new', view_func=dataset.CreateView.as_view('new')) -if not check_ckan_version('2.10'): - _dataset.add_url_rule(u'changes_multiple', 'changes_multiple', view_func=dataset.changes_multiple) -_dataset.add_url_rule(u'', view_func=dataset_read) -_dataset.add_url_rule(u'/resource/new', view_func=resource.CreateView.as_view('new_resource')) -_dataset.add_url_rule(u'/resource/', view_func=resource_read) - - -def get_blueprints(): - return [_dataset]