2021-07-21 01:12:26 +00:00
|
|
|
from sqlalchemy import *
|
|
|
|
from sqlalchemy.orm import relationship
|
2021-08-04 15:35:10 +00:00
|
|
|
from files.__main__ import Base
|
2021-09-05 09:49:48 +00:00
|
|
|
from files.helpers.sanitize import sanitize
|
2021-07-21 01:12:26 +00:00
|
|
|
from .mix_ins import *
|
|
|
|
import time
|
|
|
|
|
|
|
|
class ModAction(Base, Stndrd, Age_times):
|
|
|
|
__tablename__ = "modactions"
|
|
|
|
id = Column(BigInteger, primary_key=True)
|
|
|
|
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"))
|
|
|
|
kind = Column(String(32))
|
|
|
|
target_user_id = Column(Integer, ForeignKey("users.id"), default=0)
|
|
|
|
target_submission_id = Column(Integer, ForeignKey("submissions.id"), default=0)
|
|
|
|
target_comment_id = Column(Integer, ForeignKey("comments.id"), default=0)
|
2021-07-26 00:45:52 +00:00
|
|
|
_note=Column(String(256), default=None)
|
2021-07-21 01:12:26 +00:00
|
|
|
created_utc = Column(Integer, default=0)
|
|
|
|
|
|
|
|
|
2021-09-17 12:36:39 +00:00
|
|
|
user = relationship("User", lazy="joined", primaryjoin="User.id==ModAction.user_id", viewonly=True)
|
|
|
|
target_user = relationship("User", lazy="joined", primaryjoin="User.id==ModAction.target_user_id", viewonly=True)
|
|
|
|
target_post = relationship("Submission", lazy="joined", viewonly=True)
|
|
|
|
target_comment = relationship("Comment", lazy="joined", viewonly=True)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs:
|
|
|
|
kwargs["created_utc"] = int(time.time())
|
|
|
|
|
|
|
|
if "note" in kwargs:
|
|
|
|
kwargs["_note"]=kwargs["note"]
|
|
|
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def __repr__(self):
|
2021-07-30 05:31:38 +00:00
|
|
|
return f"<ModAction(id={self.id})>"
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
def note(self):
|
|
|
|
|
2021-09-19 13:01:16 +00:00
|
|
|
if self.kind=="ban_user":
|
2021-07-21 01:12:26 +00:00
|
|
|
if self.target_post:
|
|
|
|
return f'for <a href="{self.target_post.permalink}">post</a>'
|
|
|
|
elif self.target_comment:
|
|
|
|
return f'for <a href="{self.target_comment.permalink}">comment</a>'
|
|
|
|
else: return self._note
|
|
|
|
else:
|
|
|
|
return self._note or ""
|
|
|
|
|
|
|
|
@note.setter
|
|
|
|
def note(self, x):
|
|
|
|
self._note=x
|
|
|
|
|
|
|
|
@property
|
|
|
|
def string(self):
|
|
|
|
|
2021-09-19 14:27:30 +00:00
|
|
|
output = ACTIONTYPES["str"].format(self=self)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-19 14:27:30 +00:00
|
|
|
if self.note: output += f" <i>({self.note})</i>"
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
return output
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target_link(self):
|
|
|
|
if self.target_user:
|
2021-09-05 09:49:48 +00:00
|
|
|
return f'<a href="{self.target_user.url}">{sanitize(self.target_user.username)}</a>'
|
2021-07-21 01:12:26 +00:00
|
|
|
elif self.target_post:
|
2021-09-05 09:49:48 +00:00
|
|
|
return f'<a href="{self.target_post.permalink}">{sanitize(self.target_post.title)}</a>'
|
2021-07-21 01:12:26 +00:00
|
|
|
elif self.target_comment:
|
|
|
|
return f'<a href="{self.target_comment.permalink}">comment</a>'
|
|
|
|
|
|
|
|
else:
|
2021-09-08 10:57:56 +00:00
|
|
|
return ""
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
2021-09-19 14:27:30 +00:00
|
|
|
return ACTIONTYPES['icon']
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def color(self):
|
2021-09-19 14:27:30 +00:00
|
|
|
return ACTIONTYPES['color']
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def permalink(self):
|
2021-09-19 14:27:30 +00:00
|
|
|
return f"/log/{self.id}"
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ACTIONTYPES={
|
2021-09-19 13:01:16 +00:00
|
|
|
"ban_user":{
|
2021-07-21 01:12:26 +00:00
|
|
|
"str":'banned user {self.target_link}',
|
|
|
|
"icon":"fa-user-slash",
|
|
|
|
"color": "bg-danger",
|
|
|
|
},
|
2021-09-19 13:01:16 +00:00
|
|
|
"unban_user":{
|
2021-07-21 01:12:26 +00:00
|
|
|
"str":'unbanned user {self.target_link}',
|
|
|
|
"icon": "fa-user-slash",
|
|
|
|
"color": "bg-muted",
|
2021-09-19 14:27:30 +00:00
|
|
|
},
|
|
|
|
"club_allow":{
|
|
|
|
"str":'disallowed user {self.target_link} from the country club',
|
|
|
|
"icon":"fa-user-slash",
|
|
|
|
"color": "bg-danger",
|
|
|
|
},
|
|
|
|
"club_ban":{
|
|
|
|
"str":'allowed user {self.target_link} into the country club',
|
|
|
|
"icon": "fa-user-slash",
|
|
|
|
"color": "bg-muted",
|
2021-07-21 01:12:26 +00:00
|
|
|
},
|
|
|
|
"nuke_user":{
|
|
|
|
"str":'removed all content of {self.target_link}',
|
|
|
|
"icon":"fa-user-slash",
|
|
|
|
"color": "bg-danger",
|
|
|
|
},
|
|
|
|
"unnuke_user":{
|
|
|
|
"str":'approved all content of {self.target_link}',
|
|
|
|
"icon": "fa-user-slash",
|
|
|
|
"color": "bg-muted",
|
|
|
|
},
|
|
|
|
"shadowban": {
|
|
|
|
"str": 'shadowbanned {self.target_link}',
|
|
|
|
"icon": "fa-user-slash",
|
|
|
|
"color": "bg-danger",
|
|
|
|
},
|
|
|
|
"unshadowban": {
|
|
|
|
"str": 'unshadowbanned {self.target_link}',
|
|
|
|
"icon": "fa-user-slash",
|
|
|
|
"color": "bg-muted",
|
|
|
|
},
|
|
|
|
"agendaposter": {
|
|
|
|
"str": "set agendaposter theme on {self.target_link}",
|
|
|
|
"icon": "fa-user-slash",
|
|
|
|
"color": "bg-muted",
|
|
|
|
},
|
|
|
|
"unagendaposter": {
|
|
|
|
"str": "removed agendaposter theme from {self.target_link}",
|
|
|
|
"icon": "fa-user-slash",
|
|
|
|
"color": "bg-muted",
|
|
|
|
},
|
|
|
|
"set_flair_locked":{
|
|
|
|
"str":"set {self.target_link}'s flair (locked)",
|
|
|
|
"icon": "fa-user-slash",
|
|
|
|
},
|
|
|
|
"set_flair_notlocked":{
|
|
|
|
"str":"set {self.target_link}'s flair (not locked)",
|
|
|
|
"icon": "fa-user-slash",
|
|
|
|
},
|
|
|
|
"pin_comment":{
|
|
|
|
"str":'pinned a {self.target_link}',
|
|
|
|
"icon":"fa-thumbtack fa-rotate--45",
|
|
|
|
"color": "bg-info",
|
|
|
|
},
|
|
|
|
"unpin_comment":{
|
|
|
|
"str":'un-pinned a {self.target_link}',
|
|
|
|
"icon":"fa-thumbtack fa-rotate--45",
|
|
|
|
"color": "bg-muted",
|
|
|
|
},
|
|
|
|
"pin_post":{
|
|
|
|
"str":'pinned post {self.target_link}',
|
|
|
|
"icon":"fa-thumbtack fa-rotate--45",
|
|
|
|
"color": "bg-success",
|
|
|
|
},
|
|
|
|
"unpin_post":{
|
|
|
|
"str":'un-pinned post {self.target_link}',
|
|
|
|
"icon":"fa-thumbtack fa-rotate--45",
|
|
|
|
"color": "bg-muted",
|
|
|
|
},
|
|
|
|
"set_nsfw":{
|
|
|
|
"str":'set nsfw on post {self.target_link}',
|
|
|
|
"icon":"fa-eye-evil",
|
|
|
|
"color": "bg-danger",
|
|
|
|
},
|
|
|
|
"unset_nsfw":{
|
|
|
|
"str":'un-set nsfw on post {self.target_link}',
|
|
|
|
"icon":"fa-eye-evil",
|
|
|
|
"color": "bg-muted",
|
2021-07-26 00:45:52 +00:00
|
|
|
},
|
2021-07-21 01:12:26 +00:00
|
|
|
"ban_post":{
|
|
|
|
"str": 'removed post {self.target_link}',
|
|
|
|
"icon":"fa-feather-alt",
|
|
|
|
"color": "bg-danger",
|
|
|
|
},
|
|
|
|
"unban_post":{
|
|
|
|
"str": 'reinstated post {self.target_link}',
|
|
|
|
"icon":"fa-feather-alt",
|
|
|
|
"color": "bg-muted",
|
|
|
|
},
|
2021-09-11 23:40:58 +00:00
|
|
|
"club":{
|
|
|
|
"str": 'marked post {self.target_link} as viewable to users with +150 coins only',
|
|
|
|
"icon":"fa-eye-slash",
|
|
|
|
"color": "bg-danger",
|
|
|
|
},
|
|
|
|
"unclub":{
|
|
|
|
"str": 'unmarked post {self.target_link} as viewable to users with +150 coins only',
|
|
|
|
"icon":"fa-eye",
|
|
|
|
"color": "bg-muted",
|
|
|
|
},
|
2021-07-21 01:12:26 +00:00
|
|
|
"ban_comment":{
|
|
|
|
"str": 'removed {self.target_link}',
|
|
|
|
"icon":"fa-comment",
|
|
|
|
"color": "bg-danger",
|
|
|
|
},
|
|
|
|
"unban_comment":{
|
|
|
|
"str": 'reinstated {self.target_link}',
|
|
|
|
"icon":"fa-comment",
|
|
|
|
"color": "bg-muted",
|
|
|
|
},
|
|
|
|
}
|