auth service up running

This commit is contained in:
2025-01-10 14:15:35 +03:00
parent 4eb95e4d9c
commit 03accfed1b
23 changed files with 457 additions and 317 deletions

View File

@@ -1,35 +1,54 @@
from api_library.date_time_actions.date_functions import system_arrow
from api_configs import Auth, ApiStatic, RelationAccess
from datetime import timedelta
from typing import Optional, List
from fastapi import HTTPException
from databases.sql_models.core_mixin import CrudCollection
from databases.extensions import SelectAction, SelectActionWithEmployee
from databases.extensions.auth import UserLoginModule
from sqlalchemy import (
String,
Boolean,
TIMESTAMP,
ForeignKey,
func,
Numeric,
Index,
BigInteger,
Integer,
Boolean,
ForeignKey,
Index,
TIMESTAMP,
func,
Text,
BigInteger,
Numeric,
or_,
)
from sqlalchemy.orm import mapped_column, relationship, Mapped
from api_library.date_time_actions.date_functions import system_arrow
from api_configs import Auth, ApiStatic, RelationAccess
from databases.sql_models.core_mixin import CrudCollection
from databases.extensions import SelectAction, SelectActionWithEmployee
from databases.extensions.auth import UserLoginModule
from api_validations.validations_request import InsertUsers, InsertPerson
from databases.language_models.identity.identity import (
UsersTokensLanguageModel,
UsersLanguageModel,
PeopleLanguageModel,
RelationshipDutyPeopleLanguageModel,
RelationshipEmployee2PostCodeLanguageModel,
AddressPostcodeLanguageModel,
AddressesLanguageModel,
AddressGeographicLocationsLanguageModel,
AddressCountryLanguageModel,
AddressStateLanguageModel,
AddressCityLanguageModel,
AddressDistrictLanguageModel,
AddressLocalityLanguageModel,
AddressNeighborhoodLanguageModel,
AddressStreetLanguageModel,
OccupantTypesLanguageModel,
ContractsLanguageModel,
)
class UsersTokens(CrudCollection):
__tablename__ = "users_tokens"
__exclude__fields__ = []
__language_model__ = UsersTokensLanguageModel
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
@@ -56,6 +75,7 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
"expiry_begins",
"related_company",
]
__language_model__ = UsersLanguageModel
user_tag: Mapped[str] = mapped_column(
String(64), server_default="", comment="Unique tag for the user", index=True
@@ -85,10 +105,10 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
Boolean, server_default="0", comment="Flag to remember user login"
)
password_expires_day: Mapped[str] = mapped_column(
password_expires_day: Mapped[int] = mapped_column(
"expires_day",
String,
server_default=str(Auth.PASSWORD_EXPIRE_DAY),
Integer,
server_default=str(Auth.PASSWORD_EXPIRE_DAY.days),
comment="Password expires in days",
)
password_expiry_begins: Mapped[TIMESTAMP] = mapped_column(
@@ -233,6 +253,7 @@ class RelationshipDutyPeople(CrudCollection):
__tablename__ = "relationship_duty_people"
__exclude__fields__ = []
__access_by__ = RelationAccess.SuperAccessList
__language_model__ = RelationshipDutyPeopleLanguageModel
company_id: Mapped[int] = mapped_column(
ForeignKey("companies.id"), nullable=False
@@ -285,6 +306,7 @@ class People(CrudCollection, SelectAction):
"birth_date",
"tax_no",
]
__language_model__ = PeopleLanguageModel
firstname: Mapped[str] = mapped_column(
String, nullable=False, comment="First name of the person"
@@ -395,6 +417,7 @@ class RelationshipEmployee2PostCode(CrudCollection):
__tablename__ = "relationship_employee2postcode"
__exclude__fields__ = []
__include__fields__ = []
__language_model__ = RelationshipEmployee2PostCodeLanguageModel
company_id: Mapped[int] = mapped_column(
ForeignKey("companies.id"), nullable=True
@@ -421,6 +444,7 @@ class AddressPostcode(CrudCollection, SelectActionWithEmployee):
__exclude__fields__ = []
__access_by__ = []
__many__table__ = RelationshipEmployee2PostCode
__language_model__ = AddressPostcodeLanguageModel
street_id: Mapped[int] = mapped_column(ForeignKey("address_street.id"))
street_uu_id: Mapped[str] = mapped_column(
@@ -440,6 +464,7 @@ class Addresses(CrudCollection):
__tablename__ = "addresses"
__exclude__fields__ = []
__language_model__ = AddressesLanguageModel
build_number: Mapped[str] = mapped_column(
String(24), nullable=False, comment="Build Number"
@@ -537,6 +562,7 @@ class AddressGeographicLocations(CrudCollection):
__tablename__ = "address_geographic_locations"
__exclude__fields__ = []
__language_model__ = AddressGeographicLocationsLanguageModel
geo_table: Mapped[str] = mapped_column(
String, nullable=False, comment="Address Table Name"
@@ -588,6 +614,7 @@ class AddressCountry(CrudCollection):
__tablename__ = "address_country"
__exclude__fields__ = []
__language_model__ = AddressCountryLanguageModel
country_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Country Code"
@@ -619,6 +646,7 @@ class AddressState(CrudCollection):
__tablename__ = "address_state"
__exclude__fields__ = []
__language_model__ = AddressStateLanguageModel
state_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="State Code"
@@ -662,6 +690,7 @@ class AddressCity(CrudCollection):
__tablename__ = "address_city"
__exclude__fields__ = []
__language_model__ = AddressCityLanguageModel
city_code: Mapped[str] = mapped_column(
String(24), nullable=False, comment="City Code"
@@ -703,6 +732,7 @@ class AddressDistrict(CrudCollection):
__tablename__ = "address_district"
__exclude__fields__ = []
__language_model__ = AddressDistrictLanguageModel
district_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="District Code"
@@ -745,6 +775,7 @@ class AddressLocality(CrudCollection):
__tablename__ = "address_locality"
__exclude__fields__ = []
__language_model__ = AddressLocalityLanguageModel
locality_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Locality Code"
@@ -789,6 +820,7 @@ class AddressNeighborhood(CrudCollection):
__tablename__ = "address_neighborhood"
__exclude__fields__ = []
__language_model__ = AddressNeighborhoodLanguageModel
neighborhood_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Neighborhood Code"
@@ -839,6 +871,7 @@ class AddressStreet(CrudCollection):
__tablename__ = "address_street"
__exclude__fields__ = []
__language_model__ = AddressStreetLanguageModel
street_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Street Code"
@@ -940,6 +973,7 @@ class OccupantTypes(CrudCollection):
__tablename__ = "occupant_types"
__exclude__fields__ = []
__language_model__ = OccupantTypesLanguageModel
occupant_type: Mapped[str] = mapped_column(
String, nullable=False, comment="Occupant Type"
@@ -971,6 +1005,7 @@ class Contracts(CrudCollection):
__tablename__ = "contracts"
__exclude__fields__ = []
__language_model__ = ContractsLanguageModel
contract_type: Mapped[str] = mapped_column(
String(5),
@@ -1021,49 +1056,3 @@ class Contracts(CrudCollection):
Index("_contract_ndx_01", contract_code, unique=True),
{"comment": "Contract Information"},
)
# def selected_employee_and_duty_details(self, selected_duty_uu_id):
# from database_sql_models import (
# Companies,
# Employees,
# Duties,
# Departments,
# )
#
# found_person = People.find_one(id=self.person_id)
# found_employee = Employees.find_one(
# people_id=found_person.id, is_confirmed=True
# )
# found_duty = Duties.find_one(uu_id=selected_duty_uu_id)
# found_department = Departments.find_one(id=found_duty.department_id)
# found_company = Companies.find_one(id=found_department.company_id)
# return {
# "duty_list": {
# "duty_id": found_duty.id,
# "duty_uu_id": found_duty.uu_id.__str__(),
# "duty_code": found_duty.duty_code,
# "duty_name": found_duty.duty_name,
# "duty_description": found_duty.duty_description,
# },
# "employee_list": {
# "employee_id": found_employee.id,
# "employee_uu_id": found_employee.uu_id.__str__(),
# "people_id": found_employee.people_id,
# "duty_id": found_employee.duty_id,
# "employee_description": found_employee.employee_description,
# },
# "department_list": {
# "department_id": found_department.id,
# "department_uu_id": found_department.uu_id.__str__(),
# "company_id": found_department.company_id,
# "department_name": found_department.department_name,
# "department_description": found_department.department_description,
# },
# "companies_list": {
# "company_id": found_company.id,
# "company_uu_id": found_company.uu_id.__str__(),
# "formal_name": found_company.formal_name,
# "company_tag": found_company.company_tag,
# },
# }