Rejigger the Mod/Report state system.
This commit is contained in:
parent
31ebdd0213
commit
ccf809406e
36 changed files with 492 additions and 226 deletions
|
@ -6,6 +6,7 @@ from sqlalchemy.orm import Session, declared_attr, deferred, relationship
|
|||
|
||||
from files.classes.base import CreatedBase
|
||||
from files.classes.flags import Flag
|
||||
from files.classes.visstate import StateMod, StateReport
|
||||
from files.classes.votes import Vote
|
||||
from files.helpers.assetcache import assetcache_path
|
||||
from files.helpers.config.const import *
|
||||
|
@ -23,7 +24,6 @@ class Submission(CreatedBase):
|
|||
author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
edited_utc = Column(Integer, default=0, nullable=False)
|
||||
thumburl = Column(String)
|
||||
is_banned = Column(Boolean, default=False, nullable=False)
|
||||
bannedfor = Column(Boolean)
|
||||
ghost = Column(Boolean, default=False, nullable=False)
|
||||
views = Column(Integer, default=0, nullable=False)
|
||||
|
@ -34,7 +34,6 @@ class Submission(CreatedBase):
|
|||
private = Column(Boolean, default=False, nullable=False)
|
||||
club = Column(Boolean, default=False, nullable=False)
|
||||
comment_count = Column(Integer, default=0, nullable=False)
|
||||
is_approved = Column(Integer, ForeignKey("users.id"))
|
||||
over_18 = Column(Boolean, default=False, nullable=False)
|
||||
is_bot = Column(Boolean, default=False, nullable=False)
|
||||
upvotes = Column(Integer, default=1, nullable=False)
|
||||
|
@ -47,26 +46,23 @@ class Submission(CreatedBase):
|
|||
body = Column(Text)
|
||||
body_html = Column(Text)
|
||||
flair = Column(String)
|
||||
ban_reason = Column(String)
|
||||
embed_url = Column(String)
|
||||
filter_state = Column(String, nullable=False)
|
||||
task_id = Column(Integer, ForeignKey("tasks_repeatable_scheduled_submissions.id"))
|
||||
|
||||
# Visibility states here
|
||||
state_user_deleted_utc = Column(DateTime(timezone=True), nullable=True) # null if it hasn't been deleted by the user
|
||||
# TBD: state_mod
|
||||
# TBD: state_mod_set_by
|
||||
# TBD: state_report
|
||||
state_mod = Column(Enum(StateMod), default=StateMod.FILTERED, nullable=False) # default to Filtered just to partially neuter possible exploits
|
||||
state_mod_set_by = Column(String, nullable=True) # This should *really* be a User.id, but I don't want to mess with the required refactoring at the moment - it's extra hard because it could potentially be a lot of extra either data or queries
|
||||
state_report = Column(Enum(StateReport), default=StateReport.UNREPORTED, nullable=False)
|
||||
|
||||
Index('fki_submissions_approver_fkey', is_approved)
|
||||
Index('post_app_id_idx', app_id)
|
||||
Index('subimssion_binary_group_idx', is_banned, state_user_deleted_utc, over_18)
|
||||
Index('submission_isbanned_idx', is_banned)
|
||||
Index('subimssion_binary_group_idx', state_mod, state_user_deleted_utc, over_18)
|
||||
Index('submission_state_mod_idx', state_mod)
|
||||
Index('submission_isdeleted_idx', state_user_deleted_utc)
|
||||
|
||||
@declared_attr
|
||||
def submission_new_sort_idx(self):
|
||||
return Index('submission_new_sort_idx', self.is_banned, self.state_user_deleted_utc, self.created_utc.desc(), self.over_18)
|
||||
return Index('submission_new_sort_idx', self.state_mod, self.state_user_deleted_utc, self.created_utc.desc(), self.over_18)
|
||||
|
||||
Index('submission_pinned_idx', is_pinned)
|
||||
Index('submissions_author_index', author_id)
|
||||
|
@ -83,7 +79,6 @@ class Submission(CreatedBase):
|
|||
|
||||
author = relationship("User", primaryjoin="Submission.author_id==User.id")
|
||||
oauth_app = relationship("OauthApp", viewonly=True)
|
||||
approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True)
|
||||
awards = relationship("AwardRelationship", viewonly=True)
|
||||
reports = relationship("Flag", viewonly=True)
|
||||
comments = relationship("Comment", primaryjoin="Comment.parent_submission==Submission.id")
|
||||
|
@ -107,7 +102,7 @@ class Submission(CreatedBase):
|
|||
author = self.author
|
||||
author.post_count = db.query(Submission.id).filter_by(
|
||||
author_id=self.author_id,
|
||||
is_banned=False,
|
||||
state_mod=StateMod.VISIBLE,
|
||||
state_user_deleted_utc=None).count()
|
||||
db.add(author)
|
||||
|
||||
|
@ -235,8 +230,6 @@ class Submission(CreatedBase):
|
|||
data = {'author_name': self.author_name if self.author else '',
|
||||
'permalink': self.permalink,
|
||||
'shortlink': self.shortlink,
|
||||
'is_banned': bool(self.is_banned),
|
||||
'state_user_deleted_utc': self.state_user_deleted_utc,
|
||||
'created_utc': self.created_utc,
|
||||
'id': self.id,
|
||||
'title': self.title,
|
||||
|
@ -261,24 +254,21 @@ class Submission(CreatedBase):
|
|||
'club': self.club,
|
||||
}
|
||||
|
||||
if self.ban_reason:
|
||||
data["ban_reason"]=self.ban_reason
|
||||
|
||||
return data
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def json_core(self):
|
||||
if self.is_banned:
|
||||
return {'is_banned': True,
|
||||
if self.state_mod != StateMod.VISIBLE:
|
||||
return {
|
||||
'state_user_deleted_utc': self.state_user_deleted_utc,
|
||||
'ban_reason': self.ban_reason,
|
||||
'state_mod_set_by': self.state_mod_set_by,
|
||||
'id': self.id,
|
||||
'title': self.title,
|
||||
'permalink': self.permalink,
|
||||
}
|
||||
elif self.state_user_deleted_utc:
|
||||
return {'is_banned': bool(self.is_banned),
|
||||
return {
|
||||
'state_user_deleted_utc': self.state_user_deleted_utc,
|
||||
'id': self.id,
|
||||
'title': self.title,
|
||||
|
@ -292,7 +282,7 @@ class Submission(CreatedBase):
|
|||
def json(self):
|
||||
data=self.json_core
|
||||
|
||||
if self.state_user_deleted_utc or self.is_banned:
|
||||
if self.state_user_deleted_utc or self.state_mod != StateMod.VISIBLE:
|
||||
return data
|
||||
|
||||
data["author"]='👻' if self.ghost else self.author.json_core
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue