AW: theCure
This commit is contained in:
65
backend/app/models/core.py
Normal file
65
backend/app/models/core.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from sqlalchemy.orm import DeclarativeBase, mapped_column
|
||||
from sqlalchemy import String, Text, DateTime, ForeignKey, Boolean
|
||||
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
||||
from sqlalchemy.sql import func
|
||||
import uuid
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
class Application(Base):
|
||||
__tablename__ = "applications"
|
||||
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = mapped_column(String, unique=True, nullable=False)
|
||||
description = mapped_column(Text)
|
||||
owner_user_id = mapped_column(UUID(as_uuid=True), nullable=True)
|
||||
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
class Entity(Base):
|
||||
__tablename__ = "entities"
|
||||
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
application_id = mapped_column(UUID(as_uuid=True), ForeignKey("applications.id"), nullable=False)
|
||||
name = mapped_column(String, nullable=False)
|
||||
label = mapped_column(String)
|
||||
description = mapped_column(Text)
|
||||
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
class Field(Base):
|
||||
__tablename__ = "fields"
|
||||
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
entity_id = mapped_column(UUID(as_uuid=True), ForeignKey("entities.id"), nullable=False)
|
||||
name = mapped_column(String, nullable=False)
|
||||
label = mapped_column(String)
|
||||
field_type = mapped_column(String, nullable=False)
|
||||
required = mapped_column(Boolean, default=False)
|
||||
default_value = mapped_column(String)
|
||||
relation_entity = mapped_column(UUID(as_uuid=True), ForeignKey("entities.id"))
|
||||
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
class Form(Base):
|
||||
__tablename__ = "forms"
|
||||
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
application_id = mapped_column(UUID(as_uuid=True), ForeignKey("applications.id"), nullable=False)
|
||||
entity_id = mapped_column(UUID(as_uuid=True), ForeignKey("entities.id"), nullable=False)
|
||||
name = mapped_column(String, nullable=False)
|
||||
label = mapped_column(String)
|
||||
form_type = mapped_column(String, nullable=False)
|
||||
layout_json = mapped_column(JSONB, nullable=False)
|
||||
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
class Workflow(Base):
|
||||
__tablename__ = "workflows"
|
||||
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
application_id = mapped_column(UUID(as_uuid=True), ForeignKey("applications.id"), nullable=False)
|
||||
entity_id = mapped_column(UUID(as_uuid=True), ForeignKey("entities.id"), nullable=False)
|
||||
name = mapped_column(String, nullable=False)
|
||||
description = mapped_column(Text)
|
||||
trigger_event = mapped_column(String, nullable=False)
|
||||
condition_json = mapped_column(JSONB)
|
||||
action_json = mapped_column(JSONB)
|
||||
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
48
backend/app/models/security.py
Normal file
48
backend/app/models/security.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from sqlalchemy.orm import mapped_column
|
||||
from sqlalchemy import String, Text, DateTime, ForeignKey, Boolean
|
||||
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
||||
from sqlalchemy.sql import func
|
||||
import uuid
|
||||
from .core import Base
|
||||
|
||||
class Role(Base):
|
||||
__tablename__ = "roles"
|
||||
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = mapped_column(String, unique=True, nullable=False)
|
||||
description = mapped_column(Text)
|
||||
parent_role_id = mapped_column(UUID(as_uuid=True), ForeignKey("roles.id"))
|
||||
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
email = mapped_column(String, unique=True)
|
||||
display_name = mapped_column(String)
|
||||
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
class UserRole(Base):
|
||||
__tablename__ = "user_roles"
|
||||
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
user_id = mapped_column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
|
||||
role_id = mapped_column(UUID(as_uuid=True), ForeignKey("roles.id"), nullable=False)
|
||||
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
class EntityPermission(Base):
|
||||
__tablename__ = "entity_permissions"
|
||||
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
role_id = mapped_column(UUID(as_uuid=True), ForeignKey("roles.id"), nullable=False)
|
||||
entity_id = mapped_column(UUID(as_uuid=True), ForeignKey("entities.id"), nullable=False)
|
||||
can_create = mapped_column(Boolean, default=False)
|
||||
can_read = mapped_column(Boolean, default=False)
|
||||
can_update = mapped_column(Boolean, default=False)
|
||||
can_delete = mapped_column(Boolean, default=False)
|
||||
row_filter_json = mapped_column(JSONB)
|
||||
created_at = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
class FieldPermission(Base):
|
||||
__tablename__ = "field_permissions"
|
||||
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
role_id = mapped_column(UUID(as_uuid=_
|
||||
27
backend/app/models/views.py
Normal file
27
backend/app/models/views.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from sqlalchemy.orm import mapped_column
|
||||
from sqlalchemy import String, Boolean
|
||||
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
||||
from .core import Base
|
||||
|
||||
# Read-only ORM mappings to Postgres views
|
||||
|
||||
class CurrentUserEntityPermission(Base):
|
||||
__tablename__ = "current_user_entity_permissions"
|
||||
user_id = mapped_column(UUID(as_uuid=True), primary_key=True)
|
||||
entity_id = mapped_column(UUID(as_uuid=True), primary_key=True)
|
||||
entity_name = mapped_column(String)
|
||||
can_create = mapped_column(Boolean)
|
||||
can_read = mapped_column(Boolean)
|
||||
can_update = mapped_column(Boolean)
|
||||
can_delete = mapped_column(Boolean)
|
||||
row_filters = mapped_column(JSONB)
|
||||
|
||||
class CurrentUserFieldPermission(Base):
|
||||
__tablename__ = "current_user_field_permissions"
|
||||
user_id = mapped_column(UUID(as_uuid=True), primary_key=True)
|
||||
field_id = mapped_column(UUID(as_uuid=True), primary_key=True)
|
||||
entity_id = mapped_column(UUID(as_uuid=True))
|
||||
field_name = mapped_column(String)
|
||||
entity_name = mapped_column(String)
|
||||
can_read = mapped_column(Boolean)
|
||||
can_update = mapped_column(Boolean)
|
||||
Reference in New Issue
Block a user