Commit 49973aa8 authored by Enrico Zini's avatar Enrico Zini
Browse files

Added editable_by filter to simplify permission checking in templates

parent e3b6fb37
......@@ -347,6 +347,22 @@ class Process(models.Model):
from django.db.models import Max
return p.processes.annotate(last_change=Max("log__logdate")).order_by("-last_change")[0]
def can_be_edited(self, am=None):
# FD and DAM can edit anything
if am is not None and (am.is_fd or am.is_dam):
return True
# If the process is closed, then AMs cannot edit it
if not self.is_active:
return False
# If we do not check by AM, we're done
if am is None:
return True
# Otherwise the AM can edit if manager of this process
return self.manager == am
#def get_log(self, desc=False, max=None):
# res = orm.object_session(self) \
# .query(Log) \
......
{% extends "public/base.html" %}
{% load const %}
{% load macros %}
{% load perms %}
{% macro process_table processes %}
<table>
......@@ -13,7 +14,7 @@
<th>Progress</th>
<th>AM</th>
<th>Advocate(s)</th>
{% if cur_am %}
{% if request.am %}
<th>Extras</th>
{% endif %}
</thead>
......@@ -43,9 +44,9 @@
<a href="{% url public_person key=a.lookup_key %}" title="{{a.fullname}}">{{a.uid}}</a>{% if not forloop.last %},{% endif %}
{% endfor %}
</td>
{% if cur_am %}
{% if request.am %}
<td>
{% if cur_am.is_fd or cur_am.is_dam or cur_am == p.manager and p.is_active %}
{% if p|editable_by:request.am %}
<a href="{% url restricted_nmstatus key=p.lookup_key %}">edit</a>
{% endif %}
</td>
......@@ -60,7 +61,7 @@
{% block relatedpages %}
{{block.super}}
{% if cur_am %}
{% if request.am %}
<a href="{% url restricted_person key=person.lookup_key %}">full version</a>
{% endif %}
{% endblock %}
......
......@@ -175,13 +175,6 @@ def person(request, key):
am = None
am_processes = []
cur_am = None
cur_person = None
if not request.user.is_anonymous():
cur_person = request.user.get_profile()
if cur_person.is_am:
cur_am = cur_person.am
adv_processes = person.advocated \
.annotate(started=Min("log__logdate"), ended=Max("log__logdate")) \
.order_by("is_active", "ended")
......@@ -189,8 +182,6 @@ def person(request, key):
return render_to_response("public/person.html",
dict(
person=person,
cur_person=cur_person,
cur_am=cur_am,
am=am,
processes=processes,
am_processes=am_processes,
......
Supports Markdown
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