From 9f770ef9214f1c9c8e5e22d3f5267387e1b448a0 Mon Sep 17 00:00:00 2001 From: Bridger Maxwell <bridgeyman@gmail.com> Date: Tue, 14 Aug 2012 19:16:45 -0400 Subject: [PATCH] Visiting the wiki from a course you aren't in does a redirect to the regular wiki. --- lms/djangoapps/course_wiki/course_nav.py | 24 ++++++++++++++++++++++-- lms/urls.py | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/course_wiki/course_nav.py b/lms/djangoapps/course_wiki/course_nav.py index 776f3f9..51158cf 100644 --- a/lms/djangoapps/course_wiki/course_nav.py +++ b/lms/djangoapps/course_wiki/course_nav.py @@ -14,6 +14,10 @@ class Middleware(object): If it intercepts a request for /wiki/.. that has a referrer in the form /courses/course_id/... it will redirect the user to the page /courses/course_id/wiki/... + + It is also possible that someone followed a link leading to a course + that they don't have access to. In this case, we redirect them to the + same page on the regular wiki. """ def process_request(self, request): @@ -37,11 +41,27 @@ class Middleware(object): # See if we are able to view the course. If we are, redirect to it try: course = check_course(request.user, course_id) - return redirect("/courses/" + course.id + "/view_wiki/" + path_match.group('wiki_path') ) + return redirect("/courses/" + course.id + "/wiki/" + path_match.group('wiki_path') ) except Http404: # Even though we came from the course, we can't see it. So don't worry about it. pass + + else: + # It is also possible we are going to a course wiki view, but we + # don't have permission to see the course! + course_match = re.match(r'/courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/wiki/(?P<wiki_path>.*|)$', request.path) + if course_match: + course_id = course_match.group('course_id') + # See if we are able to view the course. If we aren't, redirect to regular wiki + try: + course = check_course(request.user, course_id) + # Good, we can see the course. Carry on + return None + except Http404: + # We can't see the course, so redirect to the regular wiki + return redirect("/wiki/" + course_match.group('wiki_path')) + return None @@ -54,7 +74,7 @@ def context_processor(request): bar to be shown. """ - match = re.match(r'^/courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/view_wiki(?P<wiki_path>.*|)', request.path) + match = re.match(r'^/courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/wiki(?P<wiki_path>.*|)', request.path) if match: course_id = match.group('course_id') diff --git a/lms/urls.py b/lms/urls.py index 59503dc..14e0fa0 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -172,9 +172,9 @@ if settings.WIKI_ENABLED: # These urls are for viewing the wiki in the context of a course. They should # never be returned by a reverse() so they come after the other url patterns - url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/wiki/?$', + url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/course_wiki/?$', 'course_wiki.views.course_wiki_redirect', name="course_wiki"), - url(r'^courses/(?:[^/]+/[^/]+/[^/]+)/view_wiki/', include(wiki_pattern())), + url(r'^courses/(?:[^/]+/[^/]+/[^/]+)/wiki/', include(wiki_pattern())), ) if settings.QUICKEDIT: -- libgit2 0.26.0