mirror of https://github.com/zulip/zulip.git
users: Prevent mirror dummy users from being "reactivated."
These do not represent users who were ever active, so they should not be able to be reactivated. See also #26703.
This commit is contained in:
parent
0e4532f8e7
commit
c5373e9934
|
@ -19,6 +19,7 @@ from zerver.lib.avatar import avatar_url
|
|||
from zerver.lib.create_user import create_user
|
||||
from zerver.lib.default_streams import get_slim_realm_default_streams
|
||||
from zerver.lib.email_notifications import enqueue_welcome_emails, send_account_registered_email
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.mention import silent_mention_syntax_for_user
|
||||
from zerver.lib.send_email import clear_scheduled_invitation_emails
|
||||
from zerver.lib.stream_subscription import bulk_get_subscriber_peer_info
|
||||
|
@ -591,6 +592,10 @@ def do_activate_mirror_dummy_user(
|
|||
@transaction.atomic(savepoint=False)
|
||||
def do_reactivate_user(user_profile: UserProfile, *, acting_user: Optional[UserProfile]) -> None:
|
||||
"""Reactivate a user that had previously been deactivated"""
|
||||
if user_profile.is_mirror_dummy:
|
||||
raise JsonableError(
|
||||
_("Cannot activate a placeholder account; ask the user to sign up, instead.")
|
||||
)
|
||||
change_user_is_active(user_profile, True)
|
||||
|
||||
event_time = timezone_now()
|
||||
|
|
|
@ -1567,6 +1567,20 @@ class ActivateTest(ZulipTestCase):
|
|||
result = self.client_post(f"/json/users/{invalid_user_id}/reactivate")
|
||||
self.assert_json_error(result, "No such user")
|
||||
|
||||
def test_api_with_mirrordummy_user(self) -> None:
|
||||
self.login("iago")
|
||||
desdemona = self.example_user("desdemona")
|
||||
change_user_is_active(desdemona, False)
|
||||
|
||||
desdemona.is_mirror_dummy = True
|
||||
desdemona.save(update_fields=["is_mirror_dummy"])
|
||||
|
||||
# Cannot deactivate a user which is marked as "mirror dummy" from importing
|
||||
result = self.client_post(f"/json/users/{desdemona.id}/reactivate")
|
||||
self.assert_json_error(
|
||||
result, "Cannot activate a placeholder account; ask the user to sign up, instead."
|
||||
)
|
||||
|
||||
def test_api_with_insufficient_permissions(self) -> None:
|
||||
non_admin = self.example_user("othello")
|
||||
do_change_user_role(non_admin, UserProfile.ROLE_MEMBER, acting_user=None)
|
||||
|
|
Loading…
Reference in New Issue