mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	Remove "all" option for flag-updating endpoint.
The "all" option for 'message/flags' was dangerous, as it could apply to any of our flags. The only flag it made sense for, the "read" flag, now has a dedicated endpoint.
This commit is contained in:
		@@ -2600,14 +2600,11 @@ def do_mark_all_as_read(user_profile):
 | 
			
		||||
    statsd.incr("mark_all_as_read", count)
 | 
			
		||||
    return count
 | 
			
		||||
 | 
			
		||||
def do_update_message_flags(user_profile, operation, flag, messages, all, stream_obj, topic_name):
 | 
			
		||||
    # type: (UserProfile, Text, Text, Optional[Sequence[int]], bool, Optional[Stream], Optional[Text]) -> int
 | 
			
		||||
def do_update_message_flags(user_profile, operation, flag, messages, stream_obj, topic_name):
 | 
			
		||||
    # type: (UserProfile, Text, Text, Optional[Sequence[int]], Optional[Stream], Optional[Text]) -> int
 | 
			
		||||
    flagattr = getattr(UserMessage.flags, flag)
 | 
			
		||||
 | 
			
		||||
    if all:
 | 
			
		||||
        log_statsd_event('bankruptcy')
 | 
			
		||||
        msgs = UserMessage.objects.filter(user_profile=user_profile)
 | 
			
		||||
    elif stream_obj is not None:
 | 
			
		||||
    if stream_obj is not None:
 | 
			
		||||
        recipient = get_recipient(Recipient.STREAM, stream_obj.id)
 | 
			
		||||
        if topic_name:
 | 
			
		||||
            msgs = UserMessage.objects.filter(message__recipient=recipient,
 | 
			
		||||
@@ -2656,7 +2653,7 @@ def do_update_message_flags(user_profile, operation, flag, messages, all, stream
 | 
			
		||||
             'operation': operation,
 | 
			
		||||
             'flag': flag,
 | 
			
		||||
             'messages': messages,
 | 
			
		||||
             'all': all}
 | 
			
		||||
             'all': False}
 | 
			
		||||
    send_event(event, [user_profile.id])
 | 
			
		||||
 | 
			
		||||
    statsd.incr("flags.%s.%s" % (flag, operation), count)
 | 
			
		||||
 
 | 
			
		||||
@@ -588,7 +588,7 @@ class EventsRegisterTest(ZulipTestCase):
 | 
			
		||||
        user_profile = self.example_user('hamlet')
 | 
			
		||||
        events = self.do_test(
 | 
			
		||||
            lambda: do_update_message_flags(user_profile, 'add', 'starred',
 | 
			
		||||
                                            [message], False, None, None),
 | 
			
		||||
                                            [message], None, None),
 | 
			
		||||
            state_change_expected=False,
 | 
			
		||||
        )
 | 
			
		||||
        error = schema_checker('events[0]', events[0])
 | 
			
		||||
@@ -602,7 +602,7 @@ class EventsRegisterTest(ZulipTestCase):
 | 
			
		||||
        ])
 | 
			
		||||
        events = self.do_test(
 | 
			
		||||
            lambda: do_update_message_flags(user_profile, 'remove', 'starred',
 | 
			
		||||
                                            [message], False, None, None),
 | 
			
		||||
                                            [message], None, None),
 | 
			
		||||
            state_change_expected=False,
 | 
			
		||||
        )
 | 
			
		||||
        error = schema_checker('events[0]', events[0])
 | 
			
		||||
@@ -624,7 +624,7 @@ class EventsRegisterTest(ZulipTestCase):
 | 
			
		||||
 | 
			
		||||
            self.do_test(
 | 
			
		||||
                lambda: do_update_message_flags(user_profile, 'add', 'read',
 | 
			
		||||
                                                [message], False, None, None),
 | 
			
		||||
                                                [message], None, None),
 | 
			
		||||
                state_change_expected=True,
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -793,14 +793,10 @@ def get_messages_backend(request, user_profile,
 | 
			
		||||
def update_message_flags(request, user_profile,
 | 
			
		||||
                         messages=REQ(validator=check_list(check_int)),
 | 
			
		||||
                         operation=REQ('op'), flag=REQ(),
 | 
			
		||||
                         all=REQ(validator=check_bool, default=False),
 | 
			
		||||
                         stream_name=REQ(default=None),
 | 
			
		||||
                         topic_name=REQ(default=None)):
 | 
			
		||||
    # type: (HttpRequest, UserProfile, List[int], Text, Text, bool, Optional[Text], Optional[Text]) -> HttpResponse
 | 
			
		||||
    if all:
 | 
			
		||||
        target_count_str = "all"
 | 
			
		||||
    else:
 | 
			
		||||
        target_count_str = str(len(messages))
 | 
			
		||||
    # type: (HttpRequest, UserProfile, List[int], Text, Text, Optional[Text], Optional[Text]) -> HttpResponse
 | 
			
		||||
    target_count_str = str(len(messages))
 | 
			
		||||
    log_data_str = "[%s %s/%s]" % (operation, flag, target_count_str)
 | 
			
		||||
    request._log_data["extra"] = log_data_str
 | 
			
		||||
    stream = None
 | 
			
		||||
@@ -817,7 +813,7 @@ def update_message_flags(request, user_profile,
 | 
			
		||||
            if not topic_exists:
 | 
			
		||||
                raise JsonableError(_('No such topic \'%s\'') % (topic_name,))
 | 
			
		||||
    count = do_update_message_flags(user_profile, operation, flag, messages,
 | 
			
		||||
                                    all, stream, topic_name)
 | 
			
		||||
                                    stream, topic_name)
 | 
			
		||||
 | 
			
		||||
    # If we succeed, update log data str with the actual count for how
 | 
			
		||||
    # many messages were updated.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user