Fix some basic pep8 problems

This commit is contained in:
Álvaro Arranz 2018-07-12 19:32:56 +02:00
parent 1030939052
commit ce4ec44f1b
No known key found for this signature in database
GPG Key ID: A9BA9AAE8CF561AB
7 changed files with 51 additions and 40 deletions

View File

@ -17,12 +17,16 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>. # along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>.
import ckan.plugins as plugins from __future__ import absolute_import
import ckanext.privatedatasets.constants as constants
import db
import importlib import importlib
import logging import logging
import ckan.plugins as plugins
from ckanext.privatedatasets import constants, db
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
PARSER_CONFIG_PROP = 'ckan.privatedatasets.parser' PARSER_CONFIG_PROP = 'ckan.privatedatasets.parser'
@ -54,6 +58,7 @@ def package_acquired(context, request_data):
context['method'] = 'grant' context['method'] = 'grant'
return _process_package(context, request_data) return _process_package(context, request_data)
def acquisitions_list(context, data_dict): def acquisitions_list(context, data_dict):
''' '''
API to retrieve the list of datasets that have been acquired by a certain user 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' context['method'] = 'revoke'
return _process_package(context, request_data) return _process_package(context, request_data)
def _process_package(context, request_data): def _process_package(context, request_data):
log.info('Notification received: %s' % 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 user_info in result['users_datasets']:
for dataset_id in user_info['datasets']: for dataset_id in user_info['datasets']:
try: try:
context_pkg_show = context.copy() context_pkg_show = context.copy()
context_pkg_show['ignore_auth'] = True context_pkg_show['ignore_auth'] = True

View File

@ -17,16 +17,15 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>. # along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import ckan.authz as authz
from ckan.common import _, request
import ckan.lib.helpers as helpers import ckan.lib.helpers as helpers
import ckan.logic.auth as logic_auth import ckan.logic.auth as logic_auth
import ckan.plugins.toolkit as tk 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 @tk.auth_allow_anonymous_access
@ -137,11 +136,13 @@ def package_acquired(context, data_dict):
# TODO: Improve security # TODO: Improve security
return {'success': True} return {'success': True}
def acquisitions_list(context, data_dict): def acquisitions_list(context, data_dict):
# Users can get only their acquisitions list # Users can get only their acquisitions list
return {'success': context['user'] == data_dict['user']} return {'success': context['user'] == data_dict['user']}
@tk.auth_allow_anonymous_access @tk.auth_allow_anonymous_access
def revoke_access(context, data_dict): def revoke_access(context, data_dict):
# TODO: Check functionality and improve security(if needed) # TODO: Check functionality and improve security(if needed)
return {'success': True} return {'success': True}

View File

@ -17,13 +17,16 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>. # along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>.
import constants from __future__ import absolute_import
import db
from itertools import count
import re import re
from ckan.plugins import toolkit from ckan.plugins import toolkit
from ckan.common import _ 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): 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 # Avoid missing value
# "if not private_val:" is not valid because private_val can be False # "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 private_val = None
# If the private field is not included in the data dict, we must check the current value # 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 # Get the allowed user list
if (constants.ALLOWED_USERS,) in data and isinstance(data[(constants.ALLOWED_USERS,)], list): if (constants.ALLOWED_USERS,) in data and isinstance(data[(constants.ALLOWED_USERS,)], list):
allowed_users = data[(constants.ALLOWED_USERS,)] 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_str = data[(constants.ALLOWED_USERS_STR,)].strip()
allowed_users = [allowed_user for allowed_user in allowed_users_str.split(',') if allowed_user.strip() != ''] allowed_users = [allowed_user for allowed_user in allowed_users_str.split(',') if allowed_user.strip() != '']
else: else:

View File

@ -17,6 +17,8 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>. # along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import sqlalchemy as sa import sqlalchemy as sa
AllowedUser = None AllowedUser = None
@ -38,7 +40,9 @@ def init_db(model):
AllowedUser = _AllowedUser AllowedUser = _AllowedUser
# FIXME: Maybe a default value should not be included... # 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('package_id', sa.types.UnicodeText, primary_key=True, default=u''),
sa.Column('user_name', sa.types.UnicodeText, primary_key=True, default=u''), sa.Column('user_name', sa.types.UnicodeText, primary_key=True, default=u''),
) )

View File

@ -17,13 +17,17 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>. # along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>.
import ckan.model as model from __future__ import absolute_import
import ckan.plugins.toolkit as tk
import db
from ckan.common import request
import logging 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__) log = logging.getLogger(__name__)

View File

@ -17,11 +17,12 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>. # along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>.
import ckan.plugins.toolkit as tk
import re import re
from urlparse import urlparse from urlparse import urlparse
from ckan.common import request from ckan.common import request
import ckan.plugins.toolkit as tk
import six
class FiWareNotificationParser(object): class FiWareNotificationParser(object):
@ -32,7 +33,7 @@ class FiWareNotificationParser(object):
fields = ['customer_name', 'resources'] fields = ['customer_name', 'resources']
for field in fields: 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}) raise tk.ValidationError({'message': '%s not found in the request' % field})
# Parse the body # Parse the body
@ -40,7 +41,7 @@ class FiWareNotificationParser(object):
user_name = request_data['customer_name'] user_name = request_data['customer_name']
datasets = [] datasets = []
if not isinstance(user_name, basestring): if not isinstance(user_name, six.string_types):
raise tk.ValidationError({'message': 'Invalid customer_name format'}) raise tk.ValidationError({'message': 'Invalid customer_name format'})
if not isinstance(resources, list): if not isinstance(resources, list):
@ -61,4 +62,3 @@ class FiWareNotificationParser(object):
raise tk.ValidationError({'message': 'Invalid resource format'}) raise tk.ValidationError({'message': 'Invalid resource format'})
return {'users_datasets': [{'user': user_name, 'datasets': datasets}]} return {'users_datasets': [{'user': user_name, 'datasets': datasets}]}

View File

@ -17,19 +17,14 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>. # along with CKAN Private Dataset Extension. If not, see <http://www.gnu.org/licenses/>.
import ckan.lib.search as search from __future__ import absolute_import
import ckan.model as model
import ckan.plugins as p
import ckan.plugins.toolkit as tk
from ckan import model, plugins as p
from ckan.lib import search
from ckan.lib.plugins import DefaultPermissionLabels from ckan.lib.plugins import DefaultPermissionLabels
from ckan.plugins import toolkit as tk
import auth from ckanext.privatedatasets import auth, actions, constants, converters_validators as conv_val, db, helpers
import actions
import constants
import converters_validators as conv_val
import db
import helpers as helpers
HIDDEN_FIELDS = [constants.ALLOWED_USERS, constants.SEARCHABLE] HIDDEN_FIELDS = [constants.ALLOWED_USERS, constants.SEARCHABLE]
@ -150,8 +145,6 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm, DefaultPermissio
return m return m
###################################################################### ######################################################################
############################## IACTIONS ############################## ############################## IACTIONS ##############################
###################################################################### ######################################################################
@ -270,7 +263,7 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm, DefaultPermissio
def after_search(self, search_results, search_params): def after_search(self, search_results, search_params):
for result in search_results['results']: for result in search_results['results']:
# Extra fields should not be returned # Extra fields should not be returned
# The original list cannot be modified # The original list cannot be modified
attrs = list(HIDDEN_FIELDS) attrs = list(HIDDEN_FIELDS)