Skip to content

Commit

Permalink
ref: reduce dataset option visibility for non-admins
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Nov 18, 2021
1 parent 6414f73 commit 95ae9f4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 47 deletions.
3 changes: 1 addition & 2 deletions ckanext/dcor_schemas/assets/webassets.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
hide_unused_elements:
contents:
- hide_unused_elements.css

hide_for_nonadmin:
hide_for_non_admin:
contents:
- hide_for_non_admin.css
6 changes: 6 additions & 0 deletions ckanext/dcor_schemas/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
{% block styles %}
{{ super() }}
{% asset 'dcor_schemas/hide_unused_elements' %}

{# Only admins can see those elements (kind of a workaround) #}
{% if not c.userobj.sysadmin %}
{% asset 'dcor_schemas/hide_for_non_admin' %}
{% endif %}

{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% ckan_extends %}

{# Add custom metadata fields (only show to admins) #}
{% set user_is_sysadmin = h.check_access('sysadmin') %}

{# Add custom metadata fields #}

{% block package_basic_fields_custom %}
{{ form.input('authors', label=_('Authors'), id='field-authors', placeholder=_('Guybrush Threepwood, John Cleese'), value=data.authors, error=errors.authors, classes=['control-required', 'only-for-admin']) }}
Expand All @@ -9,59 +11,78 @@
{% endblock %}


{# Only show other fields to admins #}
{# Only show other non-essential fields to admins #}

{% block package_basic_fields_title %}
{% if user_is_sysadmin %}
{{ super() }}
{% endif %}
{% endblock %}

{% block package_basic_fields_url %}
{% if user_is_sysadmin %}
{{ super() }}
{% endif %}
{% endblock %}

{% block package_basic_fields_description %}
{% if user_is_sysadmin %}
{{ super() }}
{% endif %}
{% endblock %}

{% if not c.userobj.sysadmin %}
{% block package_basic_fields_title %} {% endblock %}
{% block package_basic_fields_url %} {% endblock %}
{% block package_basic_fields_description %} {% endblock %}
{% block package_basic_fields_tags %} {% endblock %}
{% endif %}
{% block package_basic_fields_tags %}
{% if user_is_sysadmin %}
{{ super() }}
{% endif %}
{% endblock %}

{# Make 'private=False' the default #}

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


{# Modify license fields only to less-restrictive ones #}

{% block package_basic_fields_license %}
<div class="form-group">
{% set error = errors.license_id %}
<label class="control-label control-required" for="field-license">{{ _("License") }}</label>
<div class="controls">
<div class="row">
<div class="col-md-6">
<select id="field-license" name="license_id" data-module="autocomplete">
{% set existing_license_id = data.get('license_id', 'none') %}
{% for license_id, license_desc in h.dcor_schemas_license_options(existing_license_id) %}
<option value="{{ license_id }}" {% if existing_license_id == license_id %}selected="selected"{% endif %}>{{ license_desc }}</option>
{% endfor %}
</select>
{% if error %}<span class="error-block">{{ error }}</span>{% endif %}
</div>
<div class="col-md-6">
<span class="info-block info-inline">
<i class="fa fa-info-circle"></i>
{% trans %}
Please find a comparison of the licenses at
<a href="https://en.wikipedia.org/wiki/Creative_Commons_license#Seven_regularly_used_licenses">Wikipedia</a>.
You may always switch to a less restrictive license.
{% endtrans %}
</span>
</div>
</div>
</div>
</div>
<div class="{{ classes }}">
{% set error = errors.license_id %}
<label class="control-label control-required" for="field-license">{{ _("License") }}</label>
<div class="controls">
<div class="row">
<div class="col-md-6">
<select id="field-license" name="license_id" data-module="autocomplete">
{% set existing_license_id = data.get('license_id', 'none') %}
{% for license_id, license_desc in h.dcor_schemas_license_options(existing_license_id) %}
<option value="{{ license_id }}" {% if existing_license_id == license_id %}selected="selected"{% endif %}>{{ license_desc }}</option>
{% endfor %}
</select>
{% if error %}<span class="error-block">{{ error }}</span>{% endif %}
</div>
<div class="col-md-6">
<span class="info-block info-inline">
<i class="fa fa-info-circle"></i>
{% trans %}
Please find a comparison of the licenses at
<a href="https://en.wikipedia.org/wiki/Creative_Commons_license#Seven_regularly_used_licenses">Wikipedia</a>.
You may always switch to a less restrictive license.
{% endtrans %}
</span>
</div>
</div>
</div>
</div>
{% endblock %}

0 comments on commit 95ae9f4

Please sign in to comment.