'Test that user could attach to the problem only libraries that he has access (or which were created by him).
This test was created on the basis of bug described in the pull requests on github:
https://github.com/edx/edx-platform/pull/11331
https://github.com/edx/edx-platform/pull/11611'

def test_studio_user_permissions(self):

    self._create_library(org='admin_org_1', library='lib_adm_1', display_name='admin_lib_1')
    self._create_library(org='admin_org_2', library='lib_adm_2', display_name='admin_lib_2')
    self._login_as_non_staff_user()
    self._create_library(org='staff_org_1', library='lib_staff_1', display_name='staff_lib_1')
    self._create_library(org='staff_org_2', library='lib_staff_2', display_name='staff_lib_2')
    with modulestore().default_store(ModuleStoreEnum.Type.split):
        course = CourseFactory.create()
    instructor_role = CourseInstructorRole(course.id)
    auth.add_users(self.user, instructor_role, self.non_staff_user)
    lib_block = ItemFactory.create(category='library_content', parent_location=course.location, user_id=self.non_staff_user.id, publish_item=False)
    def _get_settings_html():
        '\n                                                Helper    function    to    get    block    settings    HTML\n                                                Used    to    check    the    available    libraries.\n                                                '
        edit_view_url = reverse_usage_url('xblock_view_handler', lib_block.location, {'view_name': STUDIO_VIEW})
        resp = self.client.get_json(edit_view_url)
        self.assertEquals(resp.status_code, 200)
        return parse_json(resp)['html']
    self._login_as_staff_user()
    staff_settings_html = _get_settings_html()
    self.assertIn('staff_lib_1', staff_settings_html)
    self.assertIn('staff_lib_2', staff_settings_html)
    self.assertIn('admin_lib_1', staff_settings_html)
    self.assertIn('admin_lib_2', staff_settings_html)
    self._login_as_non_staff_user()
    response = self.client.get_json(LIBRARY_REST_URL)
    staff_libs = parse_json(response)
    self.assertEquals(2, len(staff_libs))
    non_staff_settings_html = _get_settings_html()
    self.assertIn('staff_lib_1', non_staff_settings_html)
    self.assertIn('staff_lib_2', non_staff_settings_html)
    self.assertNotIn('admin_lib_1', non_staff_settings_html)
    self.assertNotIn('admin_lib_2', non_staff_settings_html)
