mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Merge pull request #279 from matrix-org/erikj/unfederatable
Add flag which disables federation of the room
This commit is contained in:
commit
a38d36ccd0
@ -20,7 +20,7 @@ from twisted.internet import defer
|
|||||||
from synapse.api.constants import EventTypes, Membership, JoinRules
|
from synapse.api.constants import EventTypes, Membership, JoinRules
|
||||||
from synapse.api.errors import AuthError, Codes, SynapseError
|
from synapse.api.errors import AuthError, Codes, SynapseError
|
||||||
from synapse.util.logutils import log_function
|
from synapse.util.logutils import log_function
|
||||||
from synapse.types import UserID, EventID
|
from synapse.types import RoomID, UserID, EventID
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import pymacaroons
|
import pymacaroons
|
||||||
@ -80,6 +80,15 @@ class Auth(object):
|
|||||||
"Room %r does not exist" % (event.room_id,)
|
"Room %r does not exist" % (event.room_id,)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
creating_domain = RoomID.from_string(event.room_id).domain
|
||||||
|
originating_domain = UserID.from_string(event.sender).domain
|
||||||
|
if creating_domain != originating_domain:
|
||||||
|
if not self.can_federate(event, auth_events):
|
||||||
|
raise AuthError(
|
||||||
|
403,
|
||||||
|
"This room has been marked as unfederatable."
|
||||||
|
)
|
||||||
|
|
||||||
# FIXME: Temp hack
|
# FIXME: Temp hack
|
||||||
if event.type == EventTypes.Aliases:
|
if event.type == EventTypes.Aliases:
|
||||||
return True
|
return True
|
||||||
@ -219,6 +228,11 @@ class Auth(object):
|
|||||||
user_id, room_id, repr(member)
|
user_id, room_id, repr(member)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def can_federate(self, event, auth_events):
|
||||||
|
creation_event = auth_events.get((EventTypes.Create, ""))
|
||||||
|
|
||||||
|
return creation_event.content.get("m.federate", True) is True
|
||||||
|
|
||||||
@log_function
|
@log_function
|
||||||
def is_membership_change_allowed(self, event, auth_events):
|
def is_membership_change_allowed(self, event, auth_events):
|
||||||
membership = event.content["membership"]
|
membership = event.content["membership"]
|
||||||
@ -234,6 +248,15 @@ class Auth(object):
|
|||||||
|
|
||||||
target_user_id = event.state_key
|
target_user_id = event.state_key
|
||||||
|
|
||||||
|
creating_domain = RoomID.from_string(event.room_id).domain
|
||||||
|
target_domain = UserID.from_string(target_user_id).domain
|
||||||
|
if creating_domain != target_domain:
|
||||||
|
if not self.can_federate(event, auth_events):
|
||||||
|
raise AuthError(
|
||||||
|
403,
|
||||||
|
"This room has been marked as unfederatable."
|
||||||
|
)
|
||||||
|
|
||||||
# get info about the caller
|
# get info about the caller
|
||||||
key = (EventTypes.Member, event.user_id, )
|
key = (EventTypes.Member, event.user_id, )
|
||||||
caller = auth_events.get(key)
|
caller = auth_events.get(key)
|
||||||
|
@ -149,12 +149,15 @@ class RoomCreationHandler(BaseHandler):
|
|||||||
for val in raw_initial_state:
|
for val in raw_initial_state:
|
||||||
initial_state[(val["type"], val.get("state_key", ""))] = val["content"]
|
initial_state[(val["type"], val.get("state_key", ""))] = val["content"]
|
||||||
|
|
||||||
|
creation_content = config.get("creation_content", {})
|
||||||
|
|
||||||
user = UserID.from_string(user_id)
|
user = UserID.from_string(user_id)
|
||||||
creation_events = self._create_events_for_new_room(
|
creation_events = self._create_events_for_new_room(
|
||||||
user, room_id,
|
user, room_id,
|
||||||
preset_config=preset_config,
|
preset_config=preset_config,
|
||||||
invite_list=invite_list,
|
invite_list=invite_list,
|
||||||
initial_state=initial_state,
|
initial_state=initial_state,
|
||||||
|
creation_content=creation_content,
|
||||||
room_alias=room_alias,
|
room_alias=room_alias,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -203,7 +206,8 @@ class RoomCreationHandler(BaseHandler):
|
|||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
|
|
||||||
def _create_events_for_new_room(self, creator, room_id, preset_config,
|
def _create_events_for_new_room(self, creator, room_id, preset_config,
|
||||||
invite_list, initial_state, room_alias):
|
invite_list, initial_state, creation_content,
|
||||||
|
room_alias):
|
||||||
config = RoomCreationHandler.PRESETS_DICT[preset_config]
|
config = RoomCreationHandler.PRESETS_DICT[preset_config]
|
||||||
|
|
||||||
creator_id = creator.to_string()
|
creator_id = creator.to_string()
|
||||||
@ -225,9 +229,10 @@ class RoomCreationHandler(BaseHandler):
|
|||||||
|
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
creation_content.update({"creator": creator.to_string()})
|
||||||
creation_event = create(
|
creation_event = create(
|
||||||
etype=EventTypes.Create,
|
etype=EventTypes.Create,
|
||||||
content={"creator": creator.to_string()},
|
content=creation_content,
|
||||||
)
|
)
|
||||||
|
|
||||||
join_event = create(
|
join_event = create(
|
||||||
|
@ -35,7 +35,7 @@ def create_event(name=None, type=None, state_key=None, depth=2, event_id=None,
|
|||||||
|
|
||||||
if not event_id:
|
if not event_id:
|
||||||
_next_event_id += 1
|
_next_event_id += 1
|
||||||
event_id = str(_next_event_id)
|
event_id = "$%s:test" % (_next_event_id,)
|
||||||
|
|
||||||
if not name:
|
if not name:
|
||||||
if state_key is not None:
|
if state_key is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user