From 51d7cd6d7e2192795b54779ecff66990bba337c0 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 29 Sep 2022 12:18:27 +0200 Subject: [PATCH] fix shit with hole logs --- files/classes/mod_logs.py | 8 +-- files/classes/sub_logs.py | 34 ++++------ files/routes/admin.py | 2 +- files/routes/awards.py | 2 +- files/routes/reporting.py | 5 +- files/routes/subs.py | 38 +++++++++--- files/templates/default.html | 2 +- files/templates/log.html | 4 +- files/templates/settings2.html | 110 +++++++++++++++++---------------- 9 files changed, 107 insertions(+), 98 deletions(-) diff --git a/files/classes/mod_logs.py b/files/classes/mod_logs.py index 38b4bdde1..898dbb91a 100644 --- a/files/classes/mod_logs.py +++ b/files/classes/mod_logs.py @@ -70,10 +70,6 @@ class ModAction(Base): else: return self._note or "" - @note.setter - def note(self, x): - self._note=x - @property @lazy def string(self): @@ -295,7 +291,7 @@ ACTIONTYPES = { "color": 'bg-danger' }, 'pin_comment': { - "str": 'pinned a {self.target_link}', + "str": 'pinned {self.target_link}', "icon": 'fa-thumbtack fa-rotate--45', "color": 'bg-success' }, @@ -395,7 +391,7 @@ ACTIONTYPES = { "color": 'bg-success' }, 'unpin_comment': { - "str": 'unpinned a {self.target_link}', + "str": 'unpinned {self.target_link}', "icon": 'fa-thumbtack fa-rotate--45', "color": 'bg-muted' }, diff --git a/files/classes/sub_logs.py b/files/classes/sub_logs.py index 55a2d317c..1be5156b4 100644 --- a/files/classes/sub_logs.py +++ b/files/classes/sub_logs.py @@ -60,26 +60,13 @@ class SubAction(Base): years = int(months / 12) return f"{years}yr ago" - @property - def note(self): - - if self.kind=="ban_user": - if self.target_post: return f'for post' - else: return self._note - else: - return self._note or "" - - @note.setter - def note(self, x): - self._note=x - @property @lazy def string(self): output = ACTIONTYPES[self.kind]["str"].format(self=self, cc=CC_TITLE) - if self.note: output += f" ({self.note})" + if self._note: output += f" ({self._note})" return output @@ -90,6 +77,7 @@ class SubAction(Base): elif self.target_post: if self.target_post.club: return f'{CC} ONLY' return censor_slurs(f'{self.target_post.title_html}', None) + elif self.target_comment_id: return f'comment' @property @lazy @@ -113,12 +101,12 @@ ACTIONTYPES = { "color": 'bg-danger' }, 'unexile_user': { - "str": 'unexile user {self.target_link}', + "str": 'unexiled user {self.target_link}', "icon": 'fa-user', "color": 'bg-success' }, 'make_mod': { - "str": 'made {self.target_link} mod', + "str": 'made {self.target_link} a mod', "icon": 'fa-user-crown', "color": 'bg-success' }, @@ -133,7 +121,7 @@ ACTIONTYPES = { "color": 'bg-danger' }, 'move_chudrama': { - "str": 'moved post {self.target_link} to /h/chudrama', + "str": 'moved post {self.target_link} to /h/chudrama', "icon": 'fa-feather-alt', "color": 'bg-danger' }, @@ -142,13 +130,13 @@ ACTIONTYPES = { "icon": 'fa-tag', "color": 'bg-primary' }, - 'change_sidebar': { - "str": 'changed the sidebar', + 'edit_sidebar': { + "str": 'edited the sidebar', "icon": 'fa-columns', "color": 'bg-primary' }, - 'change_css': { - "str": 'changed the css', + 'edit_css': { + "str": 'edited the css', "icon": 'fa-css3-alt', "color": 'bg-primary' }, @@ -178,12 +166,12 @@ ACTIONTYPES = { "color": 'bg-muted' }, 'pin_comment': { - "str": 'pinned comment {self.target_link}', + "str": 'pinned {self.target_link}', "icon": 'fa-thumbtack fa-rotate--45', "color": 'bg-success' }, 'unpin_comment': { - "str": 'unpinned comment {self.target_link}', + "str": 'unpinned {self.target_link}', "icon": 'fa-thumbtack fa-rotate--45', "color": 'bg-muted' }, diff --git a/files/routes/admin.py b/files/routes/admin.py index 4c63363b6..7cfb1cdd7 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -862,7 +862,7 @@ def agendaposter(user_id, v): kind="agendaposter", user_id=v.id, target_user_id=user.id, - note=note + _note=note ) g.db.add(ma) diff --git a/files/routes/awards.py b/files/routes/awards.py index e2fa12dbb..882ac2a1e 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -303,7 +303,7 @@ def award_thing(v, thing_type, id): kind="agendaposter", user_id=v.id, target_user_id=author.id, - note=f"for 1 day" + _note=f"for 1 day" ) g.db.add(ma) elif kind == "flairlock": diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 7f8ae8473..7c7a1db61 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -42,9 +42,11 @@ def flag_post(pid, v): g.db.add(ma) else: ma = SubAction( + sub=post.sub, kind="flair_post", user_id=v.id, - target_submission_id=post.id + target_submission_id=post.id, + _note=f'"{post.flair}"' ) g.db.add(ma) @@ -84,6 +86,7 @@ def flag_post(pid, v): g.db.add(ma) else: ma = SubAction( + sub=sub_from, kind='move_chudrama', user_id=v.id, target_submission_id=post.id diff --git a/files/routes/subs.py b/files/routes/subs.py index a7caef2d8..0f07e61d3 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -31,6 +31,7 @@ def exile_post(v, pid): send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{p.title}]({p.shortlink})") ma = SubAction( + sub=sub, kind='exile_user', user_id=v.id, target_user_id=u.id, @@ -65,6 +66,7 @@ def exile_comment(v, cid): send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{c.permalink}]({c.shortlink})") ma = SubAction( + sub=sub, kind='exile_user', user_id=v.id, target_user_id=u.id, @@ -89,6 +91,7 @@ def unexile(v, sub, uid): send_notification(u.id, f"@{v.username} has revoked your exile from /h/{sub}") ma = SubAction( + sub=sub, kind='unexile_user', user_id=v.id, target_user_id=u.id @@ -280,6 +283,7 @@ def add_mod(v, sub): send_repeatable_notification(user.id, f"@{v.username} has added you as a mod to /h/{sub}") ma = SubAction( + sub=sub, kind='make_mod', user_id=v.id, target_user_id=user.id @@ -320,6 +324,7 @@ def remove_mod(v, sub): send_repeatable_notification(user.id, f"@{v.username} has removed you as a mod from /h/{sub}") ma = SubAction( + sub=sub, kind='remove_mod', user_id=v.id, target_user_id=user.id @@ -395,6 +400,7 @@ def kick(v, pid): g.db.add(ma) else: ma = SubAction( + sub=old, kind='kick_post', user_id=v.id, target_submission_id=post.id @@ -441,7 +447,8 @@ def post_sub_sidebar(v, sub): g.db.add(sub) ma = SubAction( - kind='change_sidebar', + sub=sub.name, + kind='edit_sidebar', user_id=v.id ) g.db.add(ma) @@ -472,7 +479,8 @@ def post_sub_css(v, sub): g.db.add(sub) ma = SubAction( - kind='change_css', + sub=sub.name, + kind='edit_css', user_id=v.id ) g.db.add(ma) @@ -515,6 +523,7 @@ def sub_banner(v, sub): g.db.add(sub) ma = SubAction( + sub=sub.name, kind='change_banner', user_id=v.id ) @@ -547,6 +556,7 @@ def sub_sidebar(v, sub): g.db.add(sub) ma = SubAction( + sub=sub.name, kind='change_sidebar_image', user_id=v.id ) @@ -579,6 +589,7 @@ def sub_marsey(v, sub): g.db.add(sub) ma = SubAction( + sub=sub.name, kind='change_marsey', user_id=v.id ) @@ -609,6 +620,7 @@ def hole_pin(v, pid): send_repeatable_notification(p.author_id, message) ma = SubAction( + sub=p.sub, kind='pin_post', user_id=v.id, target_submission_id=p.id @@ -634,6 +646,7 @@ def hole_unpin(v, pid): send_repeatable_notification(p.author_id, message) ma = SubAction( + sub=p.sub, kind='unpin_post', user_id=v.id, target_submission_id=p.id @@ -659,6 +672,7 @@ def sub_stealth(v, sub): if sub.stealth: ma = SubAction( + sub=sub.name, kind='enable_stealth', user_id=v.id ) @@ -666,6 +680,7 @@ def sub_stealth(v, sub): return {"message": f"Stealth mode has been enabled for /h/{sub} successfully!"} else: ma = SubAction( + sub=sub.name, kind='disable_stealth', user_id=v.id ) @@ -688,6 +703,7 @@ def mod_pin(cid, v): g.db.add(comment) ma = SubAction( + sub=comment.post.sub, kind="pin_comment", user_id=v.id, target_comment_id=comment.id @@ -700,7 +716,7 @@ def mod_pin(cid, v): return {"message": "Comment pinned!"} -@app.post("/mod_unpin/") +@app.post("/unmod_pin/") @is_not_permabanned def mod_unpin(cid, v): @@ -713,6 +729,7 @@ def mod_unpin(cid, v): g.db.add(comment) ma = SubAction( + sub=comment.post.sub, kind="unpin_comment", user_id=v.id, target_comment_id=comment.id @@ -731,7 +748,7 @@ def mod_unpin(cid, v): def hole_log(v, sub): sub = g.db.get(Sub, sub.strip().lower()) if not sub: abort(404) - sub = sub.name + sub = sub try: page = max(int(request.values.get("page", 1)), 1) except: page = 1 @@ -748,7 +765,7 @@ def hole_log(v, sub): kind = None actions = [] else: - actions = g.db.query(SubAction).filter_by(sub=sub) + actions = g.db.query(SubAction).filter_by(sub=sub.name) if mod_id: actions = actions.filter_by(user_id=mod_id) @@ -763,14 +780,17 @@ def hole_log(v, sub): next_exists=len(actions)>25 actions=actions[:25] - mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub).all()] + mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub.name).all()] mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username).all()] - return render_template("log.html", v=v, mods=mods, types=types, mod=mod, type=kind, actions=actions, next_exists=next_exists, page=page) + return render_template("log.html", v=v, admins=mods, types=types, admin=mod, type=kind, actions=actions, next_exists=next_exists, page=page, sub=sub) @app.get("/h//log/") @auth_required def hole_log_item(id, v, sub): + sub = g.db.get(Sub, sub.strip().lower()) + if not sub: abort(404) + sub = sub try: id = int(id) except: abort(404) @@ -779,9 +799,9 @@ def hole_log_item(id, v, sub): if not action: abort(404) - mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub).all()] + mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub.name).all()] mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username).all()] types = ACTIONTYPES - return render_template("log.html", v=v, actions=[action], next_exists=False, page=1, action=action, mods=mods, types=types) + return render_template("log.html", v=v, actions=[action], next_exists=False, page=1, action=action, admins=mods, types=types, sub=sub) diff --git a/files/templates/default.html b/files/templates/default.html index 3a40b03d5..fe3d85754 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -335,7 +335,7 @@ {% block sidebar %} - {% if has_sidebar and (home or p) %} + {% if has_sidebar and (home or p or request.path.startswith('/h/')) %} {% include "sidebar_" + SITE_NAME + ".html" %} {% endif %} {% endblock %} diff --git a/files/templates/log.html b/files/templates/log.html index d6b0a384e..4ff0d4105 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -40,9 +40,9 @@
-
+
-
Moderation Log
+
{% if sub %}/h/{{sub.name}} {% endif %}Moderation Log
diff --git a/files/templates/settings2.html b/files/templates/settings2.html index 34f96d022..f2440b297 100644 --- a/files/templates/settings2.html +++ b/files/templates/settings2.html @@ -54,70 +54,72 @@ {% block subNav %} {% set mod = (v and v.admin_level > 1) %} -
-
-
-
-
-
-
- + {% if not request.path.startswith('/h/') %} +
+
+
+
+
+
+
+ +
-
-
-
-
- +
+
+
+ +
-
+ {% endif %} {% endblock %}