Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2cc1dbe18 | |||
| 0ce85fd5f7 | |||
| 57135fc859 | |||
| ae498ce4cb | |||
| 9c6390e73b |
@@ -1,18 +1,6 @@
|
|||||||
"""Appeal model for moderation actions."""
|
"""Appeal model for moderation actions."""
|
||||||
|
|
||||||
from datetime import datetime
|
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, Enum
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from sqlalchemy import (
|
|
||||||
Column,
|
|
||||||
Enum,
|
|
||||||
ForeignKey,
|
|
||||||
Integer,
|
|
||||||
String,
|
|
||||||
Text,
|
|
||||||
DateTime,
|
|
||||||
CheckConstraint,
|
|
||||||
)
|
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
@@ -22,46 +10,25 @@ from app.database import Base
|
|||||||
class Appeal(Base):
|
class Appeal(Base):
|
||||||
__tablename__ = "appeals"
|
__tablename__ = "appeals"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True)
|
||||||
moderation_action_id = Column(
|
moderation_action_id = Column(
|
||||||
Integer,
|
Integer, ForeignKey("moderation_actions.id"), nullable=False
|
||||||
ForeignKey("moderation_actions.id", ondelete="CASCADE"),
|
|
||||||
nullable=False,
|
|
||||||
)
|
|
||||||
user_id = Column(
|
|
||||||
Integer,
|
|
||||||
ForeignKey("users.id", ondelete="CASCADE"),
|
|
||||||
nullable=False,
|
|
||||||
)
|
)
|
||||||
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||||
reason = Column(Text, nullable=False)
|
reason = Column(Text, nullable=False)
|
||||||
status = Column(
|
status = Column(
|
||||||
Enum("pending", "approved", "rejected", name="appeal_status", create_type=False),
|
Enum(
|
||||||
nullable=False,
|
"pending", "approved", "rejected",
|
||||||
|
name="appeal_status_enum",
|
||||||
|
),
|
||||||
default="pending",
|
default="pending",
|
||||||
)
|
|
||||||
reviewed_by = Column(
|
|
||||||
Integer,
|
|
||||||
ForeignKey("users.id", ondelete="SET NULL"),
|
|
||||||
nullable=True,
|
|
||||||
)
|
|
||||||
reviewed_at = Column(DateTime(timezone=True), nullable=True)
|
|
||||||
created_at = Column(
|
|
||||||
DateTime(timezone=True),
|
|
||||||
server_default=func.now(),
|
|
||||||
nullable=False,
|
nullable=False,
|
||||||
)
|
)
|
||||||
|
reviewed_by = Column(Integer, ForeignKey("users.id"), nullable=True)
|
||||||
|
reviewed_at = Column(DateTime(timezone=True), nullable=True)
|
||||||
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
moderation_action = relationship("ModerationAction", back_populates="appeals")
|
moderation_action = relationship("ModerationAction", back_populates="appeals")
|
||||||
reviewer = relationship(
|
user = relationship("User", back_populates="appeals")
|
||||||
"User",
|
reviewer = relationship("User", foreign_keys=[reviewed_by])
|
||||||
foreign_keys=[reviewed_by],
|
|
||||||
back_populates="reviewed_appeals",
|
|
||||||
)
|
|
||||||
|
|
||||||
__table_args__ = (
|
|
||||||
CheckConstraint(
|
|
||||||
"status IN ('pending', 'approved', 'rejected')",
|
|
||||||
name="check_appeal_status",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,118 +1,35 @@
|
|||||||
"""Moderation action model."""
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum as PyEnum
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from sqlalchemy import (
|
from sqlalchemy import Column, Enum, ForeignKey, Integer, String, Text, DateTime
|
||||||
Column,
|
|
||||||
Enum,
|
|
||||||
ForeignKey,
|
|
||||||
Integer,
|
|
||||||
String,
|
|
||||||
Text,
|
|
||||||
DateTime,
|
|
||||||
func,
|
|
||||||
)
|
|
||||||
from sqlalchemy.dialects.postgresql import TIMESTAMPTZ
|
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
from app.database import Base
|
from app.database import Base
|
||||||
|
|
||||||
|
|
||||||
class TargetType(str, PyEnum):
|
|
||||||
"""Type of entity being reported or moderated."""
|
|
||||||
USER = "user"
|
|
||||||
WORLD = "world"
|
|
||||||
ASSET = "asset"
|
|
||||||
CHAT_MESSAGE = "chat_message"
|
|
||||||
|
|
||||||
|
|
||||||
class ReasonCategory(str, PyEnum):
|
|
||||||
"""Category of report reason."""
|
|
||||||
HARASSMENT = "harassment"
|
|
||||||
HATE_SPEECH = "hate_speech"
|
|
||||||
SEXUAL_CONTENT = "sexual_content"
|
|
||||||
VIOLENCE = "violence"
|
|
||||||
SPAM = "spam"
|
|
||||||
SELF_HARM = "self_harm"
|
|
||||||
OTHER = "other"
|
|
||||||
|
|
||||||
|
|
||||||
class ReportStatus(str, PyEnum):
|
|
||||||
"""Status of a report."""
|
|
||||||
OPEN = "open"
|
|
||||||
IN_REVIEW = "in_review"
|
|
||||||
RESOLVED = "resolved"
|
|
||||||
DISMISSED = "dismissed"
|
|
||||||
|
|
||||||
|
|
||||||
class Resolution(str, PyEnum):
|
|
||||||
"""Resolution outcome of a report."""
|
|
||||||
ACTION_TAKEN = "action_taken"
|
|
||||||
NO_ACTION = "no_action"
|
|
||||||
|
|
||||||
|
|
||||||
class ModerationActionType(str, PyEnum):
|
|
||||||
"""Type of moderation action."""
|
|
||||||
WARN = "warn"
|
|
||||||
SUSPEND = "suspend"
|
|
||||||
BAN = "ban"
|
|
||||||
RESTRICT = "restrict"
|
|
||||||
REMOVE = "remove"
|
|
||||||
RESTORE = "restore"
|
|
||||||
|
|
||||||
|
|
||||||
class ModerationAction(Base):
|
class ModerationAction(Base):
|
||||||
__tablename__ = "moderation_actions"
|
__tablename__ = "moderation_actions"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True)
|
||||||
moderator_id = Column(
|
moderator_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||||
Integer,
|
target_user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||||
ForeignKey("users.id", ondelete="SET NULL"),
|
|
||||||
nullable=True,
|
|
||||||
)
|
|
||||||
target_user_id = Column(
|
|
||||||
Integer,
|
|
||||||
ForeignKey("users.id", ondelete="SET NULL"),
|
|
||||||
nullable=True,
|
|
||||||
)
|
|
||||||
target_type = Column(
|
target_type = Column(
|
||||||
Enum(TargetType, name="target_type_enum", create_type=False),
|
Enum("user", "world", "asset", "chat_message", name="target_type_enum"),
|
||||||
nullable=False,
|
nullable=False,
|
||||||
)
|
)
|
||||||
target_id = Column(String(64), nullable=False)
|
target_id = Column(String(64), nullable=False)
|
||||||
action = Column(
|
action = Column(
|
||||||
Enum(ModerationActionType, name="moderation_action_type_enum", create_type=False),
|
Enum("warn", "suspend", "ban", "restrict", "remove", "restore", name="action_enum"),
|
||||||
nullable=False,
|
nullable=False,
|
||||||
)
|
)
|
||||||
reason = Column(Text, nullable=True)
|
reason = Column(Text, nullable=True)
|
||||||
report_id = Column(
|
report_id = Column(Integer, ForeignKey("reports.id"), nullable=True)
|
||||||
Integer,
|
expires_at = Column(DateTime(timezone=True), nullable=True)
|
||||||
ForeignKey("reports.id", ondelete="SET NULL"),
|
revoked_at = Column(DateTime(timezone=True), nullable=True)
|
||||||
nullable=True,
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
)
|
|
||||||
expires_at = Column(TIMESTAMPTZ, nullable=True)
|
|
||||||
revoked_at = Column(TIMESTAMPTZ, nullable=True)
|
|
||||||
created_at = Column(
|
|
||||||
DateTime(timezone=True),
|
|
||||||
server_default=func.now(),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
moderator = relationship(
|
moderator = relationship("User", foreign_keys=[moderator_id])
|
||||||
"User",
|
target_user = relationship("User", foreign_keys=[target_user_id])
|
||||||
foreign_keys=[moderator_id],
|
|
||||||
back_populates="moderation_actions_given",
|
|
||||||
)
|
|
||||||
target_user = relationship(
|
|
||||||
"User",
|
|
||||||
foreign_keys=[target_user_id],
|
|
||||||
back_populates="moderation_actions_received",
|
|
||||||
)
|
|
||||||
report = relationship("Report", back_populates="moderation_actions")
|
report = relationship("Report", back_populates="moderation_actions")
|
||||||
appeals = relationship(
|
|
||||||
"Appeal",
|
|
||||||
back_populates="moderation_action",
|
|
||||||
cascade="all, delete-orphan",
|
|
||||||
)
|
|
||||||
|
|||||||
+34
-120
@@ -1,146 +1,60 @@
|
|||||||
"""Report model for user-generated moderation reports."""
|
"""Report model for Trust & Safety."""
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
import sqlalchemy as sa
|
|
||||||
from sqlalchemy import (
|
from sqlalchemy import (
|
||||||
Column,
|
Column,
|
||||||
DateTime,
|
|
||||||
Enum,
|
|
||||||
ForeignKey,
|
|
||||||
Integer,
|
Integer,
|
||||||
String,
|
String,
|
||||||
Text,
|
Text,
|
||||||
|
DateTime,
|
||||||
|
ForeignKey,
|
||||||
|
Enum as SAEnum,
|
||||||
)
|
)
|
||||||
from sqlalchemy.dialects.postgresql import TIMESTAMPTZ
|
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
from app.database import Base
|
from app.database import Base
|
||||||
|
|
||||||
|
|
||||||
class ReportStatus:
|
|
||||||
"""Valid statuses for a Report."""
|
|
||||||
|
|
||||||
OPEN = "open"
|
|
||||||
IN_REVIEW = "in_review"
|
|
||||||
RESOLVED = "resolved"
|
|
||||||
DISMISSED = "dismissed"
|
|
||||||
|
|
||||||
|
|
||||||
class Resolution:
|
|
||||||
"""Possible resolution outcomes for a Report."""
|
|
||||||
|
|
||||||
ACTION_TAKEN = "action_taken"
|
|
||||||
NO_ACTION = "no_action"
|
|
||||||
|
|
||||||
|
|
||||||
class TargetType:
|
|
||||||
"""Types of entities that can be reported."""
|
|
||||||
|
|
||||||
USER = "user"
|
|
||||||
WORLD = "world"
|
|
||||||
ASSET = "asset"
|
|
||||||
CHAT_MESSAGE = "chat_message"
|
|
||||||
|
|
||||||
|
|
||||||
class ReasonCategory:
|
|
||||||
"""Categories for why something was reported."""
|
|
||||||
|
|
||||||
HARASSMENT = "harassment"
|
|
||||||
HATE_SPEECH = "hate_speech"
|
|
||||||
SEXUAL_CONTENT = "sexual_content"
|
|
||||||
VIOLENCE = "violence"
|
|
||||||
SPAM = "spam"
|
|
||||||
SELF_HARM = "self_harm"
|
|
||||||
OTHER = "other"
|
|
||||||
|
|
||||||
|
|
||||||
class Report(Base):
|
class Report(Base):
|
||||||
__tablename__ = "reports"
|
__tablename__ = "reports"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True)
|
||||||
reporter_id = Column(
|
reporter_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||||
Integer,
|
target_type = SAEnum("user", "world", "asset", "chat_message", name="target_type_enum", nullable=False)
|
||||||
ForeignKey("users.id", ondelete="CASCADE"),
|
|
||||||
nullable=False,
|
|
||||||
)
|
|
||||||
target_type = Column(
|
|
||||||
Enum(
|
|
||||||
TargetType.USER,
|
|
||||||
TargetType.WORLD,
|
|
||||||
TargetType.ASSET,
|
|
||||||
TargetType.CHAT_MESSAGE,
|
|
||||||
name="target_type",
|
|
||||||
create_type=False,
|
|
||||||
),
|
|
||||||
nullable=False,
|
|
||||||
)
|
|
||||||
target_id = Column(String(64), nullable=False)
|
target_id = Column(String(64), nullable=False)
|
||||||
reason_category = Column(
|
reason_category = SAEnum(
|
||||||
Enum(
|
"harassment",
|
||||||
ReasonCategory.HARASSMENT,
|
"hate_speech",
|
||||||
ReasonCategory.HATE_SPEECH,
|
"sexual_content",
|
||||||
ReasonCategory.SEXUAL_CONTENT,
|
"violence",
|
||||||
ReasonCategory.VIOLENCE,
|
"spam",
|
||||||
ReasonCategory.SPAM,
|
"self_harm",
|
||||||
ReasonCategory.SELF_HARM,
|
"other",
|
||||||
ReasonCategory.OTHER,
|
name="reason_category_enum",
|
||||||
name="reason_category",
|
|
||||||
create_type=False,
|
|
||||||
),
|
|
||||||
nullable=False,
|
nullable=False,
|
||||||
)
|
)
|
||||||
details = Column(Text, nullable=True)
|
details = Column(Text, nullable=True)
|
||||||
status = Column(
|
status = SAEnum(
|
||||||
Enum(
|
"open",
|
||||||
ReportStatus.OPEN,
|
"in_review",
|
||||||
ReportStatus.IN_REVIEW,
|
"resolved",
|
||||||
ReportStatus.RESOLVED,
|
"dismissed",
|
||||||
ReportStatus.DISMISSED,
|
name="report_status_enum",
|
||||||
name="report_status",
|
default="open",
|
||||||
create_type=False,
|
|
||||||
),
|
|
||||||
nullable=False,
|
nullable=False,
|
||||||
default=ReportStatus.OPEN,
|
|
||||||
)
|
)
|
||||||
resolved_by = Column(
|
resolved_by = Column(Integer, ForeignKey("users.id"), nullable=True)
|
||||||
Integer,
|
resolution = SAEnum(
|
||||||
ForeignKey("users.id", ondelete="SET NULL"),
|
"action_taken",
|
||||||
|
"action_not_needed",
|
||||||
|
"duplicate",
|
||||||
|
name="resolution_enum",
|
||||||
nullable=True,
|
nullable=True,
|
||||||
)
|
)
|
||||||
resolution = Column(
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
Enum(
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||||
Resolution.ACTION_TAKEN,
|
resolved_at = Column(DateTime(timezone=True), nullable=True)
|
||||||
Resolution.NO_ACTION,
|
|
||||||
name="resolution",
|
|
||||||
create_type=False,
|
|
||||||
),
|
|
||||||
nullable=True,
|
|
||||||
)
|
|
||||||
created_at = Column(
|
|
||||||
TIMESTAMPTZ,
|
|
||||||
nullable=False,
|
|
||||||
server_default=sa.func.now(),
|
|
||||||
)
|
|
||||||
updated_at = Column(
|
|
||||||
TIMESTAMPTZ,
|
|
||||||
nullable=False,
|
|
||||||
server_default=sa.func.now(),
|
|
||||||
onupdate=sa.func.now(),
|
|
||||||
)
|
|
||||||
resolved_at = Column(TIMESTAMPTZ, nullable=True)
|
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
reporter = relationship("User", foreign_keys=[reporter_id])
|
reporter = relationship("User", foreign_keys=[reporter_id])
|
||||||
resolver = relationship("User", foreign_keys=[resolved_by])
|
resolved_by_user = relationship("User", foreign_keys=[resolved_by])
|
||||||
moderation_actions = relationship(
|
|
||||||
"ModerationAction",
|
|
||||||
back_populates="report",
|
|
||||||
cascade="all, delete-orphan",
|
|
||||||
)
|
|
||||||
appeals = relationship(
|
|
||||||
"Appeal",
|
|
||||||
back_populates="report",
|
|
||||||
cascade="all, delete-orphan",
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,20 +1,12 @@
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime, Date, Enum
|
from sqlalchemy import Boolean, Column, Date, DateTime, Enum, Integer, String
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
from app.database import Base
|
from app.database import Base
|
||||||
|
|
||||||
|
|
||||||
class UserRole:
|
|
||||||
"""Valid user roles."""
|
|
||||||
USER = "user"
|
|
||||||
MODERATOR = "moderator"
|
|
||||||
ADMIN = "admin"
|
|
||||||
|
|
||||||
|
|
||||||
class User(Base):
|
class User(Base):
|
||||||
__tablename__ = "users"
|
__tablename__ = "users"
|
||||||
|
|
||||||
@@ -25,9 +17,8 @@ class User(Base):
|
|||||||
date_of_birth = Column(Date, nullable=True)
|
date_of_birth = Column(Date, nullable=True)
|
||||||
is_active = Column(Boolean, default=True)
|
is_active = Column(Boolean, default=True)
|
||||||
role = Column(
|
role = Column(
|
||||||
Enum(UserRole.USER, UserRole.MODERATOR, UserRole.ADMIN, name="user_role", create_type=False),
|
Enum("user", "moderator", "admin", name="user_role", default="user"),
|
||||||
nullable=False,
|
default="user",
|
||||||
default=UserRole.USER,
|
|
||||||
)
|
)
|
||||||
banned_until = Column(DateTime(timezone=True), nullable=True)
|
banned_until = Column(DateTime(timezone=True), nullable=True)
|
||||||
suspended_until = Column(DateTime(timezone=True), nullable=True)
|
suspended_until = Column(DateTime(timezone=True), nullable=True)
|
||||||
@@ -37,16 +28,7 @@ class User(Base):
|
|||||||
sessions = relationship("Session", back_populates="user", cascade="all, delete-orphan")
|
sessions = relationship("Session", back_populates="user", cascade="all, delete-orphan")
|
||||||
worlds = relationship("World", back_populates="owner")
|
worlds = relationship("World", back_populates="owner")
|
||||||
assets = relationship("Asset", back_populates="owner")
|
assets = relationship("Asset", back_populates="owner")
|
||||||
moderation_actions_given = relationship(
|
appeals = relationship("Appeal", back_populates="user")
|
||||||
"ModerationAction",
|
|
||||||
foreign_keys="ModerationAction.moderator_id",
|
|
||||||
back_populates="moderator",
|
|
||||||
)
|
|
||||||
moderation_actions_received = relationship(
|
|
||||||
"ModerationAction",
|
|
||||||
foreign_keys="ModerationAction.target_user_id",
|
|
||||||
back_populates="target_user",
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_adult(self) -> bool:
|
def is_adult(self) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user