mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-01-21 03:01:07 -05:00
Allow users to GET individual state events for rooms that they have left
This commit is contained in:
parent
09cb5c7d33
commit
e2054ce21a
@ -16,7 +16,7 @@
|
|||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes, Membership
|
from synapse.api.constants import EventTypes, Membership
|
||||||
from synapse.api.errors import RoomError, SynapseError
|
from synapse.api.errors import SynapseError
|
||||||
from synapse.streams.config import PaginationConfig
|
from synapse.streams.config import PaginationConfig
|
||||||
from synapse.events.utils import serialize_event
|
from synapse.events.utils import serialize_event
|
||||||
from synapse.events.validator import EventValidator
|
from synapse.events.validator import EventValidator
|
||||||
@ -277,13 +277,19 @@ class MessageHandler(BaseHandler):
|
|||||||
Raises:
|
Raises:
|
||||||
SynapseError if something went wrong.
|
SynapseError if something went wrong.
|
||||||
"""
|
"""
|
||||||
have_joined = yield self.auth.check_joined_room(room_id, user_id)
|
member_event = yield self.auth.check_user_was_in_room(room_id, user_id)
|
||||||
if not have_joined:
|
|
||||||
raise RoomError(403, "User not in room.")
|
if member_event.membership == Membership.JOIN:
|
||||||
|
data = yield self.state_handler.get_current_state(
|
||||||
|
room_id, event_type, state_key
|
||||||
|
)
|
||||||
|
elif member_event.membership == Membership.LEAVE:
|
||||||
|
key = (event_type, state_key)
|
||||||
|
room_state = yield self.store.get_state_for_events(
|
||||||
|
room_id, [member_event.event_id], [key]
|
||||||
|
)
|
||||||
|
data = room_state[member_event.event_id].get(key)
|
||||||
|
|
||||||
data = yield self.state_handler.get_current_state(
|
|
||||||
room_id, event_type, state_key
|
|
||||||
)
|
|
||||||
defer.returnValue(data)
|
defer.returnValue(data)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -239,7 +239,7 @@ class RoomPermissionsTestCase(RestTestCase):
|
|||||||
"PUT", topic_path, topic_content)
|
"PUT", topic_path, topic_content)
|
||||||
self.assertEquals(403, code, msg=str(response))
|
self.assertEquals(403, code, msg=str(response))
|
||||||
(code, response) = yield self.mock_resource.trigger_get(topic_path)
|
(code, response) = yield self.mock_resource.trigger_get(topic_path)
|
||||||
self.assertEquals(403, code, msg=str(response))
|
self.assertEquals(200, code, msg=str(response))
|
||||||
|
|
||||||
# get topic in PUBLIC room, not joined, expect 403
|
# get topic in PUBLIC room, not joined, expect 403
|
||||||
(code, response) = yield self.mock_resource.trigger_get(
|
(code, response) = yield self.mock_resource.trigger_get(
|
||||||
@ -301,11 +301,11 @@ class RoomPermissionsTestCase(RestTestCase):
|
|||||||
room=room, expect_code=200)
|
room=room, expect_code=200)
|
||||||
|
|
||||||
# get membership of self, get membership of other, private room + left
|
# get membership of self, get membership of other, private room + left
|
||||||
# expect all 403s
|
# expect all 200s
|
||||||
yield self.leave(room=room, user=self.user_id)
|
yield self.leave(room=room, user=self.user_id)
|
||||||
yield self._test_get_membership(
|
yield self._test_get_membership(
|
||||||
members=[self.user_id, self.rmcreator_id],
|
members=[self.user_id, self.rmcreator_id],
|
||||||
room=room, expect_code=403)
|
room=room, expect_code=200)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_membership_public_room_perms(self):
|
def test_membership_public_room_perms(self):
|
||||||
@ -326,11 +326,11 @@ class RoomPermissionsTestCase(RestTestCase):
|
|||||||
room=room, expect_code=200)
|
room=room, expect_code=200)
|
||||||
|
|
||||||
# get membership of self, get membership of other, public room + left
|
# get membership of self, get membership of other, public room + left
|
||||||
# expect 403.
|
# expect 200.
|
||||||
yield self.leave(room=room, user=self.user_id)
|
yield self.leave(room=room, user=self.user_id)
|
||||||
yield self._test_get_membership(
|
yield self._test_get_membership(
|
||||||
members=[self.user_id, self.rmcreator_id],
|
members=[self.user_id, self.rmcreator_id],
|
||||||
room=room, expect_code=403)
|
room=room, expect_code=200)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_invited_permissions(self):
|
def test_invited_permissions(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user