add shadowban_reason column to stop the endless confusion and overwriting

master
Aevann 2024-02-11 16:40:22 +02:00
parent 3099ec3f34
commit cf264bae48
10 changed files with 19 additions and 21 deletions

View File

@ -115,6 +115,7 @@ class User(Base):
is_banned = Column(Integer, ForeignKey("users.id"))
unban_utc = Column(Integer)
ban_reason = deferred(Column(String))
shadowban_reason = deferred(Column(String))
is_muted = Column(Boolean, default=False)
login_nonce = Column(Integer, default=0)
coins = Column(Integer, default=DEFAULT_COINS)

View File

@ -540,7 +540,7 @@ def execute_under_siege(v, target, body, kind):
if v.shadowbanned: return
v.shadowbanned = AUTOJANNY_ID
v.ban_reason = "Under Siege"
v.shadowban_reason = "Under Siege"
g.db.add(v)
if kind == "report":

View File

@ -148,7 +148,7 @@ def execute_blackjack(v, target, body, kind):
)
g.db.add(ma)
v.ban_reason = f"Blackjack: {kind}"
v.shadowban_reason = f"Blackjack: {kind}"
g.db.add(v)
notified_ids = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['BLACKJACK_NOTIFICATIONS'])]

View File

@ -256,6 +256,7 @@ def revert_actions(v, username):
user.shadowbanned = None
user.unban_utc = None
user.ban_reason = None
user.shadowban_reason = None
if user.is_banned:
user.is_banned = None
send_repeatable_notification(user.id, f"@{v.username} (a site admin) has unbanned you!")
@ -265,6 +266,7 @@ def revert_actions(v, username):
u.shadowbanned = None
u.unban_utc = None
u.ban_reason = None
u.shadowban_reason = None
if u.is_banned:
u.is_banned = None
send_repeatable_notification(u.id, f"@{v.username} (a site admin) has unbanned you!")
@ -882,7 +884,7 @@ def shadowban(user_id, v):
if len(reason) > 256:
abort(400, "Ban reason too long!")
user.ban_reason = reason
user.shadowban_reason = reason
g.db.add(user)
check_for_alts(user)
@ -907,12 +909,12 @@ def shadowban(user_id, v):
def unshadowban(user_id, v):
user = get_account(user_id)
user.shadowbanned = None
if not user.is_banned: user.ban_reason = None
user.shadowban_reason = None
g.db.add(user)
for alt in get_alt_graph(user.id):
alt.shadowbanned = None
if not alt.is_banned: alt.ban_reason = None
alt.shadowban_reason = None
g.db.add(alt)
ma = ModAction(
@ -1214,8 +1216,7 @@ def unban_user(fullname, v):
user.is_banned = None
user.unban_utc = None
if not user.shadowbanned:
user.ban_reason = None
user.ban_reason = None
send_repeatable_notification(user.id, f"@{v.username} (a site admin) has unbanned you!")
g.db.add(user)
@ -1223,8 +1224,7 @@ def unban_user(fullname, v):
if x.is_banned: send_repeatable_notification(x.id, f"@{v.username} (a site admin) has unbanned you!")
x.is_banned = None
x.unban_utc = None
if not x.shadowbanned:
x.ban_reason = None
x.ban_reason = None
g.db.add(x)
ma = ModAction(

View File

@ -292,8 +292,7 @@ def award_thing(v, thing_type, id):
else:
author.unban_utc = None
author.is_banned = None
if not author.shadowbanned:
author.ban_reason = None
author.ban_reason = None
send_repeatable_notification(author.id, "You have been unbanned!")
elif kind == "grass":
link3 = f"/{thing_type}/{obj.id}"

View File

@ -103,11 +103,11 @@ def check_for_alts(current, include_current_session=False):
for u in get_alt_graph(current.id):
if u.shadowbanned and not current.shadowbanned:
current.shadowbanned = u.shadowbanned
current.ban_reason = u.ban_reason
current.shadowban_reason = u.shadowban_reason
g.db.add(current)
elif current.shadowbanned and not u.shadowbanned:
u.shadowbanned = current.shadowbanned
u.ban_reason = current.ban_reason
u.shadowban_reason = current.shadowban_reason
g.db.add(u)
elif u.is_permabanned and not current.is_permabanned:
current.is_banned = u.is_banned
@ -120,11 +120,6 @@ def check_for_alts(current, include_current_session=False):
u.unban_utc = None
g.db.add(u)
if current.ban_reason == "Under Siege" and u.ban_reason and u.ban_reason != "Under Siege":
current.ban_reason = u.ban_reason
elif u.ban_reason == "Under Siege" and current.ban_reason and current.ban_reason != "Under Siege":
u.ban_reason = current.ban_reason
if u.is_muted and not current.is_muted:
current.is_muted = u.is_muted
g.db.add(current)

View File

@ -27,7 +27,7 @@
<tr>
<td data-sort-key="{{user.username.lower() if user else ''}}">{%- include 'user_in_table.html' -%}</td>
<td>{{user.truescore}}</td>
<td>{{user.ban_reason | safe}}</td>
<td>{{user.shadowban_reason | safe}}</td>
<td><a href="/{{user.shadowbanned_by}}">{{user.shadowbanned_by}}</a></td>
<td {% if user.last_active %}data-time="{{user.last_active}}"{% endif %}></td>
</tr>

View File

@ -1,3 +1,3 @@
{% if user.shadowbanned and v and v.admin_level >= PERMS['USER_SHADOWBAN'] %}
<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title='Shadowbanned by {{user.shadowbanned_by}} for "{{user.ban_reason}}"' data-bs-html="true"></i>
<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title='Shadowbanned by {{user.shadowbanned_by}} for "{{user.shadowban_reason}}"' data-bs-html="true"></i>
{% endif %}

View File

@ -23,7 +23,7 @@
{% endif %}
{% if v and v.admin_level >= PERMS['USER_SHADOWBAN'] and u.shadowbanned %}
<h5 class="text-primary" id="profile-{{deviceType}}--shadowbanned">SHADOWBANNED USER:
{{u.ban_reason | safe}}
{{u.shadowban_reason | safe}}
(by <a href="/{{u.shadowbanned_by}}">{{u.shadowbanned_by}}</a>)
</h5>

View File

@ -0,0 +1,3 @@
alter table users add column shadowban_reason varchar(256);
update users set shadowban_reason=ban_reason where shadowbanned is not null;
update users set ban_reason=null where is_banned is null and ban_reason is not null;