MarseyWorld/files/classes/mod_logs.py

421 lines
10 KiB
Python
Raw Normal View History

2022-05-04 23:09:46 +00:00
import time
from copy import deepcopy
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from sqlalchemy import Column, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.sql.sqltypes import *
from files.classes import Base
2022-05-04 23:09:46 +00:00
from files.helpers.const import *
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.helpers.lazy import lazy
2022-08-21 17:08:48 +00:00
from files.helpers.regex import censor_slurs
from files.helpers.sorting_and_time import make_age_string
2022-05-04 23:09:46 +00:00
class ModAction(Base):
__tablename__ = "modactions"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"))
kind = Column(String)
target_user_id = Column(Integer, ForeignKey("users.id"))
target_submission_id = Column(Integer, ForeignKey("submissions.id"))
target_comment_id = Column(Integer, ForeignKey("comments.id"))
_note=Column(String)
created_utc = Column(Integer)
2022-05-04 23:09:46 +00:00
user = relationship("User", primaryjoin="User.id==ModAction.user_id")
target_user = relationship("User", primaryjoin="User.id==ModAction.target_user_id")
target_post = relationship("Submission")
2022-05-04 23:09:46 +00:00
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
super().__init__(*args, **kwargs)
2022-05-04 23:09:46 +00:00
def __repr__(self):
return f"<{self.__class__.__name__}(id={self.id})>"
2022-05-04 23:09:46 +00:00
@property
@lazy
def age_string(self):
return make_age_string(self.created_utc)
2022-05-04 23:09:46 +00:00
@property
def note(self):
if self.kind=="ban_user":
if self.target_post: return f'for <a href="{self.target_post.permalink}">post</a>'
elif self.target_comment_id: return f'for <a href="/comment/{self.target_comment_id}">comment</a>'
else: return self._note
else:
return self._note or ""
@property
@lazy
def string(self):
output = ACTIONTYPES[self.kind]["str"].format(self=self)
2022-05-04 23:09:46 +00:00
if self.note: output += f" <i>({self.note})</i>"
return output
@property
@lazy
def target_link(self):
if self.target_user: return f'<a href="{self.target_user.url}">{self.target_user.username}</a>'
elif self.target_post:
2022-08-21 17:08:48 +00:00
return censor_slurs(f'<a href="{self.target_post.permalink}">{self.target_post.title_html}</a>', None)
2022-05-04 23:09:46 +00:00
elif self.target_comment_id: return f'<a href="/comment/{self.target_comment_id}?context=8#context">comment</a>'
@property
@lazy
def icon(self):
return ACTIONTYPES[self.kind]['icon']
@property
@lazy
def color(self):
return ACTIONTYPES[self.kind]['color']
@property
@lazy
def permalink(self):
2022-09-29 12:43:14 +00:00
return f"{SITE_FULL}/log/{self.id}"
2022-05-04 23:09:46 +00:00
ACTIONTYPES = {
2022-11-07 01:47:27 +00:00
'chud': {
"str": 'chudded {self.target_link}',
2022-05-04 23:09:46 +00:00
"icon": 'fa-snooze',
"color": 'bg-danger'
},
'approve_app': {
"str": 'approved an application by {self.target_link}',
"icon": 'fa-robot',
"color": 'bg-success'
},
'badge_grant': {
"str": 'granted badge to {self.target_link}',
"icon": 'fa-badge',
"color": 'bg-success'
},
'badge_remove': {
"str": 'removed badge from {self.target_link}',
"icon": 'fa-badge',
"color": 'bg-danger'
},
'ban_comment': {
"str": 'removed {self.target_link}',
"icon": 'fa-comment',
"color": 'bg-danger'
},
'ban_domain': {
"str": 'banned a domain',
"icon": 'fa-globe',
"color": 'bg-danger'
},
'ban_post': {
"str": 'removed post {self.target_link}',
"icon": 'fa-feather-alt',
"color": 'bg-danger'
},
'ban_user': {
"str": 'banned user {self.target_link}',
"icon": 'fa-user-slash',
"color": 'bg-danger'
},
'delete_report': {
"str": 'deleted report on {self.target_link}',
"icon": 'fa-flag',
"color": 'bg-danger'
},
2022-11-30 18:26:07 +00:00
'disable_bots': {
"str": 'disabled bots',
2022-05-04 23:09:46 +00:00
"icon": 'fa-robot',
"color": 'bg-danger'
},
2022-11-30 18:26:07 +00:00
'disable_fart_mode': {
2022-05-04 23:09:46 +00:00
"str": 'disabled fart mode',
"icon": 'fa-gas-pump-slash',
"color": 'bg-danger'
},
2022-11-30 18:26:07 +00:00
'disable_read_only_mode': {
"str": 'disabled read only mode',
2022-05-04 23:09:46 +00:00
"icon": 'fa-book',
"color": 'bg-danger'
},
2022-11-30 18:26:07 +00:00
'disable_signups': {
"str": 'disabled signups',
2022-05-04 23:09:46 +00:00
"icon": 'fa-users',
"color": 'bg-danger'
},
'disable_login_required': {
2022-11-30 18:26:07 +00:00
"str": 'disabled login required',
"icon": 'fa-users',
"color": 'bg-danger'
},
2022-05-04 23:09:46 +00:00
'disable_under_attack': {
"str": 'disabled under attack mode',
"icon": 'fa-shield',
"color": 'bg-muted'
},
2022-11-30 18:26:07 +00:00
'disable_under_siege': {
"str": 'disabled under siege mode',
"icon": 'fa-shield',
"color": 'bg-muted'
},
2022-05-04 23:09:46 +00:00
'distinguish_comment': {
"str": 'distinguished {self.target_link}',
"icon": 'fa-crown',
"color": 'bg-success'
},
'distinguish_post': {
"str": 'distinguished {self.target_link}',
"icon": 'fa-crown',
"color": 'bg-success'
},
'distribute': {
"str": 'distributed bet winnings to voters on {self.target_link}',
"icon": 'fa-dollar-sign',
"color": 'bg-success'
},
2022-11-06 05:28:44 +00:00
'clear_internal_cache': {
"str": 'cleared internal cache',
2022-05-04 23:09:46 +00:00
"icon": 'fa-trash-alt',
"color": 'bg-muted'
},
'edit_post': {
"str": 'edited {self.target_link}',
"icon": 'fa-edit',
"color": 'bg-primary'
},
'edit_rules': {
"str": 'edited the rules',
"icon": 'fa-columns',
"color": 'bg-primary'
},
2022-11-30 18:26:07 +00:00
'enable_bots': {
"str": 'enabled bots',
2022-05-04 23:09:46 +00:00
"icon": 'fa-robot',
"color": 'bg-success'
},
2022-11-30 18:26:07 +00:00
'enable_fart_mode': {
2022-05-04 23:09:46 +00:00
"str": 'enabled fart mode',
"icon": 'fa-gas-pump',
"color": 'bg-success'
},
2022-11-30 18:26:07 +00:00
'enable_read_only_mode': {
"str": 'enabled read only mode',
2022-05-04 23:09:46 +00:00
"icon": 'fa-book',
"color": 'bg-success'
},
2022-11-30 18:26:07 +00:00
'enable_signups': {
"str": 'enabled signups',
2022-05-04 23:09:46 +00:00
"icon": 'fa-users',
"color": 'bg-success'
},
'enable_login_required': {
2022-11-30 18:26:07 +00:00
"str": 'enabled login required',
"icon": 'fa-users',
"color": 'bg-success'
},
2022-05-04 23:09:46 +00:00
'enable_under_attack': {
"str": 'enabled under attack mode',
"icon": 'fa-shield',
"color": 'bg-success'
},
2022-11-30 18:26:07 +00:00
'enable_under_siege': {
"str": 'enabled under siege mode',
"icon": 'fa-shield',
"color": 'bg-success',
},
2022-05-04 23:09:46 +00:00
'flair_post': {
"str": 'set a flair on {self.target_link}',
"icon": 'fa-tag',
"color": 'bg-primary'
},
'link_accounts': {
"str": 'linked {self.target_link}',
"icon": 'fa-link',
"color": 'bg-success'
},
account linking improvements (#448) currently account delinking is very messy and can sometimes just not work we do codey stuff so it's not as bad also we create a pretty page for mops to mop up borked account links * alts: allow proper delinking * fix prev commit * url fix * fix 500 * fixes * :pepodrool: * flag * :pepodrool: redux * sdsdsdsds * correct endpoint * fix html page * alts: only adjust session history if flag is set * fix 500 * allow relinking * fsdsds * :pepodrool: redux * alts: don't fail if an alt isn't history * use postToastSwitch + some API changes * remove unnecessary variables * d-none * delink accounts mod action * fa-link-slash * alts: add form to create alt * remove copied and pasted template * rounded section * UI improvement + fix * \n * fix status * admin: remove duplicate route admin: do a permissions check on 2 pages that need it admin: set the manual flag for manually flagged alts * variable change * fix 500 * alts * add shadowban icon to alt link tool * shadowbanned tooltip * add user info section * fix 500, remove unnecessary form, and add alt votes button * trans and also link to page * margin * sdsdsd * stop the count * fix prev commit * with ctx * plural * alts * don't show shadowbanned users to those who can't see them this is... extremely rare and won't ever be seen in production however if perms were ever rearranged in the future, this keeps permissions correct * shadowban check in alt list * let shadow realm enthusiasts see shadowban alts * sdsdsds * test * be graceful where needed * sdsdsdsds * alts: don't allow adding the same account alts: clarify wording * rename and reorder on admin panel * EOL * remove frankly unnecessary check * try with a set * test * Revert "try with a set" This reverts commit 72be353fba5ffa39b37590cc5d3bf584c94ee06e. * Revert "Revert "try with a set"" This reverts commit 81e41890a192e8b46d0463477998e905fddf56ba. * Revert "Revert "Revert "try with a set""" This reverts commit be51592135a3c09848f993f0154bd2ac862ae505. * clean up test
2022-11-14 17:32:13 +00:00
'delink_accounts': {
"str": 'delinked {self.target_link}',
"icon": 'fa-link-slash',
"color": 'bg-danger'
},
2022-05-04 23:09:46 +00:00
'make_admin': {
2022-09-29 10:05:14 +00:00
"str": 'made {self.target_link} an admin',
2022-05-04 23:09:46 +00:00
"icon": 'fa-user-crown',
"color": 'bg-success'
},
'mod_mute_user': {
"str": 'muted reports from user {self.target_link}',
"icon": 'fa-file-signature',
"color": 'bg-danger'
},
'mod_unmute_user': {
"str": 'unmuted reports from user {self.target_link}',
"icon": 'fa-file-signature',
"color": 'bg-success'
},
2022-05-04 23:09:46 +00:00
'monthly': {
"str": 'distributed monthly marseybux',
"icon": 'fa-sack-dollar',
"color": 'bg-success'
},
'move_hole': {
2022-06-09 06:42:52 +00:00
"str": 'changed hole of {self.target_link}',
2022-05-04 23:09:46 +00:00
"icon": 'fa-manhole',
"color": 'bg-primary'
},
'nuke_user': {
"str": 'removed all content of {self.target_link}',
"icon": 'fa-radiation-alt',
"color": 'bg-danger'
},
'pin_comment': {
2022-09-29 10:18:27 +00:00
"str": 'pinned {self.target_link}',
2022-05-04 23:09:46 +00:00
"icon": 'fa-thumbtack fa-rotate--45',
"color": 'bg-success'
},
'pin_post': {
"str": 'pinned post {self.target_link}',
"icon": 'fa-thumbtack fa-rotate--45',
"color": 'bg-success'
},
2022-11-06 05:28:44 +00:00
'clear_cloudflare_cache': {
"str": 'cleared cloudflare cache',
2022-11-15 13:54:24 +00:00
"icon": 'fab fa-cloudflare',
2022-05-04 23:09:46 +00:00
"color": 'bg-muted'
},
'reject_app': {
"str": 'rejected an application request by {self.target_link}',
"icon": 'fa-robot',
"color": 'bg-muted'
},
'remove_admin': {
"str": 'removed {self.target_link} as admin',
"icon": 'fa-user-crown',
"color": 'bg-danger'
},
'revert': {
"str": 'reverted {self.target_link} mod actions',
"icon": 'fa-history',
"color": 'bg-danger'
},
'revoke_app': {
"str": 'revoked an application by {self.target_link}',
"icon": 'fa-robot',
"color": 'bg-muted'
},
'set_flair_locked': {
"str": "set {self.target_link}'s flair (locked)",
"icon": 'fa-award',
"color": 'bg-primary'
},
'set_flair_notlocked': {
"str": "set {self.target_link}'s flair (not locked)",
"icon": 'fa-award',
"color": 'bg-primary'
},
2022-12-10 14:57:19 +00:00
'set_new': {
"str": 'changed the default sorting of comments on {self.target_link} to `new`',
"icon": 'fa-sparkles',
"color": 'bg-primary'
},
'set_hot': {
"str": 'changed the default sorting of comments on {self.target_link} to `hot`',
"icon": 'fa-fire',
"color": 'bg-primary'
},
2022-05-04 23:09:46 +00:00
'set_nsfw': {
"str": 'set {self.target_link} as +18',
2022-05-04 23:09:46 +00:00
"icon": 'fa-eye-evil',
"color": 'bg-danger'
},
'set_nsfw_comment': {
"str": 'set {self.target_link} as +18',
"icon": 'fa-eye-evil',
"color": 'bg-danger'
},
2022-05-04 23:09:46 +00:00
'shadowban': {
"str": 'shadowbanned {self.target_link}',
"icon": 'fa-eye-slash',
"color": 'bg-danger'
},
2022-11-07 01:47:27 +00:00
'unchud': {
"str": 'unchudded {self.target_link}',
2022-05-04 23:09:46 +00:00
"icon": 'fa-snooze',
"color": 'bg-success'
},
'unban_comment': {
"str": 'reinstated {self.target_link}',
"icon": 'fa-comment',
"color": 'bg-success'
},
'unban_domain': {
"str": 'unbanned a domain',
"icon": 'fa-globe',
"color": 'bg-success'
},
'unban_post': {
"str": 'reinstated post {self.target_link}',
"icon": 'fa-feather-alt',
"color": 'bg-success'
},
'unban_user': {
"str": 'unbanned user {self.target_link}',
"icon": 'fa-user',
"color": 'bg-success'
},
'undistinguish_comment': {
"str": 'un-distinguished {self.target_link}',
"icon": 'fa-crown',
"color": 'bg-muted'
},
'undistinguish_post': {
"str": 'un-distinguished {self.target_link}',
"icon": 'fa-crown',
"color": 'bg-muted'
},
'unnuke_user': {
"str": 'approved all content of {self.target_link}',
"icon": 'fa-radiation-alt',
"color": 'bg-success'
},
'unpin_comment': {
2022-09-29 10:18:27 +00:00
"str": 'unpinned {self.target_link}',
2022-05-04 23:09:46 +00:00
"icon": 'fa-thumbtack fa-rotate--45',
"color": 'bg-muted'
},
'unpin_post': {
2022-09-29 09:39:37 +00:00
"str": 'unpinned post {self.target_link}',
2022-05-04 23:09:46 +00:00
"icon": 'fa-thumbtack fa-rotate--45',
"color": 'bg-muted'
},
'unset_nsfw': {
"str": 'unset {self.target_link} as +18',
2022-05-04 23:09:46 +00:00
"icon": 'fa-eye-evil',
"color": 'bg-success'
},
'unset_nsfw_comment': {
"str": 'unset {self.target_link} as +18',
"icon": 'fa-eye-evil',
"color": 'bg-success'
},
2022-05-04 23:09:46 +00:00
'unshadowban': {
"str": 'unshadowbanned {self.target_link}',
"icon": 'fa-eye',
"color": 'bg-success'
},
'update_hat': {
2022-09-23 14:56:01 +00:00
"str": 'updated hat image',
"icon": 'fa-hat-cowboy',
"color": 'bg-success'
},
'update_marsey': {
"str": 'updated marsey',
"icon": 'fa-cat',
"color": 'bg-success'
},
2022-05-04 23:09:46 +00:00
}
ACTIONTYPES2 = deepcopy(ACTIONTYPES)
ACTIONTYPES2.pop("shadowban")
ACTIONTYPES2.pop("unshadowban")