Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
import_realm: Reset special user permissions at import time.
Mateusz Mandera61f910d9c440
diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.pyindex fb3a1e8508f..e50ff2a962f 100644--- a/zerver/lib/import_realm.py+++ b/zerver/lib/import_realm.py@@ -1564,6 +1564,9 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Reafor user_profile_dict in data["zerver_userprofile"]:user_profile_dict["password"] = Noneuser_profile_dict["api_key"] = generate_api_key()+ for field_name in UserProfile.SPECIAL_PERMISSIONS_TO_RESET_AT_IMPORT:+ del user_profile_dict[field_name]+# Since Zulip doesn't use these permissions, drop themdel user_profile_dict["user_permissions"]del user_profile_dict["groups"]diff --git a/zerver/models/users.py b/zerver/models/users.pyindex 92825d01e85..213078383d0 100644--- a/zerver/models/users.py+++ b/zerver/models/users.py@@ -477,6 +477,17 @@ class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings):EMBEDDED_BOT,]+ # Certain fields can imply an unusually elevated level of permissions+ # for the user in some way. Such privileges generally should not be+ # carried over to a new server at import time.+ SPECIAL_PERMISSIONS_TO_RESET_AT_IMPORT = [+ "is_staff",+ "can_forge_sender",+ "can_create_users",+ "can_change_user_emails",+ "rate_limits",+ ]+id = models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")# For historical reasons, Zulip has two email fields. The