mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	compose_validate: Remove autosubscribe feature.
This was only used in the undocumented narrow_stream mode, and relied on a deprecated synchronous XHR request. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							a7dc7c0734
						
					
				
				
					commit
					807a4428f6
				
			@@ -5253,107 +5253,6 @@ class SubscriptionAPITest(ZulipTestCase):
 | 
			
		||||
        )
 | 
			
		||||
        self.assert_json_error(result, f"Stream(s) ({random_streams[0]}) do not exist")
 | 
			
		||||
 | 
			
		||||
    def helper_subscriptions_exists(
 | 
			
		||||
        self, stream: str, expect_success: bool, subscribed: bool
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Call /json/subscriptions/exists on a stream and expect a certain result.
 | 
			
		||||
        """
 | 
			
		||||
        result = self.client_post("/json/subscriptions/exists", {"stream": stream})
 | 
			
		||||
        if expect_success:
 | 
			
		||||
            json = self.assert_json_success(result)
 | 
			
		||||
        else:
 | 
			
		||||
            self.assertEqual(result.status_code, 404)
 | 
			
		||||
            json = result.json()
 | 
			
		||||
        if subscribed:
 | 
			
		||||
            self.assertIn("subscribed", json)
 | 
			
		||||
            self.assertEqual(json["subscribed"], subscribed)
 | 
			
		||||
 | 
			
		||||
    def test_successful_subscriptions_exists_subbed(self) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Calling /json/subscriptions/exist on a stream to which you are subbed
 | 
			
		||||
        should return that it exists and that you are subbed.
 | 
			
		||||
        """
 | 
			
		||||
        self.assertNotEqual(len(self.streams), 0)  # necessary for full test coverage
 | 
			
		||||
        self.helper_subscriptions_exists(self.streams[0], True, True)
 | 
			
		||||
 | 
			
		||||
    def test_successful_subscriptions_exists_not_subbed(self) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Calling /json/subscriptions/exist on a stream to which you are not
 | 
			
		||||
        subbed should return that it exists and that you are not subbed.
 | 
			
		||||
        """
 | 
			
		||||
        all_stream_names = [stream.name for stream in Stream.objects.filter(realm=self.test_realm)]
 | 
			
		||||
        streams_not_subbed = list(set(all_stream_names) - set(self.streams))
 | 
			
		||||
        self.assertNotEqual(len(streams_not_subbed), 0)  # necessary for full test coverage
 | 
			
		||||
        self.helper_subscriptions_exists(streams_not_subbed[0], True, False)
 | 
			
		||||
 | 
			
		||||
    def test_subscriptions_does_not_exist(self) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Calling /json/subscriptions/exist on a stream that doesn't exist should
 | 
			
		||||
        return that it doesn't exist.
 | 
			
		||||
        """
 | 
			
		||||
        random_streams = self.make_random_stream_names(self.streams)
 | 
			
		||||
        self.assertNotEqual(len(random_streams), 0)  # necessary for full test coverage
 | 
			
		||||
        self.helper_subscriptions_exists(random_streams[0], False, False)
 | 
			
		||||
 | 
			
		||||
    def test_subscriptions_exist_invalid_name(self) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Calling /json/subscriptions/exist on a stream whose name is invalid (as
 | 
			
		||||
        defined by valid_stream_name in zerver/views.py) should return a JSON
 | 
			
		||||
        error.
 | 
			
		||||
        """
 | 
			
		||||
        # currently, the only invalid stream name is the empty string
 | 
			
		||||
        invalid_stream_name = ""
 | 
			
		||||
        result = self.client_post("/json/subscriptions/exists", {"stream": invalid_stream_name})
 | 
			
		||||
        self.assert_json_error(result, "Stream name can't be empty!")
 | 
			
		||||
 | 
			
		||||
    def test_existing_subscriptions_autosubscription(self) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Call /json/subscriptions/exist on an existing stream and autosubscribe to it.
 | 
			
		||||
        """
 | 
			
		||||
        stream_name = "new_public_stream"
 | 
			
		||||
        cordelia = self.example_user("cordelia")
 | 
			
		||||
        self.common_subscribe_to_streams(cordelia, [stream_name], invite_only=False)
 | 
			
		||||
        result = self.client_post(
 | 
			
		||||
            "/json/subscriptions/exists", {"stream": stream_name, "autosubscribe": "false"}
 | 
			
		||||
        )
 | 
			
		||||
        response_dict = self.assert_json_success(result)
 | 
			
		||||
        self.assertIn("subscribed", response_dict)
 | 
			
		||||
        self.assertFalse(response_dict["subscribed"])
 | 
			
		||||
 | 
			
		||||
        result = self.client_post(
 | 
			
		||||
            "/json/subscriptions/exists", {"stream": stream_name, "autosubscribe": "true"}
 | 
			
		||||
        )
 | 
			
		||||
        response_dict = self.assert_json_success(result)
 | 
			
		||||
        self.assertIn("subscribed", response_dict)
 | 
			
		||||
        self.assertTrue(response_dict)
 | 
			
		||||
 | 
			
		||||
    def test_existing_subscriptions_autosubscription_private_stream(self) -> None:
 | 
			
		||||
        """Call /json/subscriptions/exist on an existing private stream with
 | 
			
		||||
        autosubscribe should fail.
 | 
			
		||||
        """
 | 
			
		||||
        stream_name = "Saxony"
 | 
			
		||||
        cordelia = self.example_user("cordelia")
 | 
			
		||||
        self.common_subscribe_to_streams(cordelia, [stream_name], invite_only=True)
 | 
			
		||||
        stream = get_stream(stream_name, self.test_realm)
 | 
			
		||||
 | 
			
		||||
        result = self.client_post(
 | 
			
		||||
            "/json/subscriptions/exists", {"stream": stream_name, "autosubscribe": "true"}
 | 
			
		||||
        )
 | 
			
		||||
        # We can't see invite-only streams here
 | 
			
		||||
        self.assert_json_error(result, "Invalid stream name 'Saxony'", status_code=404)
 | 
			
		||||
        # Importantly, we are not now subscribed
 | 
			
		||||
        self.assertEqual(num_subscribers_for_stream_id(stream.id), 1)
 | 
			
		||||
 | 
			
		||||
        # A user who is subscribed still sees the stream exists
 | 
			
		||||
        self.login("cordelia")
 | 
			
		||||
        result = self.client_post(
 | 
			
		||||
            "/json/subscriptions/exists", {"stream": stream_name, "autosubscribe": "false"}
 | 
			
		||||
        )
 | 
			
		||||
        response_dict = self.assert_json_success(result)
 | 
			
		||||
        self.assertIn("subscribed", response_dict)
 | 
			
		||||
        self.assertTrue(response_dict)
 | 
			
		||||
 | 
			
		||||
    def get_subscription(self, user_profile: UserProfile, stream_name: str) -> Subscription:
 | 
			
		||||
        stream = get_stream(stream_name, self.test_realm)
 | 
			
		||||
        return Subscription.objects.get(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user