Skip to content
Snippets Groups Projects
Commit 18ae699e authored by Carlos Vega's avatar Carlos Vega
Browse files

consider permissions in the sidebar template

parent 77c6017e
No related branches found
No related tags found
1 merge request!192Feature/add way to change password and PERMISSIONS
...@@ -23,12 +23,14 @@ ...@@ -23,12 +23,14 @@
</a> </a>
</li> </li>
{% if "change_worker" in permissions or "add_worker" in permissions or "delete_worker" in permissions %}
<li data-desc="workers"> <li data-desc="workers">
<a href="{% url 'web.views.workers' %}"> <a href="{% url 'web.views.workers' %}">
<i class="fa fa-user-md"></i> <i class="fa fa-user-md"></i>
<span>Workers</span> <span>Worker</span>
</a> </a>
</li> </li>
{% endif %}
<li data-desc="equipment_and_rooms" class="treeview"> <li data-desc="equipment_and_rooms" class="treeview">
<a href="{% url 'web.views.equipment_and_rooms' %}"> <a href="{% url 'web.views.equipment_and_rooms' %}">
...@@ -83,16 +85,29 @@ ...@@ -83,16 +85,29 @@
</span> </span>
</a> </a>
<ul class="treeview-menu"> <ul class="treeview-menu">
{% if "change_configurationitem" in permissions %}
<li><a href="{% url 'web.views.configuration' %}">General</a></li> <li><a href="{% url 'web.views.configuration' %}">General</a></li>
{% endif %}
{% if "change_language" in permissions %}
<li><a href="{% url 'web.views.languages' %}">Languages</a></li> <li><a href="{% url 'web.views.languages' %}">Languages</a></li>
{% if study.has_voucher_types %} {% endif %}
{% if study.has_voucher_types and "change_vouchertype" in permissions %}
<li><a href="{% url 'web.views.voucher_types' %}">Voucher types</a></li> <li><a href="{% url 'web.views.voucher_types' %}">Voucher types</a></li>
{% endif %} {% endif %}
{% if study.has_vouchers %}
{% if study.has_vouchers and "change_voucher" in permissions %}
<li><a href="{% url 'web.views.workers' 'VOUCHER_PARTNER' %}">Voucher partners</a></li> <li><a href="{% url 'web.views.workers' 'VOUCHER_PARTNER' %}">Voucher partners</a></li>
{% endif %} {% endif %}
{% if "change_worker" in permissions %}
<li><a href="{% url 'web.views.workers' 'HEALTH_PARTNER' %}">Health partners</a></li> <li><a href="{% url 'web.views.workers' 'HEALTH_PARTNER' %}">Health partners</a></li>
{% endif %}
{% if "change_study" in permissions %}
<li><a href="{% url 'web.views.edit_study' study_id %}">Study</a></li> <li><a href="{% url 'web.views.edit_study' study_id %}">Study</a></li>
{% endif %}
</ul> </ul>
</li> </li>
......
...@@ -6,6 +6,7 @@ from django.views.generic.base import ContextMixin ...@@ -6,6 +6,7 @@ from django.views.generic.base import ContextMixin
from web.models.constants import GLOBAL_STUDY_ID from web.models.constants import GLOBAL_STUDY_ID
from notifications import get_notifications from notifications import get_notifications
from ..models import Worker, Study from ..models import Worker, Study
from web.decorators import PermissionDecorator
handler404 = 'web.views.e404_page_not_found' handler404 = 'web.views.e404_page_not_found'
handler500 = 'web.views.e500_error' handler500 = 'web.views.e500_error'
...@@ -41,9 +42,12 @@ def wrap_response(request, template, params): ...@@ -41,9 +42,12 @@ def wrap_response(request, template, params):
def extend_context(params, request): def extend_context(params, request):
study = Study.get_by_id(GLOBAL_STUDY_ID)
person = Worker.get_by_user(request.user) # None if AnonymousUser or no Worker associated person = Worker.get_by_user(request.user) # None if AnonymousUser or no Worker associated
permissions = []
if person is not None: if person is not None:
role = person.role role = person.role
permissions = person.get_permissions(study)
person = unicode(person) person = unicode(person)
else: else:
#use full name if available, username otherwise #use full name if available, username otherwise
...@@ -54,8 +58,9 @@ def extend_context(params, request): ...@@ -54,8 +58,9 @@ def extend_context(params, request):
role = '<No worker information>' role = '<No worker information>'
notifications = get_notifications(request.user) notifications = get_notifications(request.user)
final_params = params.copy() final_params = params.copy()
study = Study.get_by_id(GLOBAL_STUDY_ID)
final_params.update({ final_params.update({
'permissions' : permissions,
'conf_perms' : permissions & PermissionDecorator.codename_groups['configuration'],
'person': person, 'person': person,
'role': role, 'role': role,
'notifications': notifications, 'notifications': notifications,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment