From 761b8e87b6d64bf4378b076a6f59077b69f00027 Mon Sep 17 00:00:00 2001
From: Jorran de Wit <jorrandewit@outlook.com>
Date: Mon, 25 Sep 2017 08:59:13 +0200
Subject: [PATCH] Finalize for use with ProductionUsers without Contributor
 instance

---
 production/templates/production/base.html           | 13 +++++++++++++
 production/templates/production/completed.html      |  2 +-
 production/templates/production/production.html     |  4 ++--
 .../production/productionevent_confirm_delete.html  |  3 +--
 .../templates/production/productionevent_form.html  |  3 +--
 production/views.py                                 | 12 ++++++++++--
 scipost/templates/scipost/navbar.html               |  5 +++++
 7 files changed, 33 insertions(+), 9 deletions(-)
 create mode 100644 production/templates/production/base.html

diff --git a/production/templates/production/base.html b/production/templates/production/base.html
new file mode 100644
index 000000000..9dbe1e96d
--- /dev/null
+++ b/production/templates/production/base.html
@@ -0,0 +1,13 @@
+{% extends 'scipost/base.html' %}
+
+{% block breadcrumb %}
+    <nav class="breadcrumb py-md-2 px-0 hidden-sm-down">
+        <div class="container">
+            {% block breadcrumb_items %}
+                <a href="{% url 'production:production' %}" class="breadcrumb-item">Production page</a>
+            {% endblock %}
+        </div>
+    </nav>
+{% endblock %}
+
+{% block container_class %}{{block.super}} pb-5{% endblock container_class %}
diff --git a/production/templates/production/completed.html b/production/templates/production/completed.html
index bf3507da6..00557d6ca 100644
--- a/production/templates/production/completed.html
+++ b/production/templates/production/completed.html
@@ -1,4 +1,4 @@
-{% extends 'scipost/_personal_page_base.html' %}
+{% extends 'production/base.html' %}
 
 {% block breadcrumb_items %}
     {{block.super}}
diff --git a/production/templates/production/production.html b/production/templates/production/production.html
index 841d159b7..d7c31e2c9 100644
--- a/production/templates/production/production.html
+++ b/production/templates/production/production.html
@@ -1,7 +1,6 @@
-{% extends 'scipost/_personal_page_base.html' %}
+{% extends 'production/base.html' %}
 
 {% block breadcrumb_items %}
-    {{block.super}}
     <span class="breadcrumb-item">Production page</span>
 {% endblock %}
 
@@ -51,6 +50,7 @@
     <div class="row">
       <div class="col-12">
     	<h2 class="highlight">{{ perms.scipost.can_assign_production_officer|yesno:"Streams,My Streams" }}</h2>
+        <a href="{% url 'production:completed' %}">View completed streams</a>
       </div>
     </div>
 
diff --git a/production/templates/production/productionevent_confirm_delete.html b/production/templates/production/productionevent_confirm_delete.html
index 75feabb00..c6cd4c05a 100644
--- a/production/templates/production/productionevent_confirm_delete.html
+++ b/production/templates/production/productionevent_confirm_delete.html
@@ -1,8 +1,7 @@
-{% extends 'scipost/_personal_page_base.html' %}
+{% extends 'production/base.html' %}
 
 {% block breadcrumb_items %}
     {{block.super}}
-    <a href="{{object.get_absolute_url}}" class="breadcrumb-item">Production streams</a>
     <span class="breadcrumb-item">Delete production event</span>
 {% endblock %}
 
diff --git a/production/templates/production/productionevent_form.html b/production/templates/production/productionevent_form.html
index fc90e04c9..d520f1c75 100644
--- a/production/templates/production/productionevent_form.html
+++ b/production/templates/production/productionevent_form.html
@@ -1,8 +1,7 @@
-{% extends 'scipost/_personal_page_base.html' %}
+{% extends 'production/base.html' %}
 
 {% block breadcrumb_items %}
     {{block.super}}
-    <a href="{{object.get_absolute_url}}" class="breadcrumb-item">Production streams</a>
     <span class="breadcrumb-item">Edit production event</span>
 {% endblock %}
 
diff --git a/production/views.py b/production/views.py
index d83931639..f122ffbcd 100644
--- a/production/views.py
+++ b/production/views.py
@@ -60,7 +60,11 @@ def completed(request):
     """
     Overview page for closed production streams.
     """
-    streams = ProductionStream.objects.completed().order_by('-opened')
+    streams = ProductionStream.objects.completed()
+    if not request.user.has_perm('scipost.can_assign_production_officer'):
+        streams = streams.filter_for_user(request.user.production_user)
+    streams = streams.order_by('-opened')
+
     context = {'streams': streams}
     return render(request, 'production/completed.html', context)
 
@@ -82,7 +86,11 @@ def user_to_officer(request):
 @is_production_user()
 @permission_required('scipost.can_view_production', return_403=True)
 def add_event(request, stream_id):
-    stream = get_object_or_404(ProductionStream.objects.ongoing(), pk=stream_id)
+    qs = ProductionStream.objects.ongoing()
+    if not request.user.has_perm('scipost.can_assign_production_officer'):
+        qs = qs.filter_for_user(request.user.production_user)
+
+    stream = get_object_or_404(qs, pk=stream_id)
     prodevent_form = ProductionEventForm(request.POST or None)
     if prodevent_form.is_valid():
         prodevent = prodevent_form.save(commit=False)
diff --git a/scipost/templates/scipost/navbar.html b/scipost/templates/scipost/navbar.html
index 2095054a8..d946d2675 100644
--- a/scipost/templates/scipost/navbar.html
+++ b/scipost/templates/scipost/navbar.html
@@ -46,6 +46,11 @@
               <li class="nav-item">
                   <a class="nav-link" href="{% url 'scipost:logout' %}">Logout</a>
               </li>
+              {% if perms.scipost.can_view_production %}
+                  <li class="nav-item{% if '/production' in request.path %} active{% endif %}">
+                    <a class="nav-link" href="{% url 'production:production' %}">Production</a>
+                  </li>
+              {% endif %}
               {% if perms.scipost.can_oversee_refereeing %}
                   <li class="nav-item{% if '/submissions/admin' in request.path %} active{% endif %}">
                     <a class="nav-link" href="{% url 'submissions:admin' %}">Editorial Administration</a>
-- 
GitLab