Commit f4de1512 authored by Willem ter Berg's avatar Willem ter Berg

loosened validation on system properties.

added 'restriction_statement' property where re-use restrictions can be
detailed.
parent 9fdec95b
......@@ -17,23 +17,20 @@ def create_schema(schema):
optional = tk.get_validator('ignore_missing')
to_extras = tk.get_converter('convert_to_extras')
is_date = tk.get_validator('is_date')
is_resource_id = tk.get_validator('resource_id_exists')
referentiedata_on_create = tk.get_validator('referentiedata_on_create')
high_value_on_create = tk.get_validator('high_value_on_create')
basisregister_on_create = tk.get_validator('basisregister_on_create')
link_status_default = tk.get_validator('link_status_default')
is_bool = tk.get_validator('boolean_validator')
schema.update({
'referentiedata': [referentiedata_on_create, to_extras],
'high_value': [high_value_on_create, to_extras],
'basisregister': [basisregister_on_create, to_extras],
'restriction_statement': [optional, to_extras],
'referentiedata': [optional, is_bool, to_extras],
'high_value': [optional, is_bool, to_extras],
'basisregister': [optional, is_bool, to_extras],
'duplicate_resources': [optional, to_extras]
})
schema['resources'].update({
'link_status': [link_status_default],
'link_status': [optional, is_bool],
'link_last_checked_date': [optional, is_date],
'is_duplicate_of': [optional, is_resource_id]
'is_duplicate_of': [optional]
})
return schema
......@@ -49,23 +46,20 @@ def update_schema(schema):
optional = tk.get_validator('ignore_missing')
to_extras = tk.get_converter('convert_to_extras')
is_date = tk.get_validator('is_date')
is_resource_id = tk.get_validator('resource_id_exists')
referentiedata_on_update = tk.get_validator('referentiedata_on_update')
high_value_on_update = tk.get_validator('high_value_on_update')
basisregister_on_update = tk.get_validator('basisregister_on_update')
link_status_update = tk.get_validator('link_status_update')
is_bool = tk.get_validator('boolean_validator')
schema.update({
'referentiedata': [referentiedata_on_update, to_extras],
'high_value': [high_value_on_update, to_extras],
'basisregister': [basisregister_on_update, to_extras],
'restriction_statement': [optional, to_extras],
'referentiedata': [optional, is_bool, to_extras],
'high_value': [optional, is_bool, to_extras],
'basisregister': [optional, is_bool, to_extras],
'duplicate_resources': [optional, to_extras]
})
schema['resources'].update({
'link_status': [link_status_update],
'link_status': [optional, is_bool],
'link_last_checked_date': [optional, is_date],
'is_duplicate_of': [optional, is_resource_id]
'is_duplicate_of': [optional]
})
return schema
......@@ -78,19 +72,19 @@ def show_schema(schema):
:param schema: dict, the current CKAN schema
:return: dict, the updated schema
"""
mandatory = tk.get_validator('not_empty')
optional = tk.get_validator('ignore_missing')
from_extras = tk.get_converter('convert_from_extras')
schema.update({
'referentiedata': [from_extras, mandatory],
'high_value': [from_extras, mandatory],
'basisregister': [from_extras, mandatory],
'restriction_statement': [from_extras, optional],
'referentiedata': [from_extras, optional],
'high_value': [from_extras, optional],
'basisregister': [from_extras, optional],
'duplicate_resources': [from_extras, optional]
})
schema['resources'].update({
'link_status': [mandatory],
'link_status': [optional],
'link_last_checked_date': [optional],
'is_duplicate_of': [optional]
})
......
# encoding: utf-8
"""
Provides validation methods that enforce system properties management.
"""
from ckan.plugins.toolkit import get_action
import ckan.authz as authz
def referentiedata_on_create(key, data_dict, errors, context):
"""
Sets the referentiedata property to its default value unless a sysadmin made the request.
:param key: tuple, the key of the data_dict to check
:param data_dict: dict, the dataset dictionary
:param errors: dict, validation errors per dataset property
:param context: dict, the request context
:return: (key, data_dict, errors, context), the original arguments, possibly modified
"""
if isinstance(data_dict[key], bool) and authz.is_sysadmin(context.get('user')):
return key, data_dict, errors, context
data_dict[key] = False
return key, data_dict, errors, context
def referentiedata_on_update(key, data_dict, errors, context):
"""
Ensures that the referentiedata property can only be changed by sysadmin users.
:param key: tuple, the key of the data_dict to check
:param data_dict: dict, the dataset dictionary
:param errors: dict, validation errors per dataset property
:param context: dict, the request context
:return: (key, data_dict, errors, context), the original arguments, possibly modified
"""
if isinstance(data_dict[key], bool) and authz.is_sysadmin(context.get('user')):
return key, data_dict, errors, context
current_dataset = get_action('package_show')(context, {'id': data_dict[('id',)]})
data_dict[key] = current_dataset['referentiedata']
return key, data_dict, errors, context
def high_value_on_create(key, data_dict, errors, context):
"""
Sets the high_value property to its default value unless a sysadmin made the request.
:param key: tuple, the key of the data_dict to check
:param data_dict: dict, the dataset dictionary
:param errors: dict, validation errors per dataset property
:param context: dict, the request context
:return: (key, data_dict, errors, context), the original arguments, possibly modified
"""
if isinstance(data_dict[key], bool) and authz.is_sysadmin(context.get('user')):
return key, data_dict, errors, context
data_dict[key] = False
return key, data_dict, errors, context
def high_value_on_update(key, data_dict, errors, context):
"""
Ensures that the high_value property can only be changed by sysadmin users.
:param key: tuple, the key of the data_dict to check
:param data_dict: dict, the dataset dictionary
:param errors: dict, validation errors per dataset property
:param context: dict, the request context
:return: (key, data_dict, errors, context), the original arguments, possibly modified
"""
if isinstance(data_dict[key], bool) and authz.is_sysadmin(context.get('user')):
return key, data_dict, errors, context
current_dataset = get_action('package_show')(context, {'id': data_dict[('id',)]})
data_dict[key] = current_dataset['high_value']
return key, data_dict, errors, context
def basisregister_on_create(key, data_dict, errors, context):
"""
Sets the basisregister property to its default value unless a sysadmin made the request.
:param key: tuple, the key of the data_dict to check
:param data_dict: dict, the dataset dictionary
:param errors: dict, validation errors per dataset property
:param context: dict, the request context
:return: (key, data_dict, errors, context), the original arguments, possibly modified
"""
if isinstance(data_dict[key], bool) and authz.is_sysadmin(context.get('user')):
return key, data_dict, errors, context
data_dict[key] = False
return key, data_dict, errors, context
def basisregister_on_update(key, data_dict, errors, context):
"""
Ensures that the basisregister property can only be changed by sysadmin users.
:param key: tuple, the key of the data_dict to check
:param data_dict: dict, the dataset dictionary
:param errors: dict, validation errors per dataset property
:param context: dict, the request context
:return: (key, data_dict, errors, context), the original arguments, possibly modified
"""
if isinstance(data_dict[key], bool) and authz.is_sysadmin(context.get('user')):
return key, data_dict, errors, context
current_dataset = get_action('package_show')(context, {'id': data_dict[('id',)]})
data_dict[key] = current_dataset['basisregister']
return key, data_dict, errors, context
def link_status_default(key, data_dict, errors, context):
"""
Sets the default link_status value.
:param key: tuple, the key of the data_dict to check
:param data_dict: dict, the dataset dictionary
:param errors: dict, validation errors per dataset property
:param context: dict, the request context
:return: (key, data_dict, errors, context), the original arguments, possibly modified
"""
data_dict[key] = False
return key, data_dict, errors, context
def link_status_update(key, data_dict, errors, context):
"""
Updates the link_status field, if the user is authorized to do so.
:param key: tuple, the key of the data_dict to check
:param data_dict: dict, the dataset dictionary
:param errors: dict, validation errors per dataset property
:param context: dict, the request context
:return: (key, data_dict, errors, context), the original arguments, possibly modified
"""
if isinstance(data_dict[key], bool) and authz.is_sysadmin(context.get('user')):
return key, data_dict, errors, context
current_dataset = get_action('resource_show')(context, {'id': data_dict[('id',)]})
data_dict[key] = current_dataset['link_status']
return key, data_dict, errors, context
......@@ -13,7 +13,6 @@ import ckanext.dcatdonl.validator.hash_validator as hash_validator
import ckanext.dcatdonl.validator.legal_foundation_validator as legal_foundation_validator
import ckanext.dcatdonl.validator.valuelist_validator as valuelist_validator
import ckanext.dcatdonl.validator.changetype_validator as changetype_validator
import ckanext.dcatdonl.validator.system_properties_validator as system_properties_validator
class ValidatorException(Exception):
......@@ -55,15 +54,7 @@ _VALIDATORS = {
'iana_mediatypes': valuelist_validator.iana_mediatypes,
'adms_distributiestatus': valuelist_validator.adms_distributiestatus,
'convert_to_list_if_curly_string': type_validator.convert_to_list_if_string,
'convert_to_curly_string_if_list': type_validator.convert_to_curly_string_if_list,
'referentiedata_on_create': system_properties_validator.referentiedata_on_create,
'referentiedata_on_update': system_properties_validator.referentiedata_on_update,
'high_value_on_create': system_properties_validator.high_value_on_create,
'high_value_on_update': system_properties_validator.high_value_on_update,
'basisregister_on_create': system_properties_validator.basisregister_on_create,
'basisregister_on_update': system_properties_validator.basisregister_on_update,
'link_status_default': system_properties_validator.link_status_default,
'link_status_update': system_properties_validator.link_status_update
'convert_to_curly_string_if_list': type_validator.convert_to_curly_string_if_list
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment