Commit 316339f6 authored by Michal Čihař's avatar Michal Čihař

Simplify permission checking in template

Consistenly use can_translate helper to check whether user is allowed to
translate given translation.
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 1d86bf8e
{% load i18n %}
{% load translations %}
{% load permissions %}
<div class="panel panel-primary">
<div class="panel-heading">
<h4 class="panel-title">{% if history_title %}{{ history_title }}{% else %}{% trans "History" %}{% endif %}</h4>
......@@ -29,11 +31,10 @@
<tr>
<td colspan="4">{% format_translation c.target c.unit.translation.language %}</td>
<td>
{% if perms.trans.save_translation and c.target != c.unit.target %}
{% if perms.trans.save_template or not trans.is_template %}
{% can_translate request.user c.translation as user_can_translate %}
{% if user_can_translate %}
<a class="historybutton small-button" href="{{ c.translation.get_translate_url}}?{% if search_id %}sid={{ search_id }}&amp;offset={{ offset }}&amp;{% endif %}checksum={{ c.unit.checksum }}&amp;revert={{ c.id }}" title="{% trans "Revert to this translation" %}">{% trans "Revert" %}</a>
{% endif %}
{% endif %}
</td>
</tr>
{% elif c.target %}
......
......@@ -3,6 +3,9 @@
{% load static %}
{% load translations %}
{% load crispy_forms_tags %}
{% load permissions %}
{% can_translate request.user unit.translation as user_can_translate %}
{% block extra_meta %}
<link rel="canonical" href="{{ unit.get_absolute_url }}" />
......@@ -17,11 +20,9 @@
{% block content %}
{% if perms.trans.save_translation %}
{% if perms.trans.save_template or not object.is_template %}
{% if user_can_translate %}
<a href="{% url 'zen' project=unit.translation.subproject.project.slug subproject=unit.translation.subproject.slug lang=unit.translation.language.code %}?sid={{ search_id }}" title="{% trans "Edit in Zen mode" %}" class="btn btn-default pull-right flip"><i class="fa fa-arrows-alt"></i> {% trans "Zen" %}</a>
{% endif %}
{% endif %}
{% with unit.translation as object %}
{% include "show-lock.html" %}
......@@ -84,18 +85,14 @@
{{ form|crispy }}
</div>
<div class="panel-footer">
{% if not unit.translation.only_vote_suggestions or perms.trans.override_suggestion %}
{% if perms.trans.save_translation %}
{% if perms.trans.save_template or not object.is_template %}
{% if user_can_translate %}
<input class="btn btn-default" type="submit" value="{% trans "Save" %}" name="save" tabindex="150" {% if locked %}disabled="disabled"{% endif %} />
{% endif %}
{% elif not user.is_authenticated %}
{% url 'login' as login_url %}
{% with unit.translation.get_translate_url as translate_url %}
{% blocktrans %}<a href="{{ login_url }}?next={{ translate_url }}">Log in</a> for saving translations.{% endblocktrans %}
{% endwith %}
{% endif %}
{% endif %}
{% if unit.translation.subproject.enable_suggestions %}
{% if perms.trans.add_suggestion %}
......@@ -105,8 +102,7 @@
{% endif %}
{% endif %}
{% if perms.trans.save_translation %}
{% if perms.trans.save_template or not object.is_template %}
{% if user_can_translate %}
<div class="pull-right flip hidden-xs">
{% trans "Commit message:" %}
<input type="text" name="commit_message" class="tooltip-control"
......@@ -118,7 +114,6 @@
/>
</div>
{% endif %}
{% endif %}
</div>
</div>
</form>
......@@ -229,11 +224,9 @@
<td><a href="{{ item.get_absolute_url }}">{% format_translation item.target item.translation.language unit.target %}</a></td>
<td>{% get_state_flags item %}</td>
<td>
{% if perms.trans.save_translation %}
{% if perms.trans.save_template or not object.is_template %}
{% if user_can_translate %}
<a class="mergebutton small-button btn btn-default" href="{{ unit.translation.get_translate_url}}?sid={{ search_id }}&amp;offset={{ offset }}&amp;checksum={{ unit.checksum }}&amp;merge={{ item.id }}" title="{% trans "Use this translation for all components" %}">{% trans "Use this translation" %}</a>
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
......@@ -369,11 +362,9 @@
<td>{{ item.source }}</td>
<td class="target">{% format_translation item.target unit.translation.language simple=True %}</td>
<td>
{% if perms.trans.save_translation %}
{% if perms.trans.save_template or not object.is_template %}
{% if user_can_translate or perms.trans.add_suggestion %}
<a class="copydict btn btn-default btn-xs" title="{% trans "Copy word to translation" %}">{% trans "Copy" %}</a>
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
......
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2015 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django import template
import weblate.trans.permissions
register = template.Library()
@register.assignment_tag
def can_translate(user, translation):
return weblate.trans.permissions.can_translate(
user, translation
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment