diff --git a/zerver/tests/test_presence.py b/zerver/tests/test_presence.py index 7864622628..29f8128439 100644 --- a/zerver/tests/test_presence.py +++ b/zerver/tests/test_presence.py @@ -264,6 +264,12 @@ class SingleUserPresenceTests(ZulipTestCase): result = self.client_post("/json/users/me/presence", req) self.assertEqual(result.json()['msg'], '') + def test_bot_post(self): + # type: () -> None + result = self.client_post("/api/v1/users/me/presence", {'status': 'active'}, + **self.api_auth('default-bot@zulip.com')) + self.assert_json_error(result, "Presence is not supported for bot users.") + class UserPresenceAggregationTests(ZulipTestCase): def _send_presence_for_aggregated_tests(self, email, status, validate_time): # type: (str, str, datetime.datetime) -> Dict[str, Dict[str, Any]] diff --git a/zerver/views/presence.py b/zerver/views/presence.py index a3a6efd3bc..c006ddd6ba 100644 --- a/zerver/views/presence.py +++ b/zerver/views/presence.py @@ -57,6 +57,9 @@ def update_active_status_backend(request, user_profile, status=REQ(), ping_only=REQ(validator=check_bool, default=False), new_user_input=REQ(validator=check_bool, default=False)): # type: (HttpRequest, UserProfile, str, bool, bool) -> HttpResponse + if user_profile.is_bot: + return json_error(_('Presence is not supported for bot users.')) + status_val = UserPresence.status_from_string(status) if status_val is None: raise JsonableError(_("Invalid status: %s") % (status,))