Exemple #1
0
 def assert_standard_role_permissions(self, expected_bool, program=None):
     """
     Helper function to assert role and permissions assignment
     """
     assert isinstance(expected_bool, bool)
     assert has_role(self.user, 'staff') is expected_bool
     assert has_permission(self.user, 'can_advance_search') is expected_bool
     assert has_object_permission('can_advance_search', self.user, program or self.program) is expected_bool
Exemple #2
0
def get_advance_searchable_programs(user):
    """
    Helper function to retrieve all the programs where the user is allowed to search

    Args:
        user (User): Django user instance
    Returns:
        list: list of courses.models.Program instances
    """
    user_role_program = Role.objects.filter(user=user)
    programs = [
        role.program for role in user_role_program
        if has_object_permission('can_advance_search', user, role.program)
    ]
    return programs
def has_permission_template_tag(context, permission, obj, user=None):
    if not user:
        user = context['user']

    return has_object_permission(permission, user, obj)
    def test_does_not_have_object_permission(self):
        user = self.user

        self.assertFalse(has_object_permission('obj_checker', user, False))
    def test_has_object_permission(self):
        user = self.user

        self.assertTrue(has_object_permission('obj_checker', user, True))
Exemple #6
0
    def test_does_not_have_object_permission(self):
        user = self.user

        self.assertFalse(has_object_permission('obj_checker', user, False))
Exemple #7
0
    def test_has_object_permission(self):
        user = self.user

        self.assertTrue(has_object_permission('obj_checker', user, True))
Exemple #8
0
def has_permission_template_tag(context, permission, obj, user=None):
    if not user:
        user = context['user']

    return has_object_permission(permission, user, obj)