From aeac766df38c277a338d108d12410a721b778517 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 25 Oct 2021 20:08:03 +0200 Subject: [PATCH] misc --- files/classes/mod_logs.py | 48 +++++++++++++++++++--- files/helpers/wrappers.py | 4 +- files/routes/admin.py | 53 ++++++++++++++++++++----- files/routes/comments.py | 2 +- files/routes/oauth.py | 21 ++++++++++ files/routes/posts.py | 2 +- files/templates/authforms.html | 6 +-- files/templates/default.html | 8 ++-- files/templates/log.html | 6 +-- files/templates/login_2fa.html | 2 +- files/templates/settings.html | 4 +- files/templates/settings2.html | 4 +- files/templates/sign_up.html | 2 +- files/templates/sign_up_failed_ref.html | 2 +- files/templates/submit.html | 8 ++-- 15 files changed, 132 insertions(+), 40 deletions(-) diff --git a/files/classes/mod_logs.py b/files/classes/mod_logs.py index 23a9caafd..aa9f8af12 100755 --- a/files/classes/mod_logs.py +++ b/files/classes/mod_logs.py @@ -21,12 +21,7 @@ class ModAction(Base): target_post = relationship("Submission", viewonly=True) 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"] - + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) super().__init__(*args, **kwargs) def __repr__(self): @@ -113,6 +108,47 @@ class ModAction(Base): ACTIONTYPES={ + "check": { + "str": "gave {self.target_link} a checkmark", + "icon": "fa-user", + "color": "bg-muted", + }, + "uncheck": { + "str": "removed checkmark from {self.target_link}", + "icon": "fa-user-slash", + "color": "bg-muted", + }, + "ban_domain": { + "str": "banned a domain", + "icon": "fa-globe", + "color": "bg-danger", + }, + "unban_domain": { + "str": "unbanned a domain", + "icon": "fa-globe", + "color": "bg-muted", + }, + "approve_app": { + "str": "approved an application by {self.target_link}", + "icon": "fa-robot", + "color": "bg-muted", + }, + "revoke_app": { + "str": "revoked an application by {self.target_link}", + "icon": "fa-robot", + "color": "bg-danger", + }, + "reject_app": { + "str": "rejected an application request by {self.target_link}", + "icon": "fa-robot", + "color": "bg-danger", + }, + "change_rules": { + "str": "changed the rules", + "icon": "fa-balance-scale", + "color": "bg-muted", + }, + "ban_user":{ "str":'banned user {self.target_link}', "icon":"fa-user-slash", diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 7230fbe7b..35e80709c 100755 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -55,7 +55,7 @@ def check_ban_evade(v): kind="ban_post", user_id=AUTOJANNY_ACCOUNT, target_submission_id=post.id, - note="permaban evasion" + _note="permaban evasion" ) g.db.add(ma) @@ -72,7 +72,7 @@ def check_ban_evade(v): kind="ban_comment", user_id=AUTOJANNY_ACCOUNT, target_comment_id=comment.id, - note="ban evasion" + _note="ban evasion" ) g.db.add(ma) except: pass diff --git a/files/routes/admin.py b/files/routes/admin.py index 62afda94d..527782525 100755 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -191,8 +191,7 @@ def monthly(v): def get_rules(v): try: - with open(f'./{SITE_NAME} rules.html', 'r') as f: - rules = f.read() + with open(f'./{SITE_NAME} rules.html', 'r') as f: rules = f.read() except Exception: rules = None @@ -207,11 +206,17 @@ def post_rules(v): text = request.values.get('rules', '').strip() - with open(f'./{SITE_NAME} rules.html', 'w+') as f: - f.write(text) + with open(f'./{SITE_NAME} rules.html', 'w+') as f: f.write(text) - with open(f'./{SITE_NAME} rules.html', 'r') as f: - rules = f.read() + with open(f'./{SITE_NAME} rules.html', 'r') as f: rules = f.read() + + ma = ModAction( + kind="change_rules", + user_id=v.id, + ) + g.db.add(ma) + + g.db.commit() return render_template('admin/rules.html', v=v, rules=rules) @@ -671,6 +676,14 @@ def verify(user_id, v): user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() user.verified = "Verified" g.db.add(user) + + ma = ModAction( + kind="check", + user_id=v.id, + target_user_id=user.id, + ) + g.db.add(ma) + g.db.commit() return {"message": "User verfied!"} @@ -682,6 +695,14 @@ def unverify(user_id, v): user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first() user.verified = None g.db.add(user) + + ma = ModAction( + kind="uncheck", + user_id=v.id, + target_user_id=user.id, + ) + g.db.add(ma) + g.db.commit() return {"message": "User unverified!"} @@ -713,7 +734,7 @@ def admin_title_change(user_id, v): kind=kind, user_id=v.id, target_user_id=user.id, - note=f'"{new_name}"' + _note=f'"{new_name}"' ) g.db.add(ma) g.db.commit() @@ -770,7 +791,7 @@ def ban_user(user_id, v): kind="ban_user", user_id=v.id, target_user_id=user.id, - note=f'reason: "{reason}", duration: {duration}' + _note=f'reason: "{reason}", duration: {duration}' ) g.db.add(ma) @@ -1065,10 +1086,24 @@ def admin_toggle_ban_domain(v): reason=request.values.get("reason", "").strip() d = g.db.query(BannedDomain).options(lazyload('*')).filter_by(domain=domain).first() - if d: g.db.delete(d) + if d: + g.db.delete(d) + ma = ModAction( + kind="unban_domain", + user_id=v.id, + _note=domain + ) + g.db.add(ma) + else: d = BannedDomain(domain=domain, reason=reason) g.db.add(d) + ma = ModAction( + kind="ban_domain", + user_id=v.id, + _note=f'{domain}, reason: {reason}' + ) + g.db.add(ma) g.db.commit() diff --git a/files/routes/comments.py b/files/routes/comments.py index 82108c1b7..427d70d51 100755 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -242,7 +242,7 @@ def api_comment(v): user_id=AUTOJANNY_ACCOUNT, target_comment_id=comment.id, kind="ban_comment", - note="spam" + _note="spam" ) g.db.add(ma) diff --git a/files/routes/oauth.py b/files/routes/oauth.py index 78cccd832..e5c6feab3 100755 --- a/files/routes/oauth.py +++ b/files/routes/oauth.py @@ -122,6 +122,13 @@ def admin_app_approve(v, aid): send_notification(user.id, f"Your application `{app.app_name}` has been approved. Here's your access token: `{access_token}`\nPlease check the guide [here](/api) if you don't know what to do next.") + ma = ModAction( + kind="approve_app", + user_id=v.id, + target_user_id=user.id, + ) + g.db.add(ma) + g.db.commit() return {"message": f"{app.app_name} approved"} @@ -141,6 +148,13 @@ def admin_app_revoke(v, aid): g.db.delete(app) + ma = ModAction( + kind="revoke_app", + user_id=v.id, + target_user_id=app.author.id, + ) + g.db.add(ma) + g.db.commit() return {"message": f"App revoked"} @@ -160,6 +174,13 @@ def admin_app_reject(v, aid): g.db.delete(app) + ma = ModAction( + kind="reject_app", + user_id=v.id, + target_user_id=app.author.id, + ) + g.db.add(ma) + g.db.commit() return {"message": f"App rejected"} diff --git a/files/routes/posts.py b/files/routes/posts.py index 3df6d1532..b817b7ea5 100755 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -616,7 +616,7 @@ def submit_post(v): user_id=AUTOJANNY_ACCOUNT, target_submission_id=post.id, kind="ban_post", - note="spam" + _note="spam" ) g.db.add(ma) return redirect("/notifications") diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 632720923..5b72c7725 100755 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,11 +15,11 @@ {% if v %} - - {% if v.agendaposter %}{% elif v.css %}{% endif %} + + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index 008474055..3d90ae7ba 100755 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -254,12 +254,12 @@ {% if v %} - - - {% if v.agendaposter %}{% elif v.css %}{% endif %} + + + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} {% endblock %} diff --git a/files/templates/log.html b/files/templates/log.html index d0026513e..4e0efb001 100755 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -17,11 +17,11 @@ {% if v %} - - {% if v.agendaposter %}{% elif v.css %}{% endif %} + + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %}
diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 49915d5b7..2f13f8ce9 100755 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -12,7 +12,7 @@ 2-Step Login - {{'SITE_NAME' | app_config}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 5548426f4..ded705243 100755 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -55,8 +55,8 @@ - - {% if v.agendaposter %}{% elif v.css %}{% endif %} + + {% if v.agendaposter %}{% elif v.css %}{% endif %} diff --git a/files/templates/settings2.html b/files/templates/settings2.html index 47bd6aa3a..51dd0335e 100755 --- a/files/templates/settings2.html +++ b/files/templates/settings2.html @@ -40,10 +40,10 @@ {% if v %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index 097019f89..d3c40cb6c 100755 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -36,7 +36,7 @@ - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index c99b57a7b..286e8f946 100755 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -31,7 +31,7 @@ - + diff --git a/files/templates/submit.html b/files/templates/submit.html index ab0ec9f68..6cfad5b40 100755 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -25,12 +25,12 @@ {% block stylesheets %} {% if v %} - - {% if v.agendaposter %}{% elif v.css %}{% endif %} + + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - - + + {% endif %} {% endblock %}