add button to blacklist users from restricted holes

master
Aevann 2023-01-25 17:41:46 +02:00
parent f8822ac14d
commit ceee02fbce
6 changed files with 68 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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',

View File

@ -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/<int:user_id>")
@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/<int:user_id>")
@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!"}

View File

@ -101,6 +101,13 @@
<input type="submit" data-nonce="{{g.nonce}}" data-onclick="disable(this)" class="btn btn-danger" value="Remove User's Content">
</form>
{% endif %}
{% if v.admin_level >= PERMS['USER_BLACKLIST'] %}
<button type="button" id="unblacklist-{{deviceType}}" class="mt-1 {% if not u.blacklisted_by %}d-none{% endif %} btn btn-success" data-nonce="{{g.nonce}}" data-onclick="postToastSwitch(this,'/unblacklist/{{u.id}}','blacklist-{{deviceType}}','unblacklist-{{deviceType}}','d-none')">Unblacklist From Restricted Holes</button>
<button type="button" id="blacklist-{{deviceType}}" class="mt-1 {% if u.blacklisted_by %}d-none{% endif %} btn btn-danger" data-nonce="{{g.nonce}}" data-onclick="postToastSwitch(this,'/blacklist/{{u.id}}','blacklist-{{deviceType}}','unblacklist-{{deviceType}}','d-none')">Blacklist From Restricted Holes</button>
{% endif %}
</div>
</div>
{% endif %}

View File

@ -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);