Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
actions: Invalid flag operation is a user error.
Alex Vandiver81893c9dbb4e
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex f02c6d3636d..e57db1c51b6 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -4240,6 +4240,8 @@ def do_update_message_flags(user_profile: UserProfile,raise JsonableError(_("Invalid flag: '{}'").format(flag))if flag in UserMessage.NON_EDITABLE_FLAGS:raise JsonableError(_("Flag not editable: '{}'").format(flag))+ if operation not in ('add', 'remove'):+ raise JsonableError(_("Invalid message flag operation: '{}'").format(operation))flagattr = getattr(UserMessage.flags, flag)msgs = UserMessage.objects.filter(user_profile=user_profile,@@ -4272,8 +4274,6 @@ def do_update_message_flags(user_profile: UserProfile,count = msgs.update(flags=F('flags').bitor(flagattr))elif operation == 'remove':count = msgs.update(flags=F('flags').bitand(~flagattr))- else:- raise AssertionError("Invalid message flags operation")event = {'type': 'update_message_flags','op': operation,diff --git a/zerver/tests/test_message_flags.py b/zerver/tests/test_message_flags.pyindex c22b11a7823..085a41a1a67 100644--- a/zerver/tests/test_message_flags.py+++ b/zerver/tests/test_message_flags.py@@ -923,6 +923,12 @@ class MessageAccessTests(ZulipTestCase):"flag": "mentioned"})self.assert_json_error(result, "Flag not editable: 'mentioned'")+ result = self.client_post("/json/messages/flags",+ {"messages": orjson.dumps([message]).decode(),+ "op": "bogus",+ "flag": "starred"})+ self.assert_json_error(result, "Invalid message flag operation: 'bogus'")+def change_star(self, messages: List[int], add: bool=True, **kwargs: Any) -> HttpResponse:return self.client_post("/json/messages/flags",{"messages": orjson.dumps(messages).decode(),