mirror of https://github.com/zulip/zulip.git
presence: Allow bots to fetch realm presence data.
Before, presence information for an entire realm could only be queried via the `POST /api/v1/users/me/presence` endpoint. However, this endpoint also updates the presence information for the user making the request. Therefore, bot users are not allowed to access this endpoint because they don't have any presence data. This commit adds a new endpoint `GET /api/v1/realm/presence` that just returns the presence information for the realm of the caller. Fixes #10651.
This commit is contained in:
parent
7f075e0da2
commit
b2c29274f3
|
@ -485,3 +485,21 @@ class UserPresenceAggregationTests(ZulipTestCase):
|
|||
"timestamp": datetime_to_timestamp(validate_time - datetime.timedelta(seconds=2))
|
||||
}
|
||||
)
|
||||
|
||||
class GetRealmStatusesTest(ZulipTestCase):
|
||||
def test_get_statuses(self) -> None:
|
||||
# Setup the test by simulating users reporting their presence data.
|
||||
othello_email = self.example_email("othello")
|
||||
result = self.api_post(othello_email, "/api/v1/users/me/presence", {'status': 'active'},
|
||||
HTTP_USER_AGENT="ZulipAndroid/1.0")
|
||||
|
||||
hamlet_email = self.example_email("hamlet")
|
||||
result = self.api_post(hamlet_email, "/api/v1/users/me/presence", {'status': 'idle'},
|
||||
HTTP_USER_AGENT="ZulipDesktop/1.0")
|
||||
self.assert_json_success(result)
|
||||
|
||||
# Check that a bot can fetch the presence data for the realm.
|
||||
result = self.api_get(self.example_email("welcome_bot"), "/api/v1/realm/presence")
|
||||
self.assert_json_success(result)
|
||||
json = result.json()
|
||||
self.assertEqual(sorted(json['presences'].keys()), [hamlet_email, othello_email])
|
||||
|
|
|
@ -79,3 +79,6 @@ def update_active_status_backend(request: HttpRequest, user_profile: UserProfile
|
|||
ret['zephyr_mirror_active'] = False
|
||||
|
||||
return json_success(ret)
|
||||
|
||||
def get_statuses_for_realm(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||
return json_success(get_status_list(user_profile))
|
||||
|
|
|
@ -116,6 +116,9 @@ v1_api_and_json_patterns = [
|
|||
url(r'^realm/deactivate$', rest_dispatch,
|
||||
{'POST': 'zerver.views.realm.deactivate_realm'}),
|
||||
|
||||
url(r'^realm/presence$', rest_dispatch,
|
||||
{'GET': 'zerver.views.presence.get_statuses_for_realm'}),
|
||||
|
||||
# users -> zerver.views.users
|
||||
#
|
||||
# Since some of these endpoints do something different if used on
|
||||
|
|
Loading…
Reference in New Issue