Repository: e-valuation/EvaP

Issue:
Add information message on deactivated course page for editors
Editors can open a course's edit page after they approved the course, however the form will then be disabled. A message on top of the page should explain this to the user.


Discussion:

Resolving patch:
diff --git a/evap/contributor/views.py b/evap/contributor/views.py
--- a/evap/contributor/views.py
+++ b/evap/contributor/views.py
@@ -71,6 +71,9 @@ def course_view(request, course_id):
     if not (course.is_user_editor_or_delegate(user) and course.state in ['prepared', 'editor_approved', 'approved', 'in_evaluation', 'evaluated', 'reviewed']):
         raise PermissionDenied
 
+    if course.is_user_editor_or_delegate(user):
+        messages.info(request, _('You cannot edit this course because it has already been approved.'))
+
     InlineContributionFormset = inlineformset_factory(Course, Contribution, formset=ContributionFormSet, form=EditorContributionForm, extra=0)
 
     form = CourseForm(request.POST or None, instance=course)


Test patch:
diff --git a/evap/contributor/tests/test_views.py b/evap/contributor/tests/test_views.py
--- a/evap/contributor/tests/test_views.py
+++ b/evap/contributor/tests/test_views.py
@@ -1,7 +1,7 @@
 from model_mommy import mommy
 
 from evap.evaluation.models import Course, UserProfile
-from evap.evaluation.tests.tools import ViewTest, course_with_responsible_and_editor
+from evap.evaluation.tests.tools import ViewTest, create_course_with_responsible_and_editor
 
 TESTING_COURSE_ID = 2
 
@@ -12,7 +12,7 @@ class TestContributorView(ViewTest):
 
     @classmethod
     def setUpTestData(cls):
-        course_with_responsible_and_editor()
+        create_course_with_responsible_and_editor()
 
 
 class TestContributorSettingsView(ViewTest):
@@ -21,7 +21,7 @@ class TestContributorSettingsView(ViewTest):
 
     @classmethod
     def setUpTestData(cls):
-        course_with_responsible_and_editor()
+        create_course_with_responsible_and_editor()
 
     def test_save_settings(self):
         user = mommy.make(UserProfile)
@@ -39,12 +39,21 @@ class TestContributorCourseView(ViewTest):
 
     @classmethod
     def setUpTestData(cls):
-        cls.course = course_with_responsible_and_editor(course_id=TESTING_COURSE_ID)
-
+        create_course_with_responsible_and_editor(course_id=TESTING_COURSE_ID)
+    
+    def setUp(self):
+        self.course = Course.objects.get(pk=TESTING_COURSE_ID)
+    
     def test_wrong_state(self):
         self.course.revert_to_new()
         self.course.save()
         self.get_assert_403(self.url, 'responsible')
+ 
+    def test_information_message(self):
+        self.course.editor_approve()
+        self.course.save()
+        page = self.app.get(self.url, user='editor')
+        self.assertContains(page, "You cannot edit this course because it has already been approved")
 
 
 class TestContributorCoursePreviewView(ViewTest):
@@ -53,7 +62,7 @@ class TestContributorCoursePreviewView(ViewTest):
 
     @classmethod
     def setUpTestData(cls):
-        cls.course = course_with_responsible_and_editor(course_id=TESTING_COURSE_ID)
+        cls.course = create_course_with_responsible_and_editor(course_id=TESTING_COURSE_ID)
 
     def setUp(self):
         self.course = Course.objects.get(pk=TESTING_COURSE_ID)
@@ -70,7 +79,7 @@ class TestContributorCourseEditView(ViewTest):
 
     @classmethod
     def setUpTestData(cls):
-        cls.course = course_with_responsible_and_editor(course_id=TESTING_COURSE_ID)
+        cls.course = create_course_with_responsible_and_editor(course_id=TESTING_COURSE_ID)
 
     def setUp(self):
         self.course = Course.objects.get(pk=TESTING_COURSE_ID)
diff --git a/evap/evaluation/tests/tools.py b/evap/evaluation/tests/tools.py
--- a/evap/evaluation/tests/tools.py
+++ b/evap/evaluation/tests/tools.py
@@ -75,7 +75,7 @@ def get_form_data_from_instance(FormClass, instance):
     return {field.html_name: field.value() for field in form}
 
 
-def course_with_responsible_and_editor(course_id=None):
+def create_course_with_responsible_and_editor(course_id=None):
     contributor = mommy.make(UserProfile, username='responsible')
     editor = mommy.make(UserProfile, username='editor')
 
diff --git a/evap/staff/tests/test_forms.py b/evap/staff/tests/test_forms.py
--- a/evap/staff/tests/test_forms.py
+++ b/evap/staff/tests/test_forms.py
@@ -4,7 +4,7 @@
 
 from evap.evaluation.models import UserProfile, CourseType, Course, Questionnaire, \
     Contribution, Semester, Degree, EmailTemplate
-from evap.evaluation.tests.tools import get_form_data_from_instance, course_with_responsible_and_editor, to_querydict
+from evap.evaluation.tests.tools import get_form_data_from_instance, create_course_with_responsible_and_editor, to_querydict
 from evap.staff.forms import UserForm, SingleResultForm, ContributionFormSet, ContributionForm, CourseForm, \
     CourseEmailForm
 from evap.contributor.forms import CourseForm as ContributorCourseForm
@@ -16,7 +16,7 @@ def test_course_email_form(self):
         """
             Tests the CourseEmailForm with one valid and one invalid input dataset.
         """
-        course = course_with_responsible_and_editor()
+        course = create_course_with_responsible_and_editor()
         mommy.make(Contribution, course=course)
         data = {"body": "wat", "subject": "some subject", "recipients": [EmailTemplate.DUE_PARTICIPANTS]}
         form = CourseEmailForm(course=course, data=data)