Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
models: Rename is_api_super_user to can_forge_sender,
Mateusz Manderad0dc04a0934e
diff --git a/docs/production/management-commands.md b/docs/production/management-commands.mdindex f3cf8cf04a1..dd458fee1b0 100644--- a/docs/production/management-commands.md+++ b/docs/production/management-commands.md@@ -119,8 +119,8 @@ There are dozens of useful management commands under* `./manage.py change_user_email`: Change a user's email address.* `./manage.py change_user_role`: Can change are user's role(easier done [via the- UI](https://zulip.com/help/change-a-users-role)) or create an- `api_super_user`, which are needed for certain special API features.+ UI](https://zulip.com/help/change-a-users-role)) or give bots the+ `can_forge_sender` permission, which is needed for certain special API features.* `./manage.py export_single_user` does a limited version of the [mainexport tools](../production/export-and-import.md) containing justthe messages accessible by a single user.diff --git a/docs/production/security-model.md b/docs/production/security-model.mdindex e6165f1dd56..95b5281c491 100644--- a/docs/production/security-model.md+++ b/docs/production/security-model.md@@ -186,14 +186,14 @@ strength allowed is controlled by two settings innon-administrator user can, with a few exceptions (e.g. a bot cannotlog in to the web application, register for mobile pushnotifications, or create other bots).- * API super user bots can send messages that appear to have been sent by+ * Bots with the `can_forge_sender` permission can send messages that appear to have been sent byanother user. They also have the ability to see the names of allstreams, including private streams. This is important for implementingintegrations like the Jabber, IRC, and Zephyr mirrors.- API super user bots cannot be created by Zulip users, including+ These bots cannot be created by Zulip users, includingorganization owners. They can only be created on the command- line (via `manage.py change_user_role api_super_user`).+ line (via `manage.py change_user_role can_forge_sender`).## User-uploaded contentdiff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 30e25e9b1f7..8385aa741b7 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -3617,9 +3617,9 @@ def do_change_user_role(user_profile: UserProfile, value: int, acting_user: Optiperson=dict(user_id=user_profile.id, role=user_profile.role))send_event(user_profile.realm, event, active_user_ids(user_profile.realm_id))-def do_change_is_api_super_user(user_profile: UserProfile, value: bool) -> None:- user_profile.is_api_super_user = value- user_profile.save(update_fields=["is_api_super_user"])+def do_change_can_forge_sender(user_profile: UserProfile, value: bool) -> None:+ user_profile.can_forge_sender = value+ user_profile.save(update_fields=["can_forge_sender"])def do_change_stream_invite_only(stream: Stream, invite_only: bool,history_public_to_subscribers: Optional[bool]=None) -> None:@@ -5677,7 +5677,7 @@ def do_get_streams() -> List[Dict[str, Any]]:# This function is only used by API clients now.- if include_all_active and not user_profile.is_api_super_user:+ if include_all_active and not user_profile.can_forge_sender:raise JsonableError(_("User not authorized for this query"))include_public = include_public and user_profile.can_access_public_streams()diff --git a/zerver/lib/server_initialization.py b/zerver/lib/server_initialization.pyindex 8d69b3b793e..9f953848d57 100644--- a/zerver/lib/server_initialization.py+++ b/zerver/lib/server_initialization.py@@ -10,7 +10,7 @@ def server_initialized() -> bool:return Realm.objects.exists()def create_internal_realm() -> None:- from zerver.lib.actions import do_change_is_api_super_user+ from zerver.lib.actions import do_change_can_forge_senderrealm = Realm.objects.create(string_id=settings.SYSTEM_BOT_REALM)@@ -31,9 +31,9 @@ def create_internal_realm() -> None:bot.bot_owner = botbot.save()- # Initialize the email gateway bot as an API Super User+ # Initialize the email gateway bot as able to forge senders.email_gateway_bot = get_system_bot(settings.EMAIL_GATEWAY_BOT)- do_change_is_api_super_user(email_gateway_bot, True)+ do_change_can_forge_sender(email_gateway_bot, True)def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]],tos_version: Optional[str]=None,diff --git a/zerver/lib/streams.py b/zerver/lib/streams.pyindex 1b7c0f96f90..1238b1ea3f0 100644--- a/zerver/lib/streams.py+++ b/zerver/lib/streams.py@@ -205,10 +205,10 @@ def access_stream_for_send_message(sender: UserProfile,# It is private, but your are subscribedreturn- if sender.is_api_super_user:+ if sender.can_forge_sender:return- if (forwarder_user_profile is not None and forwarder_user_profile.is_api_super_user):+ if (forwarder_user_profile is not None and forwarder_user_profile.can_forge_sender):returnif sender.is_bot and (sender.bot_owner is not None anddiff --git a/zerver/management/commands/change_user_role.py b/zerver/management/commands/change_user_role.pyindex 69e686021ad..0c5cf0702f7 100644--- a/zerver/management/commands/change_user_role.py+++ b/zerver/management/commands/change_user_role.py@@ -3,7 +3,7 @@ from typing import Anyfrom django.core.management.base import CommandError-from zerver.lib.actions import do_change_is_api_super_user, do_change_user_role+from zerver.lib.actions import do_change_can_forge_sender, do_change_user_rolefrom zerver.lib.management import ZulipBaseCommandfrom zerver.models import UserProfile@@ -18,12 +18,12 @@ ONLY perform this on customer request from an authorized person.parser.add_argument('email', metavar='<email>',help="email of user to change role")parser.add_argument('new_role', metavar='<new_role>',- choices=['owner', 'admin', 'member', 'guest', 'api_super_user'],+ choices=['owner', 'admin', 'member', 'guest', 'can_forge_sender'],help="new role of the user")parser.add_argument('--revoke',dest='grant',action="store_false",- help='Remove an api_super_user\'s rights.')+ help='Remove can_forge_sender permission.')self.add_realm_args(parser, True)def handle(self, *args: Any, **options: Any) -> None:@@ -37,7 +37,7 @@ ONLY perform this on customer request from an authorized person.'member': UserProfile.ROLE_MEMBER,'guest': UserProfile.ROLE_GUEST}- if options['new_role'] != 'api_super_user':+ if options['new_role'] != 'can_forge_sender':new_role = user_role_map[options['new_role']]if not options['grant']:raise CommandError("Revoke not supported with this permission; please specify new role.")@@ -48,10 +48,10 @@ ONLY perform this on customer request from an authorized person.new_role_name = UserProfile.ROLE_ID_TO_NAME_MAP[user.role]print(f"Role for {user.delivery_email} changed from {old_role_name} to {new_role_name}.")else:- if user.is_api_super_user and options['grant']:- raise CommandError("User is already api super user for this realm.")- elif not user.is_api_super_user and not options['grant']:- raise CommandError("User is not api super user for this realm.")- do_change_is_api_super_user(user, options['grant'])+ if user.can_forge_sender and options['grant']:+ raise CommandError("User can already forge messages for this realm.")+ elif not user.can_forge_sender and not options['grant']:+ raise CommandError("User can't forge messages for this realm.")+ do_change_can_forge_sender(user, options['grant'])granted_text = "have" if options['grant'] else "not have"print(f"{user.delivery_email} changed to {granted_text} {options['new_role']} permission.")diff --git a/zerver/migrations/0307_rename_api_super_user_to_can_forge_sender.py b/zerver/migrations/0307_rename_api_super_user_to_can_forge_sender.pynew file mode 100644index 00000000000..0ed8167a5db--- /dev/null+++ b/zerver/migrations/0307_rename_api_super_user_to_can_forge_sender.py@@ -0,0 +1,18 @@+# Generated by Django 2.2.17 on 2020-12-20 13:06++from django.db import migrations+++class Migration(migrations.Migration):++ dependencies = [+ ('zerver', '0306_custom_profile_field_date_format'),+ ]++ operations = [+ migrations.RenameField(+ model_name='userprofile',+ old_name='is_api_super_user',+ new_name='can_forge_sender',+ ),+ ]diff --git a/zerver/models.py b/zerver/models.pyindex 7f3d15fcc84..87797bec804 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -988,9 +988,9 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):# like native Zulip messages (with a name + avatar, etc.).is_mirror_dummy: bool = models.BooleanField(default=False)- # API super users are allowed to forge messages as sent by another+ # Users with this flag set are allowed to forge messages as sent by another# user and to send to private streams; also used for Zephyr/Jabber mirroring.- is_api_super_user: bool = models.BooleanField(default=False, db_index=True)+ can_forge_sender: bool = models.BooleanField(default=False, db_index=True)### Notifications settings. ###diff --git a/zerver/tests/test_cache.py b/zerver/tests/test_cache.pyindex 7c1dc0b6be1..da37be067da 100644--- a/zerver/tests/test_cache.py+++ b/zerver/tests/test_cache.py@@ -260,17 +260,17 @@ class BotCacheKeyTest(ZulipTestCase):self.assertEqual(user_profile, bot_profile)# Flip the setting and save:- flipped_setting = not bot_profile.is_api_super_user- bot_profile.is_api_super_user = flipped_setting+ flipped_setting = not bot_profile.can_forge_sender+ bot_profile.can_forge_sender = flipped_settingbot_profile.save()# The .save() should have deleted cache keys, so if we fetch again,- # the returned objects should have is_api_super_user set correctly.+ # the returned objects should have can_forge_sender set correctly.bot_profile2 = get_system_bot(settings.EMAIL_GATEWAY_BOT)- self.assertEqual(bot_profile2.is_api_super_user, flipped_setting)+ self.assertEqual(bot_profile2.can_forge_sender, flipped_setting)user_profile2 = get_user_profile_by_email(settings.EMAIL_GATEWAY_BOT)- self.assertEqual(user_profile2.is_api_super_user, flipped_setting)+ self.assertEqual(user_profile2.can_forge_sender, flipped_setting)def get_user_email(user: UserProfile) -> str:return user.email # nocoveragediff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.pyindex bef1931ac89..37f4d27c348 100644--- a/zerver/tests/test_message_send.py+++ b/zerver/tests/test_message_send.py@@ -15,7 +15,7 @@ from zerver.lib.actions import (build_message_send_dict,check_message,check_send_stream_message,- do_change_is_api_super_user,+ do_change_can_forge_sender,do_change_stream_post_policy,do_create_user,do_deactivate_user,@@ -677,7 +677,7 @@ class MessagePOSTTest(ZulipTestCase):user = self.example_user("default_bot")password = "test_password"user.set_password(password)- user.is_api_super_user = True+ user.can_forge_sender = Trueuser.save()result = self.api_post(user,"/api/v1/messages", {"type": "stream",@@ -686,7 +686,7 @@ class MessagePOSTTest(ZulipTestCase):"content": "Test message","topic": "Test topic","realm_str": "non-existing"})- user.is_api_super_user = False+ user.can_forge_sender = Falseuser.save()self.assert_json_error(result, "Unknown organization 'non-existing'")@@ -765,7 +765,7 @@ class MessagePOSTTest(ZulipTestCase):email = "[email protected]"user = get_user(email, get_realm('zulip'))- user.is_api_super_user = True+ user.can_forge_sender = Trueuser.save()user = get_user(email, get_realm('zulip'))self.subscribe(user, "IRCland")@@ -804,7 +804,7 @@ class MessagePOSTTest(ZulipTestCase):msg = self.get_last_message()self.assertEqual(int(datetime_to_timestamp(msg.date_sent)), int(fake_timestamp))- def test_unsubscribed_api_super_user(self) -> None:+ def test_unsubscribed_can_forge_sender(self) -> None:reset_emails_in_zulip_realm()cordelia = self.example_user('cordelia')@@ -813,7 +813,7 @@ class MessagePOSTTest(ZulipTestCase):self.unsubscribe(cordelia, stream_name)- # As long as Cordelia is a super_user, she can send messages+ # As long as Cordelia cam_forge_sender, she can send messages# to ANY stream, even one she is not unsubscribed to, and# she can do it for herself or on behalf of a mirrored user.@@ -831,13 +831,13 @@ class MessagePOSTTest(ZulipTestCase):if forged:payload['sender'] = sender_email- cordelia.is_api_super_user = False+ cordelia.can_forge_sender = Falsecordelia.save()result = self.api_post(cordelia, "/api/v1/messages", payload)self.assert_json_error_contains(result, 'authorized')- cordelia.is_api_super_user = True+ cordelia.can_forge_sender = Truecordelia.save()result = self.api_post(cordelia, "/api/v1/messages", payload)@@ -1431,7 +1431,7 @@ class StreamMessagesTest(ZulipTestCase):user = self.mit_user('starnine')self.subscribe(user, 'Verona')- do_change_is_api_super_user(user, True)+ do_change_can_forge_sender(user, True)result = self.api_post(user, "/api/v1/messages", {"type": "stream","to": "Verona","sender": self.mit_email("sipbtest"),@@ -1442,7 +1442,7 @@ class StreamMessagesTest(ZulipTestCase):subdomain="zephyr")self.assert_json_success(result)- do_change_is_api_super_user(user, False)+ do_change_can_forge_sender(user, False)result = self.api_post(user, "/api/v1/messages", {"type": "stream","to": "Verona","sender": self.mit_email("sipbtest"),diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.pyindex 339063e93fe..42a662620ba 100644--- a/zerver/tests/test_slack_importer.py+++ b/zerver/tests/test_slack_importer.py@@ -355,7 +355,7 @@ class SlackImporter(ZulipTestCase):self.assertEqual(zerver_userprofile[3]['realm'], 1)self.assertEqual(zerver_userprofile[3]['full_name'], 'Matt Perry')self.assertEqual(zerver_userprofile[3]['is_mirror_dummy'], True)- self.assertEqual(zerver_userprofile[3]['is_api_super_user'], False)+ self.assertEqual(zerver_userprofile[3]['can_forge_sender'], False)self.assertEqual(zerver_userprofile[4]['id'], test_slack_user_id_to_zulip_user_id['U8VAHEVUY'])self.assertEqual(zerver_userprofile[4]['role'], UserProfile.ROLE_GUEST)diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex d50edff6caf..d62ca4a7a85 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -3962,7 +3962,7 @@ class GetStreamsTest(ZulipTestCase):we just "knight" Hamlet for testing expediency.'''super_user = self.example_user('hamlet')- super_user.is_api_super_user = True+ super_user.can_forge_sender = Truesuper_user.save()result = self.api_get(super_user, url, data)diff --git a/zerver/views/message_send.py b/zerver/views/message_send.pyindex ea01200a023..c293d194636 100644--- a/zerver/views/message_send.py+++ b/zerver/views/message_send.py@@ -205,13 +205,13 @@ def send_message_backend(request: HttpRequest, user_profile: UserProfile,forged = forged_str is not None and forged_str in ["yes", "true"]client = request.client- is_super_user = request.user.is_api_super_user- if forged and not is_super_user:+ can_forge_sender = request.user.can_forge_sender+ if forged and not can_forge_sender:return json_error(_("User not authorized for this query"))realm = Noneif realm_str and realm_str != user_profile.realm.string_id:- if not is_super_user:+ if not can_forge_sender:# The email gateway bot needs to be able to send messages in# any realm.return json_error(_("User not authorized for this query"))@@ -236,7 +236,7 @@ def send_message_backend(request: HttpRequest, user_profile: UserProfile,# same-realm constraint.if "sender" not in request.POST:return json_error(_("Missing sender"))- if message_type_name != "private" and not is_super_user:+ if message_type_name != "private" and not can_forge_sender:return json_error(_("User not authorized for this query"))# For now, mirroring only works with recipient emails, not for