Don't allow self-mute and self-block

Fixes #454
This commit is contained in:
Andrew Godwin 2023-01-20 09:31:15 -07:00
parent 10c7da96c7
commit f150a3eee9
2 changed files with 13 additions and 1 deletions

View File

@ -45,7 +45,7 @@
{% endif %} {% endif %}
</form> </form>
{% endif %} {% endif %}
{% if not outbound_block %} {% if request.identity != identity and not outbound_block %}
<form action="{{ identity.urls.action }}" method="POST" class="inline"> <form action="{{ identity.urls.action }}" method="POST" class="inline">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="action" value="block"> <input type="hidden" name="action" value="block">

View File

@ -77,12 +77,16 @@ class IdentityService:
Follows a user (or does nothing if already followed). Follows a user (or does nothing if already followed).
Returns the follow. Returns the follow.
""" """
if from_identity == self.identity:
raise ValueError("You cannot follow yourself")
return Follow.create_local(from_identity, self.identity, boosts=boosts) return Follow.create_local(from_identity, self.identity, boosts=boosts)
def unfollow_from(self, from_identity: Identity): def unfollow_from(self, from_identity: Identity):
""" """
Unfollows a user (or does nothing if not followed). Unfollows a user (or does nothing if not followed).
""" """
if from_identity == self.identity:
raise ValueError("You cannot unfollow yourself")
existing_follow = Follow.maybe_get(from_identity, self.identity) existing_follow = Follow.maybe_get(from_identity, self.identity)
if existing_follow: if existing_follow:
existing_follow.transition_perform(FollowStates.undone) existing_follow.transition_perform(FollowStates.undone)
@ -98,6 +102,8 @@ class IdentityService:
""" """
Blocks a user. Blocks a user.
""" """
if from_identity == self.identity:
raise ValueError("You cannot block yourself")
self.unfollow_from(from_identity) self.unfollow_from(from_identity)
block = Block.create_local_block(from_identity, self.identity) block = Block.create_local_block(from_identity, self.identity)
InboxMessage.create_internal( InboxMessage.create_internal(
@ -114,6 +120,8 @@ class IdentityService:
""" """
Unlocks a user Unlocks a user
""" """
if from_identity == self.identity:
raise ValueError("You cannot unblock yourself")
existing_block = Block.maybe_get(from_identity, self.identity, mute=False) existing_block = Block.maybe_get(from_identity, self.identity, mute=False)
if existing_block and existing_block.active: if existing_block and existing_block.active:
existing_block.transition_perform(BlockStates.undone) existing_block.transition_perform(BlockStates.undone)
@ -127,6 +135,8 @@ class IdentityService:
""" """
Mutes a user. Mutes a user.
""" """
if from_identity == self.identity:
raise ValueError("You cannot mute yourself")
return Block.create_local_mute( return Block.create_local_mute(
from_identity, from_identity,
self.identity, self.identity,
@ -138,6 +148,8 @@ class IdentityService:
""" """
Unmutes a user Unmutes a user
""" """
if from_identity == self.identity:
raise ValueError("You cannot unmute yourself")
existing_block = Block.maybe_get(from_identity, self.identity, mute=True) existing_block = Block.maybe_get(from_identity, self.identity, mute=True)
if existing_block and existing_block.active: if existing_block and existing_block.active:
existing_block.transition_perform(BlockStates.undone) existing_block.transition_perform(BlockStates.undone)