feat: v1.7 overhaul - identity hash, triple wallet, financial ledger, and security audit system
This commit is contained in:
@@ -9,29 +9,34 @@ from app.db.base_class import Base
|
||||
class UserRole(str, enum.Enum):
|
||||
superadmin = "superadmin"
|
||||
admin = "admin"
|
||||
region_admin = "region_admin"
|
||||
country_admin = "country_admin"
|
||||
moderator = "moderator"
|
||||
sales_agent = "sales_agent"
|
||||
user = "user"
|
||||
service = "service"
|
||||
service_owner = "service_owner"
|
||||
fleet_manager = "fleet_manager"
|
||||
driver = "driver"
|
||||
|
||||
class Person(Base):
|
||||
"""
|
||||
Természetes személy identitása.
|
||||
A bot által talált személyek is ide kerülnek (is_ghost=True).
|
||||
Azonosítás: Név + Anyja neve + Születési adatok alapján.
|
||||
Természetes személy identitása. A DNS szint.
|
||||
Itt tároljuk az örök adatokat, amik nem vesznek el account törléskor.
|
||||
"""
|
||||
__tablename__ = "persons"
|
||||
__table_args__ = {"schema": "data"}
|
||||
__table_args__ = {"schema": "data", "extend_existing": True}
|
||||
|
||||
id = Column(BigInteger, primary_key=True, index=True)
|
||||
id_uuid = Column(PG_UUID(as_uuid=True), default=uuid.uuid4, unique=True, nullable=False)
|
||||
address_id = Column(PG_UUID(as_uuid=True), ForeignKey("data.addresses.id"), nullable=True)
|
||||
|
||||
# --- KRITIKUS: EGYEDI AZONOSÍTÓ HASH (Normalizált adatokból) ---
|
||||
identity_hash = Column(String(64), unique=True, index=True, nullable=True)
|
||||
|
||||
last_name = Column(String, nullable=False)
|
||||
first_name = Column(String, nullable=False)
|
||||
phone = Column(String, nullable=True)
|
||||
|
||||
# --- TERMÉSZETES AZONOSÍTÓK (Azonosításhoz, nem publikus) ---
|
||||
mothers_last_name = Column(String)
|
||||
mothers_first_name = Column(String)
|
||||
birth_place = Column(String)
|
||||
@@ -40,8 +45,14 @@ class Person(Base):
|
||||
identity_docs = Column(JSON, server_default=text("'{}'::jsonb"))
|
||||
ice_contact = Column(JSON, server_default=text("'{}'::jsonb"))
|
||||
|
||||
is_active = Column(Boolean, default=False, nullable=False)
|
||||
is_ghost = Column(Boolean, default=True, nullable=False) # Bot találta = True, Regisztrált = False
|
||||
# --- ÖRÖK ADATOK (Person szint) ---
|
||||
lifetime_xp = Column(BigInteger, server_default=text("0"))
|
||||
penalty_points = Column(Integer, server_default=text("0")) # 0-3 szint
|
||||
social_reputation = Column(Numeric(3, 2), server_default=text("1.00")) # 1.00 = 100%
|
||||
|
||||
is_sales_agent = Column(Boolean, server_default=text("false"))
|
||||
is_active = Column(Boolean, default=True, nullable=False)
|
||||
is_ghost = Column(Boolean, default=False, nullable=False)
|
||||
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
@@ -50,28 +61,39 @@ class Person(Base):
|
||||
memberships = relationship("OrganizationMember", back_populates="person")
|
||||
|
||||
class User(Base):
|
||||
"""
|
||||
Login entitás. Bármikor törölhető (GDPR), de Person-höz kötött.
|
||||
"""
|
||||
__tablename__ = "users"
|
||||
__table_args__ = {"schema": "data"}
|
||||
__table_args__ = {"schema": "data", "extend_existing": True}
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
email = Column(String, unique=True, index=True, nullable=False)
|
||||
hashed_password = Column(String, nullable=True)
|
||||
role = Column(Enum(UserRole), default=UserRole.user)
|
||||
is_active = Column(Boolean, default=False)
|
||||
is_deleted = Column(Boolean, default=False)
|
||||
|
||||
person_id = Column(BigInteger, ForeignKey("data.persons.id"), nullable=True)
|
||||
folder_slug = Column(String(12), unique=True, index=True)
|
||||
|
||||
refresh_token_hash = Column(String(255), nullable=True)
|
||||
two_factor_secret = Column(String(100), nullable=True)
|
||||
two_factor_enabled = Column(Boolean, default=False)
|
||||
# --- ELŐFIZETÉS ÉS VIP (Időkorlátos logika) ---
|
||||
subscription_plan = Column(String(30), server_default=text("'FREE'"))
|
||||
subscription_expires_at = Column(DateTime(timezone=True), nullable=True)
|
||||
is_vip = Column(Boolean, server_default=text("false"))
|
||||
|
||||
# --- REFERRAL ÉS SALES (Üzletkötői hálózat) ---
|
||||
referral_code = Column(String(20), unique=True)
|
||||
referred_by_id = Column(Integer, ForeignKey("data.users.id"), nullable=True)
|
||||
# Farming üzletkötő (Átruházható cégkezelő)
|
||||
current_sales_agent_id = Column(Integer, ForeignKey("data.users.id"), nullable=True)
|
||||
|
||||
is_active = Column(Boolean, default=False)
|
||||
is_deleted = Column(Boolean, default=False)
|
||||
folder_slug = Column(String(12), unique=True, index=True)
|
||||
|
||||
preferred_language = Column(String(5), server_default="hu")
|
||||
region_code = Column(String(5), server_default="HU")
|
||||
preferred_currency = Column(String(3), server_default="HUF")
|
||||
|
||||
scope_level = Column(String(30), server_default="individual")
|
||||
scope_level = Column(String(30), server_default="individual") # global, region, country, entity, individual
|
||||
scope_id = Column(String(50))
|
||||
custom_permissions = Column(JSON, server_default=text("'{}'::jsonb"))
|
||||
|
||||
@@ -79,18 +101,25 @@ class User(Base):
|
||||
|
||||
person = relationship("Person", back_populates="users")
|
||||
wallet = relationship("Wallet", back_populates="user", uselist=False)
|
||||
stats = relationship("UserStats", back_populates="user", uselist=False)
|
||||
ownership_history = relationship("VehicleOwnership", back_populates="user")
|
||||
owned_organizations = relationship("Organization", back_populates="owner")
|
||||
social_accounts = relationship("SocialAccount", back_populates="user", cascade="all, delete-orphan")
|
||||
|
||||
class Wallet(Base):
|
||||
__tablename__ = "wallets"; __table_args__ = {"schema": "data"}
|
||||
""" A 3-as felosztású pénztárca. """
|
||||
__tablename__ = "wallets"
|
||||
__table_args__ = {"schema": "data", "extend_existing": True}
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("data.users.id"), unique=True)
|
||||
coin_balance = Column(Numeric(18, 2), default=0.00); credit_balance = Column(Numeric(18, 2), default=0.00); currency = Column(String(3), default="HUF")
|
||||
|
||||
earned_credits = Column(Numeric(18, 4), server_default=text("0")) # Munka + Referral
|
||||
purchased_credits = Column(Numeric(18, 4), server_default=text("0")) # Vásárolt
|
||||
service_coins = Column(Numeric(18, 4), server_default=text("0")) # Csak hirdetésre!
|
||||
|
||||
currency = Column(String(3), default="HUF")
|
||||
user = relationship("User", back_populates="wallet")
|
||||
|
||||
# ... (VerificationToken és SocialAccount változatlan) ...
|
||||
|
||||
class VerificationToken(Base):
|
||||
__tablename__ = "verification_tokens"; __table_args__ = {"schema": "data"}
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
|
||||
Reference in New Issue
Block a user