Skip to content

Commit

Permalink
[#953] Fix display or Organization and Visibility dropdowns
Browse files Browse the repository at this point in the history
Fix the logic for displaying the Organization and Visibility dropdowns
when creating or updating a dataset.

We really need frontend tests for this.

I tested these cases manually:

User is not logged in and anon_create_dataset = True: neither
Organization nor Visibility shows, either when creating or when updating
a dataset.

User is logged in, but is not a member of any organization: neither
Organization nor Visibility shows, either when creating or when updating
a dataset. Tested both when the site has no organizations and when the
site does have orgs but user is not a member of any.

User is logged in, and is a member of an organization: Both Organization
and Visibility show when creating a dataset.

When creating a private dataset, no activities appear in the activity
stream.

User is logged in, and is a member of an organization, but dataset is
not a member of any org: neither Organization nor Visibility shows when
updating a dataset.

User is logged in, and is a member of an organization, and dataset is a
member of any org: Visibility shows but Organization does not show when
updating a dataset.

User is sysadmin, site has no orgs: neither Organization nor Visibility
shows when creating or updating a dataset.

User is sysadmin, site does have orgs: both Organization and Visibility
show when creating or updating a dataset.
  • Loading branch information
Sean Hammond authored and amercader committed Jul 1, 2013
1 parent 3cf7993 commit d9bb57c
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions ckan/templates/package/snippets/package_basic_fields.html
Expand Up @@ -52,37 +52,41 @@
{% if data.group_id %}
<input type="hidden" name="groups__0__id" value="{{ data.group_id }}" />
{% endif %}
{% set existing_org = data.owner_org or data.group_id %}
{% if h.check_access('sysadmin') or data.get('state', 'draft').startswith('draft') or data.get('state', 'none') == 'none' %}
{% set organizations_available = h.organizations_available('create_dataset') %}
{% if organizations_available %}

{% set dataset_is_draft = data.get('state', 'draft').startswith('draft') or data.get('state', 'none') == 'none' %}
{% set dataset_has_organization = data.owner_org or data.group_id %}
{% set organizations_available = h.organizations_available('create_dataset') %}
{% set user_is_sysadmin = h.check_access('sysadmin') %}

{% if organizations_available and (user_is_sysadmin or dataset_is_draft) %}
<div class="control-group">
<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 %}>{{ _('Select an organization...') }}</option>
{% 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) %}
<option value="{{ organization.id }}" {% if selected_org %} selected="selected" {% endif %}>{{ organization.name }}</option>
{% endfor %}
</select>
</div>
</div>
{% endif %}

{% if dataset_has_organization or (organizations_available and (user_is_sysadmin or dataset_is_draft)) %}
{% block package_metadata_fields_visibility %}
<div class="control-group">
<label for="field-organizations" class="control-label">{{ _('Organization') }}</label>
<label for="field-private" class="control-label">{{ _('Visibility') }}</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 %}>{{ _('Select an organization...') }}</option>
{% 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) %}
<option value="{{ organization.id }}" {% if selected_org %} selected="selected" {% endif %}>{{ organization.name }}</option>
<select id="field-private" name="private" data-module="autocomplete">
{% for option in [(true, _('Private')), (false, _('Public'))] %}
<option value="{{ option[0] }}" {% if option[0] == data.private %}selected="selected"{% endif %}>{{ option[1] }}</option>
{% endfor %}
</select>
</div>
</div>
{% endif %}
{% endblock %}
{% endif %}

{% block package_metadata_fields_visibility %}
<div class="control-group">
<label for="field-private" class="control-label">{{ _('Visibility') }}</label>
<div class="controls">
<select id="field-private" name="private" data-module="autocomplete">
{% for option in [(true, _('Private')), (false, _('Public'))] %}
<option value="{{ option[0] }}" {% if option[0] == data.private %}selected="selected"{% endif %}>{{ option[1] }}</option>
{% endfor %}
</select>
</div>
</div>
{% endblock %}

{% endblock %}

0 comments on commit d9bb57c

Please sign in to comment.