Exemplo n.º 1
0
def detach_role(person_id: int, role_id: int):
    person = get(person_id)
    role = RoleService.get(role_id)
    if person.roles.filter(id=role_id).count() == 0:
        raise exceptions.RoleNotFound
    try:
        person.roles.remove(role)
    except:
        raise exceptions.PersonManageFailed
def role_deny_place(role_id: int, place_id: int) -> RoleACLEntry:
    role = RoleService.get(role_id)
    place = PlaceService.get(place_id)
    if RoleACLEntry.objects.filter(
            role=role, place=place, type=AclType.ACL_DENY).count() > 0:
        raise exceptions.AclAlreadyAdded
    try:
        return RoleACLEntry.objects.create(role=role,
                                           place=place,
                                           type=AclType.ACL_DENY)
    except:
        raise exceptions.ACLManageFailed
def get_role_acls(role_id: int) -> List[RoleACLEntry]:
    role = RoleService.get(role_id)
    try:
        return list(role.roleaclentry_set.all())
    except:
        raise exceptions.SomethingWrong