From 877ae91b7f7dcbcae111ad04ebbafe0826c78fe5 Mon Sep 17 00:00:00 2001
From: David Ormsbee <dave@edx.org>
Date: Fri, 31 Aug 2012 21:50:33 -0400
Subject: [PATCH] Don't show View Courseware buttons if they don't have access
 to load the courseware

---
 common/djangoapps/student/views.py     | 6 +++++-
 lms/djangoapps/courseware/views.py     | 6 +++++-
 lms/templates/dashboard.html           | 4 +++-
 lms/templates/portal/course_about.html | 5 ++++-
 4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py
index ce15a2a0031..27adf485f0b 100644
--- a/common/djangoapps/student/views.py
+++ b/common/djangoapps/student/views.py
@@ -131,10 +131,14 @@ def dashboard(request):
         staff_access = True
         errored_courses = modulestore().get_errored_courses()
 
+    show_courseware_links_for = frozenset(course.id for course in courses
+                                          if has_access(request.user, course, 'load'))
+
     context = {'courses': courses,
                'message': message,
                'staff_access': staff_access,
-               'errored_courses': errored_courses,}
+               'errored_courses': errored_courses,
+               'show_courseware_links_for' : show_courseware_links_for}
 
     return render_to_response('dashboard.html', context)
 
diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py
index 6122ebd3333..71ec687cf67 100644
--- a/lms/djangoapps/courseware/views.py
+++ b/lms/djangoapps/courseware/views.py
@@ -264,7 +264,11 @@ def registered_for_course(course, user):
 def course_about(request, course_id):
     course = get_course_with_access(request.user, course_id, 'see_exists')
     registered = registered_for_course(course, request.user)
-    return render_to_response('portal/course_about.html', {'course': course, 'registered': registered})
+    show_courseware_link = has_access(request.user, course, 'load')
+    return render_to_response('portal/course_about.html',
+                              {'course': course,
+                               'registered': registered, 
+                               'show_courseware_link' : show_courseware_link})
 
 
 @ensure_csrf_cookie
diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html
index 0f9c26611b5..6be72277cca 100644
--- a/lms/templates/dashboard.html
+++ b/lms/templates/dashboard.html
@@ -87,7 +87,9 @@
               <section class="course-status">
                 <p>Class Starts - <span>${course.start_date_text}</span></p>
               </section>
-              <p class="enter-course">View Courseware</p>
+              % if course.id in show_courseware_links_for:
+                <p class="enter-course">View Courseware</p>
+              % endif
             </section>
           </a>
         </article>
diff --git a/lms/templates/portal/course_about.html b/lms/templates/portal/course_about.html
index bff24d597a1..d6c731431e3 100644
--- a/lms/templates/portal/course_about.html
+++ b/lms/templates/portal/course_about.html
@@ -74,7 +74,10 @@
 	        %if show_link:
                 <a href="${course_target}">
                 %endif
-                <span class="register disabled">You are registered for this course (${course.number})</span> <strong>View Courseware</strong>
+                <span class="register disabled">You are registered for this course (${course.number})</span>
+                % if show_courseware_link:
+                  <strong>View Courseware</strong>
+                % endif
 	        %if show_link:
                 </a>
                 %endif
-- 
GitLab