mirror of
https://github.com/Hopiu/django-rosetta.git
synced 2026-03-16 21:30:24 +00:00
Do not show Rosetta link in admin panel if user has no access to translations.
This commit is contained in:
parent
b02ad3ad1d
commit
7659e93051
3 changed files with 15 additions and 2 deletions
|
|
@ -1,8 +1,9 @@
|
|||
{% extends "admin/index.html" %}
|
||||
{% load i18n %}
|
||||
{% load rosetta i18n %}
|
||||
|
||||
{% block sidebar %}
|
||||
{{block.super}}
|
||||
{% if request.user|can_translate %}
|
||||
<div id="rosetta-content-main">
|
||||
<div class="app-rosetta module">
|
||||
<table>
|
||||
|
|
@ -16,5 +17,5 @@
|
|||
</tbody></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,14 @@ from django.utils.html import escape
|
|||
import re
|
||||
import six
|
||||
|
||||
from rosetta.access import can_translate
|
||||
|
||||
|
||||
register = template.Library()
|
||||
rx = re.compile(r'(%(\([^\s\)]*\))?[sd]|\{[\w\d_]+?\})')
|
||||
|
||||
can_translate = register.filter(can_translate)
|
||||
|
||||
|
||||
def format_message(message):
|
||||
return mark_safe(rx.sub('<code>\\1</code>', escape(message).replace(r'\n', '<br />\n')))
|
||||
|
|
|
|||
|
|
@ -1033,6 +1033,14 @@ class RosettaTestCase(TestCase):
|
|||
self.assertTrue('foo language' in r.content.decode())
|
||||
self.assertTrue('bar language' in r.content.decode())
|
||||
|
||||
def test_198_embed_in_admin_access_control(self):
|
||||
resp = self.client.get(reverse('admin:index'))
|
||||
self.assertContains(resp, 'rosetta-content-main')
|
||||
|
||||
with self.settings(ROSETTA_ACCESS_CONTROL_FUNCTION=lambda user: False):
|
||||
resp = self.client.get(reverse('admin:index'))
|
||||
self.assertNotContains(resp, 'rosetta-content-main')
|
||||
|
||||
|
||||
# Stubbed access control function
|
||||
def no_access(user):
|
||||
|
|
|
|||
Loading…
Reference in a new issue