Browse Source

Rework disallowing self bans by using the user ACL instead.

merge-requests/158/head
Bauke 2 months ago
parent
commit
4dd987a1d5
  1. 1
      tildes/tildes/models/user/user.py
  2. 2
      tildes/tildes/templates/user.jinja2
  3. 4
      tildes/tildes/views/api/web/user.py

1
tildes/tildes/models/user/user.py

@ -213,6 +213,7 @@ class User(DatabaseModel):
if self.is_deleted: if self.is_deleted:
acl.append((Deny, Everyone, "ban")) acl.append((Deny, Everyone, "ban"))
acl.append((Deny, self.user_id, "ban"))
acl.append((Allow, "*:user.ban", "ban")) acl.append((Allow, "*:user.ban", "ban"))
# view_removed_posts: # view_removed_posts:

2
tildes/tildes/templates/user.jinja2

@ -189,7 +189,7 @@
<a href="/user/{{ user.username }}/new_message" class="btn btn-primary">Send a private message</a> <a href="/user/{{ user.username }}/new_message" class="btn btn-primary">Send a private message</a>
{% endif %} {% endif %}
{% if request.user != user and request.has_permission("ban", user) %}
{% if request.has_permission("ban", user) %}
<div class="divider"></div> <div class="divider"></div>
{% if user.is_banned %} {% if user.is_banned %}
<button class="btn" <button class="btn"

4
tildes/tildes/views/api/web/user.py

@ -10,7 +10,6 @@ from typing import Optional
from marshmallow import ValidationError from marshmallow import ValidationError
from marshmallow.fields import String from marshmallow.fields import String
from pyramid.httpexceptions import ( from pyramid.httpexceptions import (
HTTPBadRequest,
HTTPForbidden, HTTPForbidden,
HTTPUnauthorized, HTTPUnauthorized,
HTTPUnprocessableEntity, HTTPUnprocessableEntity,
@ -407,9 +406,6 @@ def put_user_ban(request: Request) -> Response:
"""Ban a user.""" """Ban a user."""
user = request.context user = request.context
if request.user == user:
raise HTTPBadRequest("You cannot ban yourself")
user.is_banned = True user.is_banned = True
# delete all of the user's outstanding invite codes # delete all of the user's outstanding invite codes

Loading…
Cancel
Save