def test_containing_schema(self): p = permissions.SimpleSchemaPermission(None, None, readable_list=['a/b/c'], editable_list=['d/e/f']) self.assertTrue(p.can_view('a')) self.assertTrue(p.can_view('a/b')) self.assertTrue(p.can_view('a/b/c')) self.assertFalse(p.can_edit('a')) self.assertFalse(p.can_edit('a/b')) self.assertFalse(p.can_edit('a/b/c')) self.assertTrue(p.can_view('d')) self.assertTrue(p.can_view('d/e')) self.assertTrue(p.can_view('d/e/f')) self.assertTrue(p.can_edit('d')) self.assertTrue(p.can_edit('d/e')) self.assertTrue(p.can_edit('d/e/f')) self.assertFalse(p.can_view('g')) self.assertFalse(p.can_view('g/h')) self.assertFalse(p.can_view('g/h/i')) self.assertFalse(p.can_edit('g')) self.assertFalse(p.can_edit('g/h')) self.assertFalse(p.can_edit('g/h/i'))
def test_read_write_some(self): p = permissions.SimpleSchemaPermission(None, None, readable_list=['a'], editable_list=['a']) self.assertTrue(p.can_view('a')) self.assertTrue(p.can_edit('a')) self.assertFalse(p.can_view('b')) self.assertFalse(p.can_edit('b'))
def notify_module_enabled(cls): roles.Roles.register_permissions(cls.custom_module, cls.permissions_callback) permissions.SchemaPermissionRegistry.add( cls.PERMISSION_SCOPE, permissions.SimpleSchemaPermission(cls.custom_module, cls.PERMISSION_NAME, readable_list=['a', 'b'], editable_list=['a'])) permissions.SchemaPermissionRegistry.add( cls.PERMISSION_SCOPE, permissions.CourseAdminSchemaPermission())
def on_module_enabled(courses_custom_module, course_permissions): global custom_module # pylint: disable=global-statement custom_module = courses_custom_module course_permissions.append( roles.Permission(constants.TEACHING_ASSISTANT_PERMISSION, 'Can modify assessment due dates and scoring.')) permissions.SchemaPermissionRegistry.add( constants.SCOPE_ASSESSMENT, permissions.SimpleSchemaPermission( custom_module, constants.TEACHING_ASSISTANT_PERMISSION, readable_list=[ 'assessment/type', 'assessment/title', 'assessment/description', ], editable_list=[ 'assessment/%s' % resources_display.workflow_key(courses.SINGLE_SUBMISSION_KEY), 'assessment/%s' % resources_display.workflow_key( courses.SUBMISSION_DUE_DATE_KEY), 'assessment/%s' % resources_display.workflow_key(courses.SHOW_FEEDBACK_KEY), 'assessment/%s' % resources_display.workflow_key(courses.GRADER_KEY), 'review_opts/%s' % resources_display.workflow_key(courses.MATCHER_KEY), 'assessment/%s' % resources_display.workflow_key(courses.REVIEW_DUE_DATE_KEY), 'assessment/%s' % resources_display.workflow_key(courses.REVIEW_MIN_COUNT_KEY), 'assessment/%s' % resources_display.workflow_key(courses.REVIEW_WINDOW_MINS_KEY), ]))
def test_write_even_one_with_all_writable(self): p = permissions.SimpleSchemaPermission(None, None, all_writable=True) self.assertTrue(p.can_edit())
def test_write_even_one_with_one_writable(self): p = permissions.SimpleSchemaPermission(None, None, editable_list=['a']) self.assertTrue(p.can_edit())
def test_read_even_one_with_all_readable(self): p = permissions.SimpleSchemaPermission(None, None, all_readable=True) self.assertTrue(p.can_view())
def test_read_even_one_with_one_readable(self): p = permissions.SimpleSchemaPermission(None, None, readable_list=['a']) self.assertTrue(p.can_view())
def test_read_even_one_with_no_readable(self): p = permissions.SimpleSchemaPermission(None, None) self.assertFalse(p.can_view())
def test_write_any(self): p = permissions.SimpleSchemaPermission(None, None, all_writable=True) self.assertTrue(p.can_view('a')) self.assertTrue(p.can_edit('a')) self.assertTrue(p.can_view('b')) self.assertTrue(p.can_edit('b'))
def test_writability_implies_readability(self): p = permissions.SimpleSchemaPermission(None, None, editable_list=['a']) self.assertTrue(p.can_view('a')) self.assertTrue(p.can_edit('a')) self.assertFalse(p.can_view('b')) self.assertFalse(p.can_edit('b'))
def test_no_args_equals_no_permissions(self): p = permissions.SimpleSchemaPermission(None, None) self.assertFalse(p.can_view('a')) self.assertFalse(p.can_edit('a'))