From 67f968d04d9e88403fa180eb0f03fbaa01a9a3e6 Mon Sep 17 00:00:00 2001 From: Aevann Date: Tue, 8 Aug 2023 20:01:58 +0300 Subject: [PATCH] show who exiled the user in the icon --- files/classes/user.py | 11 ++++++----- files/routes/comments.py | 2 +- files/routes/posts.py | 2 +- files/routes/reporting.py | 2 +- files/routes/subs.py | 6 +++--- files/templates/comments.html | 12 ++++++------ files/templates/post_actions.html | 4 ++-- files/templates/post_actions_mobile.html | 4 ++-- files/templates/util/macros.html | 4 ++-- 9 files changed, 24 insertions(+), 23 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 00b454687d..3b42bb252a 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -394,11 +394,12 @@ class User(Base): return bool(g.db.query(Mod.user_id).filter_by(user_id=self.id, sub=sub).one_or_none()) @lazy - def exiled_from(self, sub): - try: - return any(map(lambda x: x.sub == sub, self.sub_exiles)) - except: - return bool(g.db.query(Exile.user_id).filter_by(user_id=self.id, sub=sub).one_or_none()) + def exiler_username(self, sub): + exile = g.db.query(Exile).options(load_only(Exile.exiler_id)).filter_by(user_id=self.id, sub=sub).one_or_none() + if exile: + return exile.exiler.username + else: + return None @property @lazy diff --git a/files/routes/comments.py b/files/routes/comments.py index f0289a00db..953879d093 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -146,7 +146,7 @@ def comment(v): if posting_to_post: sub = post_target.sub - if sub and v.exiled_from(sub): abort(403, f"You're exiled from /h/{sub}") + if sub and v.exiler_username(sub): abort(403, f"You're exiled from /h/{sub}") if sub in {'furry','vampire','racist','femboy','edgy'} and not v.client and not v.house.lower().startswith(sub): abort(403, f"You need to be a member of House {sub.capitalize()} to comment in /h/{sub}") diff --git a/files/routes/posts.py b/files/routes/posts.py index a5e107ac2d..3b5554acf8 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -451,7 +451,7 @@ def submit_post(v, sub=None): sub = g.db.query(Sub.name).filter_by(name=sname).one_or_none() if not sub: abort(400, f"/h/{sname} not found!") sub = sub[0] - if v.exiled_from(sub): abort(400, f"You're exiled from /h/{sub}") + if v.exiler_username(sub): abort(400, f"You're exiled from /h/{sub}") else: sub = None if not sub and HOLE_REQUIRED: diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 36a910cbe0..076de5b505 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -180,7 +180,7 @@ def move_post(post, v, reason): if sub_from == sub_to: abort(409, f"Post is already in {sub_to_in_notif}") - if post.author.exiled_from(sub_to): + if post.author.exiler_username(sub_to): abort(403, f"User is exiled from this {HOLE_NAME}!") if sub_to == 'changelog': diff --git a/files/routes/subs.py b/files/routes/subs.py index ecb051d21b..3dbbdbea1a 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -25,7 +25,7 @@ def exile_post(v, pid): if u.mods(sub): abort(403) - if not u.exiled_from(sub): + if not u.exiler_username(sub): exile = Exile(user_id=u.id, sub=sub, exiler_id=v.id) g.db.add(exile) @@ -60,7 +60,7 @@ def exile_comment(v, cid): if u.mods(sub): abort(403) - if not u.exiled_from(sub): + if not u.exiler_username(sub): exile = Exile(user_id=u.id, sub=sub, exiler_id=v.id) g.db.add(exile) @@ -89,7 +89,7 @@ def unexile(v, sub, uid): if not v.mods(sub): abort(403) if v.shadowbanned: return redirect(f'/h/{sub}/exilees') - if u.exiled_from(sub): + if u.exiler_username(sub): exile = g.db.query(Exile).filter_by(user_id=u.id, sub=sub).one_or_none() g.db.delete(exile) diff --git a/files/templates/comments.html b/files/templates/comments.html index 575bb2e598..12827fe9bb 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -130,8 +130,8 @@ {% if c.parent_post %} {% set sub = c.post.sub %} - {% if sub and c.author.exiled_from(sub) %} - + {% if sub and c.author.exiler_username(sub) %} + {% endif %} {% endif %} @@ -466,8 +466,8 @@ {% if c.parent_post %} {% set sub = c.post.sub %} {% if sub and v.mods(sub) and not c.author.mods(sub) %} - - + + {% endif %} {% endif %} @@ -642,8 +642,8 @@ {% if c.parent_post %} {% set sub = c.post.sub %} {% if sub and v.mods(sub) and not c.author.mods(sub) %} - - + + {% endif %} {% endif %} {% endif %} diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index 621666ea5c..1ca06d383d 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -71,8 +71,8 @@ {% if p.sub and v.mods(p.sub) %} {% if not p.author.mods(p.sub) %} - - + + {% endif %} {% endif %} {% if FEATURES['NSFW_MARKING'] and (v.id==p.author_id or v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (p.sub and v.mods(p.sub))) %} diff --git a/files/templates/post_actions_mobile.html b/files/templates/post_actions_mobile.html index 0e6ec6f7d9..208517218c 100644 --- a/files/templates/post_actions_mobile.html +++ b/files/templates/post_actions_mobile.html @@ -58,7 +58,7 @@ {% if not p.author.mods(p.sub) %} - - + + {% endif %} {% endif %} diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 513967ee2c..d0fb69476e 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -17,8 +17,8 @@ {%- endif %} {% endif %} - {% if p.sub and p.author.exiled_from(p.sub) %} - + {% if p.sub and p.author.exiler_username(p.sub) %} + {% endif %} {% if p.bannedfor %}