From ceee02fbce3469849a1e34ed351a5d9dbe2d7ccc Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 25 Jan 2023 17:41:46 +0200 Subject: [PATCH] add button to blacklist users from restricted holes --- files/classes/user.py | 7 +-- files/helpers/config/const.py | 2 + files/helpers/config/modaction_types.py | 10 +++++ files/routes/admin.py | 43 +++++++++++++++++++ files/templates/userpage/admintools.html | 7 +++ ...-blacklist-users-from-restricted-holes.sql | 2 + 6 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 migrations/20230125-add-button-to-blacklist-users-from-restricted-holes.sql diff --git a/files/classes/user.py b/files/classes/user.py index 72df00005..62b582141 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -158,6 +158,7 @@ class User(Base): marsify = Column(Integer, default=0) rainbow = Column(Integer) spider = Column(Integer, default=0) + blacklisted_by = Column(Integer, ForeignKey("users.id")) if IS_FISTMAS(): event_music = Column(Boolean, default=default_event_music, nullable=False) @@ -979,7 +980,7 @@ class User(Base): @property @lazy def can_see_chudrama(self): - if self.id == 2074: return False + if self.blacklisted_by: return False if self.shadowbanned: return False if self.is_suspended_permanently: return False if self.admin_level >= PERMS['VIEW_CHUDRAMA']: return True @@ -992,7 +993,7 @@ class User(Base): @property @lazy def can_see_countryclub(self): - if self.id == 2074: return False + if self.blacklisted_by: return False if self.shadowbanned: return False if self.is_suspended_permanently: return False if self.agendaposter == 1: return False @@ -1003,7 +1004,7 @@ class User(Base): @property @lazy def can_see_masterbaiters(self): - if self.id == 2074: return False + if self.blacklisted_by: return False if self.shadowbanned: return False if self.is_suspended_permanently: return False if self.truescore >= TRUESCORE_MASTERBAITERS_MINIMUM: return True diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 9166e2ff3..b4c169236 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -469,6 +469,7 @@ PERMS = { # Minimum admin_level to perform action. 'APPS_MODERATION': 3, 'VIEW_DM_IMAGES': 3, 'MODERATE_PENDING_SUBMITTED_ASSETS': 4, + 'USER_BLACKLIST': 5, 'POST_EDITING': 5, 'UPDATE_ASSETS': 5, 'VIEW_PATRONS': 5, @@ -792,6 +793,7 @@ elif SITE == 'watchpeopledie.tv': PERMS['HOLE_CREATE'] = 2 PERMS['POST_EDITING'] = 2 PERMS['ADMIN_ADD'] = 4 + PERMS['USER_BLACKLIST'] = 6 SUB_BANNER_LIMIT = 69420 POLL_MAX_OPTIONS = 50 diff --git a/files/helpers/config/modaction_types.py b/files/helpers/config/modaction_types.py index 2f54c963b..0e59fd69d 100644 --- a/files/helpers/config/modaction_types.py +++ b/files/helpers/config/modaction_types.py @@ -41,6 +41,11 @@ MODACTION_TYPES = { "icon": 'fa-user-slash', "color": 'bg-danger' }, + 'blacklist_user': { + "str": 'blacklisted user {self.target_link} from restricted holes', + "icon": 'fa-lock', + "color": 'bg-danger' + }, 'delete_report': { "str": 'deleted report on {self.target_link}', "icon": 'fa-flag', @@ -301,6 +306,11 @@ MODACTION_TYPES = { "icon": 'fa-user', "color": 'bg-success' }, + 'unblacklist_user': { + "str": 'unblacklisted user {self.target_link} from restricted holes', + "icon": 'fa-lock-open', + "color": 'bg-success' + }, 'undistinguish_comment': { "str": 'un-distinguished {self.target_link}', "icon": 'fa-crown', diff --git a/files/routes/admin.py b/files/routes/admin.py index af0b6c831..ab2c1933d 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1594,3 +1594,46 @@ def admin_nunuke_user(v): g.db.add(ma) return {"message": f"@{user.username}'s content has been approved!"} + +@app.post("/blacklist/") +@limiter.limit(DEFAULT_RATELIMIT_SLOWER) +@limiter.limit(DEFAULT_RATELIMIT_SLOWER, key_func=get_ID) +@admin_level_required(PERMS['USER_BLACKLIST']) +def blacklist_user(user_id, v): + user = get_account(user_id) + if user.admin_level > v.admin_level: + abort(403) + user.blacklisted_by = v.id + g.db.add(user) + check_for_alts(user) + + ma = ModAction( + kind="blacklist_user", + user_id=v.id, + target_user_id=user.id + ) + g.db.add(ma) + + return {"message": f"@{user.username} has been blacklisted from restricted holes!"} + +@app.post("/unblacklist/") +@limiter.limit(DEFAULT_RATELIMIT_SLOWER) +@limiter.limit(DEFAULT_RATELIMIT_SLOWER, key_func=get_ID) +@admin_level_required(PERMS['USER_BLACKLIST']) +def unblacklist_user(user_id, v): + user = get_account(user_id) + user.blacklisted_by = None + g.db.add(user) + + for alt in get_alt_graph(user.id): + alt.blacklisted_by = None + g.db.add(alt) + + ma = ModAction( + kind="unblacklist_user", + user_id=v.id, + target_user_id=user.id + ) + g.db.add(ma) + + return {"message": f"@{user.username} has been unblacklisted from restricted holes!"} diff --git a/files/templates/userpage/admintools.html b/files/templates/userpage/admintools.html index 24d155f03..404164315 100644 --- a/files/templates/userpage/admintools.html +++ b/files/templates/userpage/admintools.html @@ -101,6 +101,13 @@ {% endif %} + + {% if v.admin_level >= PERMS['USER_BLACKLIST'] %} + + + + {% endif %} + {% endif %} diff --git a/migrations/20230125-add-button-to-blacklist-users-from-restricted-holes.sql b/migrations/20230125-add-button-to-blacklist-users-from-restricted-holes.sql new file mode 100644 index 000000000..4a6666c64 --- /dev/null +++ b/migrations/20230125-add-button-to-blacklist-users-from-restricted-holes.sql @@ -0,0 +1,2 @@ +alter table users add column blacklisted_by int; +alter table users add constraint user_blacklisted_by_fkey foreign key (blacklisted_by) references users(id);