Repository: e-valuation/EvaP

Issue:
Availability of results for contributors must be consistent
Currently contributors can access all their course's results via the contributors page (once they have been published).
However, they cannot necessarily access them via the results page, because the courses are not linked in case there have not been sufficient voters.

It should be possible to access own courses on the results page even if there have not been sufficient voters, because text comments should be always available for the contributors. And the system must be consistent on all pages in regards to who gets access to the results.

A warning like "This course wasn't published" should be displayed on the course's details page like it's already the case for staff users.



Discussion:

Resolving patch:
diff --git a/evap/evaluation/models.py b/evap/evaluation/models.py
--- a/evap/evaluation/models.py
+++ b/evap/evaluation/models.py
@@ -169,6 +169,13 @@ def can_user_vote(self, user):
             and user in self.participants.all()
             and user not in self.voters.all())
 
+    def can_user_see_results(self, user):
+        if user.is_staff:
+            return True
+        if self.state == 'published':
+            return self.can_publish_grades() or self.is_user_contributor_or_delegate(user)
+        return False
+
     def can_fsr_edit(self):
         return self.state in ['new', 'prepared', 'lecturerApproved', 'approved', 'inEvaluation']
 
@@ -288,6 +295,17 @@ def is_user_responsible_or_delegate(self, user):
     def is_user_contributor(self, user):
         return self.contributions.filter(contributor=user).exists()
 
+    def is_user_contributor_or_delegate(self, user):
+        if self.is_user_contributor(user):
+            return True
+        else:
+            represented_userprofiles = user.represented_users.all()
+            represented_users = [profile.user for profile in represented_userprofiles]
+            if self.contributions.filter(contributor__in=represented_users).exists():
+                return True
+
+        return False
+
     def is_user_editor(self, user):
         return self.contributions.filter(contributor=user, can_edit=True).exists()
 
diff --git a/evap/evaluation/templatetags/morefilters.py b/evap/evaluation/templatetags/morefilters.py
--- a/evap/evaluation/templatetags/morefilters.py
+++ b/evap/evaluation/templatetags/morefilters.py
@@ -37,6 +37,11 @@ def studentstatename(state):
     return STUDENT_STATES_ORDERED.get(state)
 
 
+@register.filter(name='can_user_see_course')
+def can_user_see_course(course, user):
+    return course.can_user_see_results(user)
+
+
 @register.tag
 def value_from_settings(parser, token):
     try:
diff --git a/evap/results/views.py b/evap/results/views.py
--- a/evap/results/views.py
+++ b/evap/results/views.py
@@ -96,9 +96,9 @@ def course_detail(request, semester_id, course_id):
     sufficient_votes = course.num_voters >= settings.MIN_ANSWER_COUNT and float(course.num_voters) / course.num_participants >= settings.MIN_ANSWER_PERCENTAGE
 
     # results for a course might not be visible because there are not enough answers
-    # but it can still be "published" e.g. to show the comment results to lecturers
-    # the FSR can still see all results but gets a warning message
-    sufficient_votes_warning = (not sufficient_votes) and request.user.is_staff
+    # but it can still be "published" e.g. to show the comment results to lecturers.
+    # users who can open the results page see a warning message in this case
+    sufficient_votes_warning = not sufficient_votes
 
     course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)
 


Test patch: