From 24d63f25cec5ade6fe5adef01340f8838aca4b67 Mon Sep 17 00:00:00 2001
From: DawoudSheraz <dawoud.sheraz@arbisoft.com>
Date: Wed, 13 Feb 2019 15:19:32 +0500
Subject: [PATCH] add staff exemption for content access in library access

---
 .../transformers/library_content.py              |  6 ++++--
 .../transformers/tests/test_library_content.py   | 16 ++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lms/djangoapps/course_blocks/transformers/library_content.py b/lms/djangoapps/course_blocks/transformers/library_content.py
index b92b58dbebf..e566a1a0c73 100644
--- a/lms/djangoapps/course_blocks/transformers/library_content.py
+++ b/lms/djangoapps/course_blocks/transformers/library_content.py
@@ -22,7 +22,7 @@ class ContentLibraryTransformer(FilteringTransformerMixin, BlockStructureTransfo
     blocks within a library_content module to which a user should not
     have access.
 
-    Staff users are *not* exempted from library content pathways.
+    Staff users are to exempted from library content pathways.
     """
     WRITE_VERSION = 1
     READ_VERSION = 1
@@ -123,8 +123,10 @@ class ContentLibraryTransformer(FilteringTransformerMixin, BlockStructureTransfo
             Return True if selected block should be removed.
 
             Block is removed if it is part of library_content, but has
-            not been selected for current user.
+            not been selected for current user, with staff as an exemption.
             """
+            if usage_info.has_staff_access:
+                return False
             if block_key not in all_library_children:
                 return False
             if block_key in all_selected_children:
diff --git a/lms/djangoapps/course_blocks/transformers/tests/test_library_content.py b/lms/djangoapps/course_blocks/transformers/tests/test_library_content.py
index 3c4db113e97..44b0c1ea927 100644
--- a/lms/djangoapps/course_blocks/transformers/tests/test_library_content.py
+++ b/lms/djangoapps/course_blocks/transformers/tests/test_library_content.py
@@ -164,3 +164,19 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
                 ),
                 u"Expected 'selected' equality failed in iteration {}.".format(i)
             )
+
+    def test_staff_access_to_library_content(self):
+        """
+        To verify that staff member has access to all the library content blocks.
+
+        Scenario: Given a staff member in a course with library content
+        when data is transformed by LibraryContentTransformer
+        none of the unassigned block is removed from the access list
+        and staff member will have access to all the blocks
+        """
+        transformed_blocks = get_course_blocks(
+            self.staff,
+            self.course.location,
+            transformers=self.transformers
+        )
+        self.assertEqual(len(list(transformed_blocks.get_block_keys())), len(self.blocks))
-- 
GitLab