Skip to content

Commit

Permalink
[#1453] remove item for select list if config not set by adding helpe…
Browse files Browse the repository at this point in the history
…r and change validator to fail when config is set with empty string
  • Loading branch information
kindly committed Jan 24, 2014
1 parent e8c8bda commit bc9d7fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -38,6 +38,7 @@
import ckan.lib.datapreview as datapreview
import ckan.logic as logic
import ckan.lib.uploader as uploader
import ckan.new_authz as new_authz

from ckan.common import (
_, ungettext, g, c, request, session, json, OrderedDict
Expand Down Expand Up @@ -1753,6 +1754,8 @@ def get_site_statistics():

return stats

def check_config_permission(permission):
return new_authz.check_config_permission(permission)

# these are the functions that will end up in `h` template helpers
__allowed_functions__ = [
Expand Down Expand Up @@ -1855,4 +1858,5 @@ def get_site_statistics():
'get_featured_organizations',
'get_featured_groups',
'get_site_statistics',
'check_config_permission',
]
4 changes: 2 additions & 2 deletions ckan/logic/validators.py
Expand Up @@ -33,8 +33,8 @@ def owner_org_validator(key, data, errors, context):
user = context['user']
user = model.User.get(user)
if value == '' :
if new_authz.check_config_permission('create_unowned_dataset'):
return
if not new_authz.check_config_permission('create_unowned_dataset'):
raise Invalid(_('A organization must be supplied'))
# only sysadmins can remove datasets from org
if not user.sysadmin:
raise Invalid(_('You cannot remove a dataset from an existing organization'))
Expand Down
4 changes: 3 additions & 1 deletion ckan/templates/package/snippets/package_basic_fields.html
Expand Up @@ -69,7 +69,9 @@
<label for="field-organizations" class="control-label">{{ _('Organization') }}</label>
<div class="controls">
<select id="field-organizations" name="owner_org" data-module="autocomplete">
<option value="" {% if not selected_org and data.id %} selected="selected" {% endif %}>{{ _('No organization') }}</option>
{% if h.check_config_permission('create_unowned_dataset') %}
<option value="" {% if not selected_org and data.id %} selected="selected" {% endif %}>{{ _('No organization') }}</option>
{% endif %}
{% for organization in organizations_available %}
{# get out first org from users list only if there is not an existing org #}
{% set selected_org = (existing_org and existing_org == organization.id) or (not existing_org and not data.id and organization.id == organizations_available[0].id) %}
Expand Down

0 comments on commit bc9d7fb

Please sign in to comment.