Skip to content

Commit

Permalink
[#1188] Fix visibility validator
Browse files Browse the repository at this point in the history
Only the 2.1.x relevant bits were cherry-picked
  • Loading branch information
amercader committed Jan 8, 2014
1 parent d952c4f commit 9a23b77
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ckan/logic/validators.py
Expand Up @@ -642,6 +642,26 @@ def list_of_strings(key, data, errors, context):

def datasets_with_no_organization_cannot_be_private(key, data, errors,
context):
if data[key] is True and data.get(('owner_org',)) is None:

dataset_id = data.get(('id',))
owner_org = data.get(('owner_org',))
private = data[key] is True

check_passed = True
if not dataset_id and private and owner_org is None:
# When creating a dataset, enforce it directly
check_passed = False
elif dataset_id and private and owner_org is None:
# Check if the dataset actually has an owner_org, even if not provided
try:
dataset_dict = logic.get_action('package_show')({},
{'id': dataset_id})
if not dataset_dict.get('owner_org'):
check_passed = False

except logic.NotFound:
check_passed = False

if not check_passed:
errors[key].append(
_("Datasets with no organization can't be private."))

0 comments on commit 9a23b77

Please sign in to comment.