mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	realm: Refactor VIDEO_CHAT_PROVIDERS to have all possible options.
Refactors Realm.VIDEO_CHAT_PROIVDERS to have all the possible options for video chat integrations, and use get_enabled_video_chat_providers to compute the enabled options for the realm. Prep for adding Zoom server to server video chat integration.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							ef2f8c0796
						
					
				
				
					commit
					f13a1a48f7
				
			@@ -354,7 +354,7 @@ def fetch_initial_state_data(
 | 
			
		||||
        # can be removed once there are no longer clients relying on it.
 | 
			
		||||
        state["realm_url"] = state["realm_uri"] = realm.url
 | 
			
		||||
        state["realm_bot_domain"] = realm.get_bot_domain()
 | 
			
		||||
        state["realm_available_video_chat_providers"] = realm.VIDEO_CHAT_PROVIDERS
 | 
			
		||||
        state["realm_available_video_chat_providers"] = realm.get_enabled_video_chat_providers()
 | 
			
		||||
        state["settings_send_digest_emails"] = settings.SEND_DIGEST_EMAILS
 | 
			
		||||
 | 
			
		||||
        state["realm_digest_emails_enabled"] = (
 | 
			
		||||
 
 | 
			
		||||
@@ -99,6 +99,11 @@ class OrgTypeDict(TypedDict):
 | 
			
		||||
    onboarding_zulip_guide_url: str | None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class VideoChatProviderDict(TypedDict):
 | 
			
		||||
    name: str
 | 
			
		||||
    id: int
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CommonPolicyEnum(IntEnum):
 | 
			
		||||
    MEMBERS_ONLY = 1
 | 
			
		||||
    ADMINS_ONLY = 2
 | 
			
		||||
@@ -554,7 +559,7 @@ class Realm(models.Model):  # type: ignore[django-manager-missing] # django-stub
 | 
			
		||||
    UPLOAD_QUOTA_STANDARD_FREE = 50
 | 
			
		||||
    custom_upload_quota_gb = models.IntegerField(null=True)
 | 
			
		||||
 | 
			
		||||
    VIDEO_CHAT_PROVIDERS = {
 | 
			
		||||
    VIDEO_CHAT_PROVIDERS: dict[str, VideoChatProviderDict] = {
 | 
			
		||||
        "disabled": {
 | 
			
		||||
            "name": "None",
 | 
			
		||||
            "id": 0,
 | 
			
		||||
@@ -564,19 +569,16 @@ class Realm(models.Model):  # type: ignore[django-manager-missing] # django-stub
 | 
			
		||||
            "id": 1,
 | 
			
		||||
        },
 | 
			
		||||
        # ID 2 was used for the now-deleted Google Hangouts.
 | 
			
		||||
        # ID 3 reserved for optional Zoom, see below.
 | 
			
		||||
        # ID 4 reserved for optional BigBlueButton, see below.
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if settings.VIDEO_ZOOM_CLIENT_ID is not None and settings.VIDEO_ZOOM_CLIENT_SECRET is not None:
 | 
			
		||||
        VIDEO_CHAT_PROVIDERS["zoom"] = {
 | 
			
		||||
        "zoom": {
 | 
			
		||||
            "name": "Zoom",
 | 
			
		||||
            "id": 3,
 | 
			
		||||
        },
 | 
			
		||||
        "big_blue_button": {
 | 
			
		||||
            "name": "BigBlueButton",
 | 
			
		||||
            "id": 4,
 | 
			
		||||
        },
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if settings.BIG_BLUE_BUTTON_SECRET is not None and settings.BIG_BLUE_BUTTON_URL is not None:
 | 
			
		||||
        VIDEO_CHAT_PROVIDERS["big_blue_button"] = {"name": "BigBlueButton", "id": 4}
 | 
			
		||||
 | 
			
		||||
    video_chat_provider = models.PositiveSmallIntegerField(
 | 
			
		||||
        default=VIDEO_CHAT_PROVIDERS["jitsi_meet"]["id"]
 | 
			
		||||
    )
 | 
			
		||||
@@ -937,6 +939,20 @@ class Realm(models.Model):  # type: ignore[django-manager-missing] # django-stub
 | 
			
		||||
    def get_bot_domain(self) -> str:
 | 
			
		||||
        return get_fake_email_domain(self.host)
 | 
			
		||||
 | 
			
		||||
    def get_enabled_video_chat_providers(self) -> dict[str, VideoChatProviderDict]:
 | 
			
		||||
        enabled_video_chat_providers: dict[str, VideoChatProviderDict] = {}
 | 
			
		||||
        for provider in self.VIDEO_CHAT_PROVIDERS:
 | 
			
		||||
            if provider == "zoom" and (
 | 
			
		||||
                settings.VIDEO_ZOOM_CLIENT_ID is None or settings.VIDEO_ZOOM_CLIENT_SECRET is None
 | 
			
		||||
            ):
 | 
			
		||||
                continue
 | 
			
		||||
            if provider == "big_blue_button" and (
 | 
			
		||||
                settings.BIG_BLUE_BUTTON_SECRET is None or settings.BIG_BLUE_BUTTON_URL is None
 | 
			
		||||
            ):
 | 
			
		||||
                continue
 | 
			
		||||
            enabled_video_chat_providers[provider] = self.VIDEO_CHAT_PROVIDERS[provider]
 | 
			
		||||
        return enabled_video_chat_providers
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def max_invites(self) -> int:
 | 
			
		||||
        if self._max_invites is None:
 | 
			
		||||
 
 | 
			
		||||
@@ -1023,23 +1023,43 @@ class RealmTest(ZulipTestCase):
 | 
			
		||||
            get_realm("zulip").video_chat_provider, Realm.VIDEO_CHAT_PROVIDERS["jitsi_meet"]["id"]
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        req = {
 | 
			
		||||
            "video_chat_provider": orjson.dumps(
 | 
			
		||||
                Realm.VIDEO_CHAT_PROVIDERS["big_blue_button"]["id"]
 | 
			
		||||
            ).decode()
 | 
			
		||||
        }
 | 
			
		||||
        big_blue_button_provider_id = Realm.VIDEO_CHAT_PROVIDERS["big_blue_button"]["id"]
 | 
			
		||||
        req = {"video_chat_provider": f"{big_blue_button_provider_id}"}
 | 
			
		||||
        with self.settings(BIG_BLUE_BUTTON_SECRET=None):
 | 
			
		||||
            result = self.client_patch("/json/realm", req)
 | 
			
		||||
            self.assert_json_error(
 | 
			
		||||
                result, f"Invalid video_chat_provider {big_blue_button_provider_id}"
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        with self.settings(BIG_BLUE_BUTTON_URL=None):
 | 
			
		||||
            result = self.client_patch("/json/realm", req)
 | 
			
		||||
            self.assert_json_error(
 | 
			
		||||
                result, f"Invalid video_chat_provider {big_blue_button_provider_id}"
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        result = self.client_patch("/json/realm", req)
 | 
			
		||||
        self.assert_json_success(result)
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            get_realm("zulip").video_chat_provider,
 | 
			
		||||
            Realm.VIDEO_CHAT_PROVIDERS["big_blue_button"]["id"],
 | 
			
		||||
            big_blue_button_provider_id,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        req = {
 | 
			
		||||
            "video_chat_provider": orjson.dumps(Realm.VIDEO_CHAT_PROVIDERS["zoom"]["id"]).decode()
 | 
			
		||||
        }
 | 
			
		||||
        zoom_provider_id = Realm.VIDEO_CHAT_PROVIDERS["zoom"]["id"]
 | 
			
		||||
        req = {"video_chat_provider": f"{zoom_provider_id}"}
 | 
			
		||||
        with self.settings(VIDEO_ZOOM_CLIENT_ID=None):
 | 
			
		||||
            result = self.client_patch("/json/realm", req)
 | 
			
		||||
            self.assert_json_error(result, f"Invalid video_chat_provider {zoom_provider_id}")
 | 
			
		||||
 | 
			
		||||
        with self.settings(VIDEO_ZOOM_CLIENT_SECRET=None):
 | 
			
		||||
            result = self.client_patch("/json/realm", req)
 | 
			
		||||
            self.assert_json_error(result, f"Invalid video_chat_provider {zoom_provider_id}")
 | 
			
		||||
 | 
			
		||||
        result = self.client_patch("/json/realm", req)
 | 
			
		||||
        self.assert_json_success(result)
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            get_realm("zulip").video_chat_provider,
 | 
			
		||||
            zoom_provider_id,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_data_deletion_schedule_when_deactivating_realm(self) -> None:
 | 
			
		||||
        self.login("desdemona")
 | 
			
		||||
 
 | 
			
		||||
@@ -188,7 +188,7 @@ def update_realm(
 | 
			
		||||
            raise JsonableError(_("At least one authentication method must be enabled."))
 | 
			
		||||
 | 
			
		||||
    if video_chat_provider is not None and video_chat_provider not in {
 | 
			
		||||
        p["id"] for p in Realm.VIDEO_CHAT_PROVIDERS.values()
 | 
			
		||||
        p["id"] for p in realm.get_enabled_video_chat_providers().values()
 | 
			
		||||
    }:
 | 
			
		||||
        raise JsonableError(
 | 
			
		||||
            _("Invalid video_chat_provider {video_chat_provider}").format(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user