presence.py: Enforce bots cannot use update_active_status_backend.

We need to keep the UserActivity table clean now that we're using it to
compute 15day actives in analytics.
This commit is contained in:
Rishi Gupta 2017-04-11 20:37:56 -07:00 committed by Tim Abbott
parent f62b8ea080
commit bbddbdeb25
2 changed files with 9 additions and 0 deletions

View File

@ -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]]

View File

@ -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,))