def grant(request): if request.method == 'GET': name = request.GET.get('name') permission = request.GET.get('permission') grant_permission(User.objects.get(username=name), permission) return HttpResponseRedirect('/home') else: return HttpResponseForbidden()
def create(self,validated_data): user = User.objects.create_user(**validated_data) profile = Profile() assign_role(user,'customer') grant_permission(user,CREATE_RIDE) grant_permission(user,VIEW_RIDE_HISTORY) profile.user = user profile.save() return user
def grant_all(request): if request.method == 'GET': role = request.GET.get('role') permission = request.GET.get('permission') All = User.objects.all() for each in All: if (has_role(each, role) and not each.is_superuser): grant_permission(each, permission) return HttpResponseRedirect('/home') else: return HttpResponseForbidden()
def test_remove_role_reinstates_permissions_correctly_scenario_5(self): """ Initial Roles: Doctor Surgeon Actions: Grant permission: operate Remove role: Surgeon Expected resulting permission: enter_surgery_room = False operate = True """ assign_role(self.user, self.Doctor) assign_role(self.user, self.Surgeon) grant_permission(self.user, self.operate) remove_role(self.user, self.Surgeon) self.assertFalse(has_permission(self.user, self.enter_surgery_room)) self.assertFalse(has_permission(self.user, self.operate))
def test_not_allowed_permission_multiple_roles(self): user = self.user ShoRole3.assign_role_to_user(self.user) with self.assertRaises(RolePermissionScopeException): grant_permission(user, 'permission1')
def test_not_allowed_permission(self): user = self.user with self.assertRaises(RolePermissionScopeException): grant_permission(user, 'permission1')
def test_grat_granted_permission(self): user = self.user grant_permission(user, 'permission3') self.assertTrue(has_permission(user, 'permission3'))
def grant(name, perm): grant_permission(User.objects.get(username=name), perm)
def grant_all(role, perm): All = User.objects.all() for each in All: if (has_role(each, role) and not each.is_superuser): grant_permission(each, perm)