middleware and respnse models updated
This commit is contained in:
@@ -17,7 +17,10 @@ from sqlalchemy import (
|
||||
from sqlalchemy.orm import mapped_column, relationship, Mapped
|
||||
|
||||
from ApiLayers.ApiLibrary.date_time_actions.date_functions import system_arrow
|
||||
from ApiLayers.ApiLibrary.extensions.select import SelectAction, SelectActionWithEmployee
|
||||
from ApiLayers.ApiLibrary.extensions.select import (
|
||||
SelectAction,
|
||||
SelectActionWithEmployee,
|
||||
)
|
||||
|
||||
from ApiLayers.AllConfigs.Token.config import Auth
|
||||
from ApiLayers.ApiServices.Login.user_login_handler import UserLoginModule
|
||||
@@ -138,6 +141,24 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
def is_employee(self):
|
||||
return str(self.email).split("@")[1] == Auth.ACCESS_EMAIL_EXT
|
||||
|
||||
@property
|
||||
def user_type(self):
|
||||
return "Occupant" if self.is_occupant else "Employee"
|
||||
|
||||
@classmethod
|
||||
def credentials(cls):
|
||||
db_session = cls.new_session()
|
||||
person_object: People = People.filter_by_one(db=db_session, system=True, id=cls.person_id).data
|
||||
if person_object:
|
||||
return {
|
||||
"person_id": person_object.id,
|
||||
"person_uu_id": str(person_object.uu_id),
|
||||
}
|
||||
return {
|
||||
"person_id": None,
|
||||
"person_uu_id": None,
|
||||
}
|
||||
|
||||
@property
|
||||
def password_expiry_ends(self):
|
||||
"""Calculates the expiry end date based on expiry begins and expires day"""
|
||||
@@ -153,16 +174,6 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def is_super_user(self):
|
||||
"""Checks if the user is a superuser based on priority code"""
|
||||
return getattr(self.priority, "priority_code", 0) == 78
|
||||
|
||||
@property
|
||||
def is_user(self):
|
||||
"""Checks if the user is a regular user based on priority code"""
|
||||
return getattr(self.priority, "priority_code", 0) == 0
|
||||
|
||||
@classmethod
|
||||
def create_action(cls, create_user: InsertUsers, token_dict):
|
||||
db_session = cls.new_session()
|
||||
@@ -192,21 +203,7 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
created_user.reset_password_token(found_user=created_user)
|
||||
return created_user
|
||||
|
||||
@classmethod
|
||||
def credentials(cls):
|
||||
db_session = cls.new_session()
|
||||
person_object = People.filter_by_one(
|
||||
db=db_session, system=True, id=cls.person_id
|
||||
).data
|
||||
if person_object:
|
||||
return {
|
||||
"person_id": person_object.id,
|
||||
"person_uu_id": str(person_object.uu_id),
|
||||
}
|
||||
return {
|
||||
"person_id": None,
|
||||
"person_uu_id": None,
|
||||
}
|
||||
|
||||
|
||||
def get_employee_and_duty_details(self):
|
||||
from Schemas import Employees, Duties
|
||||
|
||||
Reference in New Issue
Block a user