Skip to content

Commit a55b3af

Browse files
committed
Add the Annotation.moderation_status column
This column will support the existing feature stored in AnnotationModeration and new features based on the new statuses.
1 parent 849fb71 commit a55b3af

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

h/models/annotation.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
import datetime
2+
from enum import Enum
23
from uuid import UUID
34

45
import sqlalchemy as sa
56
from sqlalchemy.dialects import postgresql as pg
67
from sqlalchemy.ext.hybrid import hybrid_property
78
from sqlalchemy.ext.mutable import MutableDict, MutableList
9+
from sqlalchemy.orm import Mapped, relationship
810

911
from h.db import Base, types
1012
from h.models.group import Group
1113
from h.util import markdown_render, uri
1214
from h.util.user import split_user
1315

1416

17+
class ModerationStatus(Enum):
18+
APPROVED = "APPROVED"
19+
PENDING = "PENDING"
20+
DENIED = "DENIED"
21+
SPAM = "SPAM"
22+
23+
1524
class Annotation(Base):
1625
"""Model class representing a single annotation."""
1726

27+
# Expose the ModerationStatus directly here
28+
ModerationStatus = ModerationStatus
29+
1830
__tablename__ = "annotation"
1931
__table_args__ = (
2032
# Tags are stored in an array-type column, and indexed using a
@@ -68,7 +80,7 @@ class Annotation(Base):
6880
index=True,
6981
)
7082

71-
group = sa.orm.relationship(
83+
group = relationship(
7284
Group,
7385
primaryjoin=(Group.pubid == groupid),
7486
foreign_keys=[groupid],
@@ -138,11 +150,15 @@ class Annotation(Base):
138150
uselist=True,
139151
)
140152

141-
mentions = sa.orm.relationship("Mention", back_populates="annotation")
153+
mentions = relationship("Mention", back_populates="annotation")
142154

143-
notifications = sa.orm.relationship(
144-
"Notification", back_populates="source_annotation"
145-
)
155+
notifications = relationship("Notification", back_populates="source_annotation")
156+
157+
moderation_status: Mapped[ModerationStatus | None]
158+
"""Current moderation status of the annotation.
159+
160+
None means the annotation is either "approved" before this column was added or it's a private annotation.
161+
"""
146162

147163
@property
148164
def uuid(self):

0 commit comments

Comments
 (0)