Avoid missing values checking the private value

This commit is contained in:
Aitor Magán 2014-07-16 15:59:45 +02:00
parent 8ce7375c31
commit 2ee2b077cc
3 changed files with 21 additions and 5 deletions

View File

@ -11,6 +11,10 @@ def private_datasets_metadata_checker(key, data, errors, context):
dataset_id = data.get(('id',))
private_val = data.get(('private',))
#Avoid missing value
if not isinstance(private_val, basestring) 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
if private_val is None and dataset_id:
dataset_dict = toolkit.get_action('package_show')({'ignore_auth': True}, {'id': dataset_id})
@ -20,7 +24,7 @@ def private_datasets_metadata_checker(key, data, errors, context):
metadata_value = data[key]
# If allowed users are included and the dataset is not private outside and organization, an error will be raised.
if metadata_value != '' and not private:
if metadata_value and not private:
errors[key].append(_('This field is only valid when you create a private dataset'))

View File

@ -14,17 +14,17 @@ this.ckan.module('allowed-users', function ($, _) {
var ds_private = $('#field-private').val();
if (ds_private == "True") {
$('#field-allowed_users').prop('disabled', false); //Enable
$('#field-allowed_users_str').prop('disabled', false); //Enable
$('#field-adquire_url').prop('disabled', false); //Enable
$('#field-searchable').prop('disabled', false); //Enable
} else {
$('#field-allowed_users').prop('disabled', true); //Disable
$('#field-allowed_users_str').prop('disabled', true); //Disable
$('#field-adquire_url').prop('disabled', true); //Disable
$('#field-searchable').prop('disabled', true); //Disable
//Remove previous values
$('#s2id_field-allowed_users .select2-search-choice').remove();
$('#field-allowed_users').val('');
$('#s2id_field-allowed_users_str .select2-search-choice').remove();
$('#field-allowed_users_str').val('');
$('#field-adquire_url').val('');
$('#field-searchable').val('True');
}

View File

@ -33,6 +33,18 @@ class ConvertersValidatorsTest(unittest.TestCase):
('False', True, None, '', False),
(None, True, None, '', False),
(None, False, None, '', False),
(True, True, 'conwet', [], False),
('True', True, 'conwet', [], False),
(False, True, 'conwet', [], False),
('False', True, 'conwet', [], False),
(None, True, 'conwet', [], False),
(None, False, 'conwet', [], False),
(True, True, None, [], False),
('True', True, None, [], False),
(False, True, None, [], False),
('False', True, None, [], False),
(None, True, None, [], False),
(None, False, None, [], False),
# When data is present, the field is only valid when the
# the private field is set to true (organization should
# not be taken into account anymore)