Update from task 90279199-752f-4c5d-8ba2-2d3b805e8caa by fiqrikm18 · Pull Request #4 · IDTS-LAB/python-codebase · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add authorization infrastructure with Casbin policy management
- New SQLAlchemy models for authorization including CasbinRuleModel, PermissionModel, AuthorizationResourceModel, RoleModel, RolePermissionModel, and UserHasRoleModel with proper relationships and constraints
- Implementation of SQLAlchemyCasbinPolicyRepository with full CRUD operations for roles, permissions, and policies including cursor-based pagination
- CasbinAuthorizationService integrating with the repository layer and providing dynamic enforcer building for access control decisions
- Infrastructure setup for authorization module with proper domain entities, services, and repository patterns following the application architecture

This commit establishes a comprehensive authorization system backend with database persistence, supporting role-based access control through Casbin policies and efficient data management through SQLAlchemy ORM.
  • Loading branch information
qwen-intl committed Jun 21, 2026
commit 989280b3d37b61ea8acc2a4e5b914138285775e7
45 changes: 0 additions & 45 deletions .gitignore
Empty file.
16 changes: 16 additions & 0 deletions src/core/authorization/infrastructure/models/casbin_rule_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column

from src.shared.database.model import Base


class CasbinRuleModel(Base):
__tablename__ = "casbin_rules"

ptype: Mapped[str] = mapped_column(String(16), index=True)
v0: Mapped[str | None] = mapped_column(String(255), index=True, nullable=True)
v1: Mapped[str | None] = mapped_column(String(255), index=True, nullable=True)
v2: Mapped[str | None] = mapped_column(String(255), index=True, nullable=True)
v3: Mapped[str | None] = mapped_column(String(255), nullable=True)
v4: Mapped[str | None] = mapped_column(String(255), nullable=True)
v5: Mapped[str | None] = mapped_column(String(255), nullable=True)
20 changes: 20 additions & 0 deletions src/core/authorization/infrastructure/models/permission_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from uuid import UUID

from sqlalchemy import String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column

from src.shared.database.mixin.timestamp import SoftDeleteMixin, TimeStampMixin
from src.shared.database.model import Base


class PermissionModel(Base, TimeStampMixin, SoftDeleteMixin):
__tablename__ = "permissions"
__table_args__ = (
UniqueConstraint("resource", "action", name="uq_permissions_resource_action"),
)

key: Mapped[str] = mapped_column(String(255), unique=True, index=True)
resource_id: Mapped[UUID] = mapped_column(index=True)
resource: Mapped[str] = mapped_column(String(100), index=True)
action: Mapped[str] = mapped_column(String(100), index=True)
description: Mapped[str | None] = mapped_column(String(255), nullable=True)
13 changes: 13 additions & 0 deletions src/core/authorization/infrastructure/models/resource_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column

from src.shared.database.mixin.timestamp import SoftDeleteMixin, TimeStampMixin
from src.shared.database.model import Base


class AuthorizationResourceModel(Base, TimeStampMixin, SoftDeleteMixin):
__tablename__ = "authorization_resources"

key: Mapped[str] = mapped_column(String(100), unique=True, index=True)
name: Mapped[str] = mapped_column(String(150), nullable=False)
description: Mapped[str | None] = mapped_column(String(255), nullable=True)
12 changes: 12 additions & 0 deletions src/core/authorization/infrastructure/models/role_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column

from src.shared.database.mixin.timestamp import SoftDeleteMixin, TimeStampMixin
from src.shared.database.model import Base


class RoleModel(Base, TimeStampMixin, SoftDeleteMixin):
__tablename__ = "roles"

name: Mapped[str] = mapped_column(String(100), unique=True, index=True)
description: Mapped[str | None] = mapped_column(String(255), nullable=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from uuid import UUID

from sqlalchemy import UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column

from src.shared.database.model import Base


class RolePermissionModel(Base):
__tablename__ = "role_permissions"
__table_args__ = (
UniqueConstraint(
"role_id",
"permission_id",
name="uq_role_permissions_role_id_permission_id",
),
)

role_id: Mapped[UUID] = mapped_column(index=True)
permission_id: Mapped[UUID] = mapped_column(index=True)
Empty file.
Loading
Loading