def check_policy_to_enter_any_area(user: User): """ Checks the area access policy for a user. """ if not user.is_active: raise InactiveUserError(user=user) if user.active_project_count() < 1: raise NoActiveProjectsForUserError(user=user) if user.access_expiration is not None and user.access_expiration < date.today(): raise PhysicalAccessExpiredUserError(user=user) user_has_access_to_at_least_one_area = user.accessible_access_levels().exists() if not user_has_access_to_at_least_one_area: raise NoPhysicalAccessUserError(user=user)
def check_policy_to_enter_any_area(user: User): """ Checks the area access policy for a user. """ if not user.is_active: raise InactiveUserError(user=user) if user.active_project_count() < 1: raise NoActiveProjectsForUserError(user=user) if user.access_expiration is not None and user.access_expiration < date.today(): raise PhysicalAccessExpiredUserError(user=user) user_has_access_to_at_least_one_area = user.physical_access_levels.all().exists() staff_has_access_to_at_least_one_area = user.is_staff and PhysicalAccessLevel.objects.filter(allow_staff_access=True).exists() if not (user_has_access_to_at_least_one_area or staff_has_access_to_at_least_one_area): raise NoPhysicalAccessUserError(user=user)