feat(request): add service accounts and unified authorization

This commit is contained in:
2026-08-11 11:16:38 +03:00
parent 51f01300c3
commit 4e7dc451ac
22 changed files with 4947 additions and 19 deletions
@@ -0,0 +1,34 @@
"""ServiceAccountRole model — ServiceAccount → Role mapping.
This is the generic Principal → Role link for Service Accounts.
Reuses existing Role model.
"""
from sqlalchemy import Column, Integer, ForeignKey, UniqueConstraint
from sqlalchemy.orm import relationship
from request_app.models.base import Base, TimestampMixin
class ServiceAccountRole(Base, TimestampMixin):
"""ServiceAccountRole — links ServiceAccount to Role.
Reuses existing Role model for authorization.
"""
__tablename__ = "service_account_roles"
id = Column(Integer, primary_key=True, index=True)
service_account_id = Column(Integer, ForeignKey("service_accounts.id", ondelete="CASCADE"), nullable=False)
role_id = Column(Integer, ForeignKey("roles.id", ondelete="CASCADE"), nullable=False)
# Unique constraint: one SA can have each role only once
__table_args__ = (
UniqueConstraint("service_account_id", "role_id", name="uq_service_account_role"),
)
# Relationships
service_account = relationship("ServiceAccount", back_populates="roles")
role = relationship("Role")
def __repr__(self) -> str:
return f"<ServiceAccountRole(sa_id={self.service_account_id}, role_id={self.role_id})>"