Repository: inducer/relate

Issue:
After pretend-facility, impersonate disappears from menu



Discussion:

Resolving patch:
diff --git a/course/templatetags/coursetags.py b/course/templatetags/coursetags.py
--- a/course/templatetags/coursetags.py
+++ b/course/templatetags/coursetags.py
@@ -115,6 +115,28 @@ def has_permission(participation, arg):
 # }}}
 
 
+@register.filter(name='may_set_fake_time')
+def may_set_fake_time(user):
+    """
+    Check if a user may set fake time.
+    :param user: a :class:`accounts.User:` instance
+    :return: a :class:`bool`
+    """
+    from course.views import may_set_fake_time as msf
+    return msf(user)
+
+
+@register.filter(name='may_set_pretend_facility')
+def may_set_pretend_facility(user):
+    """
+    Check if a user may set pretend_facility
+    :param user: a :class:`accounts.User:` instance
+    :return: a :class:`bool`
+    """
+    from course.views import may_set_pretend_facility as mspf
+    return mspf(user)
+
+
 @register.filter(name='commit_message_as_html')
 def commit_message_as_html(commit_sha, repo):
     from course.versioning import _get_commit_message_as_html


Test patch:
diff --git a/tests/test_views.py b/tests/test_views.py
--- a/tests/test_views.py
+++ b/tests/test_views.py
@@ -58,6 +58,10 @@ class TestSetFakeTime(SingleCourseTestMixin, TestCase):
 
     def test_set_fake_time_by_anonymous(self):
         with self.temporarily_switch_to_user(None):
+            # the faking url is not rendered in template
+            resp = self.c.get(self.course_page_url)
+            self.assertNotContains(resp, self.get_fake_time_url())
+
             resp = self.get_set_fake_time()
             self.assertEqual(resp.status_code, 302)
 
@@ -67,6 +71,10 @@ def test_set_fake_time_by_anonymous(self):
 
     def test_set_fake_time_no_pperm(self):
         with self.temporarily_switch_to_user(self.student_participation.user):
+            # the faking url is not rendered in template
+            resp = self.c.get(self.course_page_url)
+            self.assertNotContains(resp, self.get_fake_time_url())
+
             resp = self.get_set_fake_time()
             self.assertEqual(resp.status_code, 403)
 
@@ -76,6 +84,10 @@ def test_set_fake_time_no_pperm(self):
 
     def test_set_fake_time_by_instructor(self):
         with self.temporarily_switch_to_user(self.instructor_participation.user):
+            # the faking url is rendered in template
+            resp = self.c.get(self.course_page_url)
+            self.assertContains(resp, self.get_fake_time_url())
+
             resp = self.get_set_fake_time()
             self.assertEqual(resp.status_code, 200)
 
@@ -95,6 +107,9 @@ def test_set_fake_time_by_instructor_when_impersonating(self):
             self.assertEqual(resp.status_code, 200)
 
             self.post_impersonate(impersonatee=self.student_participation.user)
+            # the faking url is rendered in template
+            resp = self.c.get(self.course_page_url)
+            self.assertContains(resp, self.get_fake_time_url())
 
             # set fake time
             resp = self.post_set_fake_time(self.set_fake_time_data)
@@ -120,6 +135,10 @@ class TestSetPretendFacilities(SingleCourseTestMixin, TestCase):
 
     def test_pretend_facilities_by_anonymous(self):
         with self.temporarily_switch_to_user(None):
+            # the pretending url is not rendered in template
+            resp = self.c.get(self.course_page_url)
+            self.assertNotContains(resp, self.get_set_pretend_facilities_url())
+
             resp = self.get_set_pretend_facilities()
             self.assertEqual(resp.status_code, 302)
 
@@ -130,6 +149,10 @@ def test_pretend_facilities_by_anonymous(self):
 
     def test_pretend_facilities_no_pperm(self):
         with self.temporarily_switch_to_user(self.student_participation.user):
+            # the pretending url is not rendered in template
+            resp = self.c.get(self.course_page_url)
+            self.assertNotContains(resp, self.get_set_pretend_facilities_url())
+
             resp = self.get_set_pretend_facilities()
             self.assertEqual(resp.status_code, 403)
 
@@ -140,6 +163,10 @@ def test_pretend_facilities_no_pperm(self):
 
     def test_pretend_facilities_by_instructor(self):
         with self.temporarily_switch_to_user(self.instructor_participation.user):
+            # the pretending url is rendered in template
+            resp = self.c.get(self.course_page_url)
+            self.assertContains(resp, self.get_set_pretend_facilities_url())
+
             resp = self.get_set_pretend_facilities()
             self.assertEqual(resp.status_code, 200)
 
@@ -159,6 +186,10 @@ def test_pretend_facilities_by_instructor_when_impersonating(self):
 
             self.post_impersonate(impersonatee=self.student_participation.user)
 
+            # the pretending url is rendered in template
+            resp = self.c.get(self.course_page_url)
+            self.assertContains(resp, self.get_set_pretend_facilities_url())
+
             resp = self.get_set_pretend_facilities()
             self.assertEqual(resp.status_code, 200)