wag-managment-api-service-v.../a_project_files/drafts_and_notes/evyos-draft/evyos-draft-models-05-07-24

211 lines
5.9 KiB
Plaintext

postgres EndpointRestriction(CrudCollection):
"""
Initiliaze Endpoint Restriction on default
"""
__tablename__ = "endpoint_restriction"
__exclude__fields__ = []
endpoint_name = mapped_column(String, server_default="")
endpoint_method = mapped_column(String, server_default="")
endpoint_desc = mapped_column(String, server_default="")
endpoint_code = mapped_column(String, server_default="", unique=True)
endpoint_priority = mapped_column(SmallInteger, server_default="0")
postgres Priority(CrudCollection):
"""
Initiliaze at api roles on default
4ex.
{
"0": "User",
"4": "Owner",
"8": "Tenant",
"12": "Freelancer",
"16": "Tech",
"78": "Super User",
"96": "Database Manager",
"97": "Network Manager",
"98": "Application Manager",
"99": "System Admin",
}
"""
__tablename__ = "priority"
__exclude__fields__ = []
priority_code = mapped_column(SmallInteger, server_default="0")
priority_desc = mapped_column(String, server_default="")
postgres User(CrudCollection):
"""
Application User frame to connect to api with assigned token based HTTP connection
"""
__tablename__ = "user"
__exclude__fields__ = [
"hash_password",
"password_token",
"expiry_begins"
]
user_tag = mapped_column(String(64), server_default="", comment="User Tag")
email = mapped_column(String(128), server_default="")
phone_number = mapped_column(String, server_default="")
avatar = mapped_column(String, server_default="")
hash_password = mapped_column(String(256), server_default="")
password_token = mapped_column(String(256), server_default="")
remember_me = mapped_column(Boolean, server_default="0")
expires_day = mapped_column(Integer, server_default=env.PASSWORD_EXPIRE_DAY, comment="Password Expires in Days") // Password must be changed by user in [expires_day] days
expiry_begins = mapped_column(TIMESTAMP, server_default=func.now())
priority_id = mapped_column(ForeignKey("priority.id"), nullable=False)
person_id = mapped_column(ForeignKey("people.id"), nullable=False)
priority: Mapped["Priority"] = relationship("Priority", back_populates="user", foreign_keys=[priority_id])
@property def expiry_ends():
return expiry_begins + expires_day
@property
def is_super_user():
return bool(self.priority.priority_code == 78)
@property
def is_user():
return bool(self.priority.priority_code == 0)
postgres Person(CrudCollection):
"""
People that are related to users in application
"""
__tablename__ = "person"
__exclude__fields__ = []
firstname = mapped_column(String(24), nullable=False, comment="First Name")
surname = mapped_column(String(24), nullable=False, comment="Surname")
middle_name = mapped_column(String(16), server_default="")
sex_code = mapped_column(String(1), nullable=False, comment="Sex Code")
person_ref = Mapped[str] = mapped_column(String(24), server_default="")
person_tag = mapped_column(String(64), server_default="")
// ENCRYPT DATA
father_name = mapped_column(String(24), server_default="")
mother_name = mapped_column(String(24), server_default="")
country_code = mapped_column(String(4), server_default="TR")
national_identity_id = mapped_column(String(48), server_default="")
birth_place = mapped_column(String(24), server_default="")
birth_date = mapped_column(TIMESTAMP, server_default="1900-01-01")
tax_no = mapped_column(String(48), server_default="")
// ENCRYPT DATA
class Company(CrudCollection):
"""
Company class based on declarative_base and CrudCollection via session
formal_name = Government register name by offical
public_name = Public registered name by User
nick_name = Search by nickname, commercial_type = Tüzel veya birey
"""
__tablename__ = "company"
__exclude__fields__ = ["is_blacklist", "is_commercial"]
formal_name = mapped_column(String(64), nullable=False, comment="Formal Name")
company_type = mapped_column(String(1), nullable=False, comment="Company Type")
commercial_type = mapped_column(
String(5), nullable=False, comment="Commercial Type"
)
tax_no = mapped_column(
String(48), index=True, unique=True, nullable=False, comment="Tax No"
)
public_name = mapped_column(String(64))
nick_name = mapped_column(String(64))
default_lang_type = mapped_column(String(5), server_default="TR")
default_money_type = mapped_column(String(5), server_default="TL")
is_commercial = mapped_column(Boolean, server_default="False")
is_blacklist = mapped_column(Boolean, server_default="False")
official_address_id = mapped_column(ForeignKey("address.id"))
parent_id = mapped_column(ForeignKey("company.id"))
# Rule of Mongo Collection Creation #
// To avoid data load for no-sql storage all collection must be created in a pattern of
// mongo_collection_name = str(Company.uu_id()) + str(storage_reasoning) 4ex. : mongo_collection_name = str(Company.uu_id()) + str('UserPasswordHistory')
// MongoCollectionBase = str(Company.uu_id())
[Company][info] -> [Company][info] -> [Company][info] -> [Company][info]
Mongo MongoCollectionBase + Access:
{
}
Mongo MongoCollectionBase + Domain:
{
"user_id": 1,
"domain_tag": {
...
},
}
!! ADD domain_tag for user to name this domain -> so user can use domain with device that is saved
Mongo MongoCollectionBase + PasswordHistory:
{
"user_id": 1,
"password_history":
[
...{
"password_hashed": "", // String
"tmstp": "" // TMSTP,
}
],
"access_history_detail": device_single_history
}
Mongo MongoCollectionBase + AccessHistory:
// Last 60 History of a user login to application
// ! add function retrieve_last()
{
"access_history":
[
...{
"platform": "", // String
"agent": "", // String
"last_seen": "", // TMSTP
"remote_addr": "", // String
"geo_location": "", // String
"detail": {} // From ip retrieve api data
}
],
}