diff --git a/ckanext/privatedatasets/actions.py b/ckanext/privatedatasets/actions.py index ff26762..e839395 100644 --- a/ckanext/privatedatasets/actions.py +++ b/ckanext/privatedatasets/actions.py @@ -17,12 +17,16 @@ # You should have received a copy of the GNU Affero General Public License # along with CKAN Private Dataset Extension. If not, see . -import ckan.plugins as plugins -import ckanext.privatedatasets.constants as constants -import db +from __future__ import absolute_import + import importlib import logging +import ckan.plugins as plugins + +from ckanext.privatedatasets import constants, db + + log = logging.getLogger(__name__) PARSER_CONFIG_PROP = 'ckan.privatedatasets.parser' @@ -54,6 +58,7 @@ def package_acquired(context, request_data): context['method'] = 'grant' return _process_package(context, request_data) + def acquisitions_list(context, data_dict): ''' API to retrieve the list of datasets that have been acquired by a certain user @@ -137,6 +142,7 @@ def revoke_access(context, request_data): context['method'] = 'revoke' return _process_package(context, request_data) + def _process_package(context, request_data): log.info('Notification received: %s' % request_data) @@ -168,7 +174,7 @@ def _process_package(context, request_data): for user_info in result['users_datasets']: for dataset_id in user_info['datasets']: - + try: context_pkg_show = context.copy() context_pkg_show['ignore_auth'] = True diff --git a/ckanext/privatedatasets/auth.py b/ckanext/privatedatasets/auth.py index cb2c5c1..204b999 100644 --- a/ckanext/privatedatasets/auth.py +++ b/ckanext/privatedatasets/auth.py @@ -17,16 +17,15 @@ # You should have received a copy of the GNU Affero General Public License # along with CKAN Private Dataset Extension. If not, see . +from __future__ import absolute_import + +import ckan.authz as authz +from ckan.common import _, request import ckan.lib.helpers as helpers import ckan.logic.auth as logic_auth import ckan.plugins.toolkit as tk -try: - import ckan.authz as authz -except ImportError: - import ckan.new_authz as authz -import db -from ckan.common import _, request +from ckanext.privatedatasets import db @tk.auth_allow_anonymous_access @@ -137,11 +136,13 @@ def package_acquired(context, data_dict): # TODO: Improve security return {'success': True} + def acquisitions_list(context, data_dict): # Users can get only their acquisitions list return {'success': context['user'] == data_dict['user']} + @tk.auth_allow_anonymous_access def revoke_access(context, data_dict): # TODO: Check functionality and improve security(if needed) - return {'success': True} \ No newline at end of file + return {'success': True} diff --git a/ckanext/privatedatasets/converters_validators.py b/ckanext/privatedatasets/converters_validators.py index 83e3547..26ea1c4 100644 --- a/ckanext/privatedatasets/converters_validators.py +++ b/ckanext/privatedatasets/converters_validators.py @@ -17,13 +17,16 @@ # You should have received a copy of the GNU Affero General Public License # along with CKAN Private Dataset Extension. If not, see . -import constants -import db +from __future__ import absolute_import + +from itertools import count import re from ckan.plugins import toolkit from ckan.common import _ -from itertools import count +import six + +from ckanext.privatedatasets import constants, db def private_datasets_metadata_checker(key, data, errors, context): @@ -33,7 +36,7 @@ def private_datasets_metadata_checker(key, data, errors, context): # Avoid missing value # "if not private_val:" is not valid because private_val can be False - if not isinstance(private_val, basestring) and not isinstance(private_val, bool): + if not isinstance(private_val, six.string_types) and not isinstance(private_val, bool): private_val = None # If the private field is not included in the data dict, we must check the current value @@ -57,7 +60,7 @@ def allowed_users_convert(key, data, errors, context): # Get the allowed user list if (constants.ALLOWED_USERS,) in data and isinstance(data[(constants.ALLOWED_USERS,)], list): allowed_users = data[(constants.ALLOWED_USERS,)] - elif (constants.ALLOWED_USERS_STR,) in data and isinstance(data[(constants.ALLOWED_USERS_STR,)], basestring): + elif (constants.ALLOWED_USERS_STR,) in data and isinstance(data[(constants.ALLOWED_USERS_STR,)], six.string_types): allowed_users_str = data[(constants.ALLOWED_USERS_STR,)].strip() allowed_users = [allowed_user for allowed_user in allowed_users_str.split(',') if allowed_user.strip() != ''] else: diff --git a/ckanext/privatedatasets/db.py b/ckanext/privatedatasets/db.py index b1b38f1..b0fa04c 100644 --- a/ckanext/privatedatasets/db.py +++ b/ckanext/privatedatasets/db.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU Affero General Public License # along with CKAN Private Dataset Extension. If not, see . +from __future__ import absolute_import + import sqlalchemy as sa AllowedUser = None @@ -38,7 +40,9 @@ def init_db(model): AllowedUser = _AllowedUser # FIXME: Maybe a default value should not be included... - package_allowed_users_table = sa.Table('package_allowed_users', model.meta.metadata, + package_allowed_users_table = sa.Table( + 'package_allowed_users', + model.meta.metadata, sa.Column('package_id', sa.types.UnicodeText, primary_key=True, default=u''), sa.Column('user_name', sa.types.UnicodeText, primary_key=True, default=u''), ) diff --git a/ckanext/privatedatasets/helpers.py b/ckanext/privatedatasets/helpers.py index 4c371ca..ad2b455 100755 --- a/ckanext/privatedatasets/helpers.py +++ b/ckanext/privatedatasets/helpers.py @@ -17,13 +17,17 @@ # You should have received a copy of the GNU Affero General Public License # along with CKAN Private Dataset Extension. If not, see . -import ckan.model as model -import ckan.plugins.toolkit as tk -import db - -from ckan.common import request +from __future__ import absolute_import import logging + +from ckan.common import request +import ckan.model as model +import ckan.plugins.toolkit as tk + +from ckanext.privatedatasets import db + + log = logging.getLogger(__name__) diff --git a/ckanext/privatedatasets/parsers/fiware.py b/ckanext/privatedatasets/parsers/fiware.py index f5cec78..5ea9894 100644 --- a/ckanext/privatedatasets/parsers/fiware.py +++ b/ckanext/privatedatasets/parsers/fiware.py @@ -17,11 +17,12 @@ # You should have received a copy of the GNU Affero General Public License # along with CKAN Private Dataset Extension. If not, see . -import ckan.plugins.toolkit as tk import re - from urlparse import urlparse + from ckan.common import request +import ckan.plugins.toolkit as tk +import six class FiWareNotificationParser(object): @@ -32,7 +33,7 @@ class FiWareNotificationParser(object): fields = ['customer_name', 'resources'] for field in fields: - if not field in request_data: + if field not in request_data: raise tk.ValidationError({'message': '%s not found in the request' % field}) # Parse the body @@ -40,7 +41,7 @@ class FiWareNotificationParser(object): user_name = request_data['customer_name'] datasets = [] - if not isinstance(user_name, basestring): + if not isinstance(user_name, six.string_types): raise tk.ValidationError({'message': 'Invalid customer_name format'}) if not isinstance(resources, list): @@ -61,4 +62,3 @@ class FiWareNotificationParser(object): raise tk.ValidationError({'message': 'Invalid resource format'}) return {'users_datasets': [{'user': user_name, 'datasets': datasets}]} - \ No newline at end of file diff --git a/ckanext/privatedatasets/plugin.py b/ckanext/privatedatasets/plugin.py index 0ab370e..38ba9a8 100755 --- a/ckanext/privatedatasets/plugin.py +++ b/ckanext/privatedatasets/plugin.py @@ -17,19 +17,14 @@ # You should have received a copy of the GNU Affero General Public License # along with CKAN Private Dataset Extension. If not, see . -import ckan.lib.search as search -import ckan.model as model -import ckan.plugins as p -import ckan.plugins.toolkit as tk +from __future__ import absolute_import +from ckan import model, plugins as p +from ckan.lib import search from ckan.lib.plugins import DefaultPermissionLabels +from ckan.plugins import toolkit as tk -import auth -import actions -import constants -import converters_validators as conv_val -import db -import helpers as helpers +from ckanext.privatedatasets import auth, actions, constants, converters_validators as conv_val, db, helpers HIDDEN_FIELDS = [constants.ALLOWED_USERS, constants.SEARCHABLE] @@ -150,8 +145,6 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm, DefaultPermissio return m - - ###################################################################### ############################## IACTIONS ############################## ###################################################################### @@ -270,7 +263,7 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm, DefaultPermissio def after_search(self, search_results, search_params): for result in search_results['results']: - # Extra fields should not be returned + # Extra fields should not be returned # The original list cannot be modified attrs = list(HIDDEN_FIELDS)