Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' of github.com:matrix-org/synapse into erikj/ig…
Browse files Browse the repository at this point in the history
…nore_user
  • Loading branch information
erikjohnston committed May 9, 2016
2 parents def64d6 + 3f84da1 commit c9eb6df
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
16 changes: 8 additions & 8 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from synapse.api.constants import EventTypes, Membership, JoinRules
from synapse.api.errors import AuthError, Codes, SynapseError, EventSizeError
from synapse.types import Requester, RoomID, UserID, EventID
from synapse.types import Requester, UserID, get_domian_from_id
from synapse.util.logutils import log_function
from synapse.util.logcontext import preserve_context_over_fn
from synapse.util.metrics import Measure
Expand Down Expand Up @@ -91,8 +91,8 @@ def check(self, event, auth_events):
"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
creating_domain = get_domian_from_id(event.room_id)
originating_domain = get_domian_from_id(event.sender)
if creating_domain != originating_domain:
if not self.can_federate(event, auth_events):
raise AuthError(
Expand Down Expand Up @@ -219,7 +219,7 @@ def check_host_in_room(self, room_id, host):
for event in curr_state.values():
if event.type == EventTypes.Member:
try:
if UserID.from_string(event.state_key).domain != host:
if get_domian_from_id(event.state_key) != host:
continue
except:
logger.warn("state_key not user_id: %s", event.state_key)
Expand Down Expand Up @@ -266,8 +266,8 @@ def is_membership_change_allowed(self, event, auth_events):

target_user_id = event.state_key

creating_domain = RoomID.from_string(event.room_id).domain
target_domain = UserID.from_string(target_user_id).domain
creating_domain = get_domian_from_id(event.room_id)
target_domain = get_domian_from_id(target_user_id)
if creating_domain != target_domain:
if not self.can_federate(event, auth_events):
raise AuthError(
Expand Down Expand Up @@ -889,8 +889,8 @@ def check_redaction(self, event, auth_events):
if user_level >= redact_level:
return False

redacter_domain = EventID.from_string(event.event_id).domain
redactee_domain = EventID.from_string(event.redacts).domain
redacter_domain = get_domian_from_id(event.event_id)
redactee_domain = get_domian_from_id(event.redacts)
if redacter_domain == redactee_domain:
return True

Expand Down
8 changes: 3 additions & 5 deletions synapse/handlers/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from synapse.api.errors import LimitExceededError, SynapseError, AuthError
from synapse.crypto.event_signing import add_hashes_and_signatures
from synapse.api.constants import Membership, EventTypes
from synapse.types import UserID, RoomAlias, Requester
from synapse.types import UserID, RoomAlias, Requester, get_domian_from_id
from synapse.push.action_generator import ActionGenerator

from synapse.util.logcontext import PreserveLoggingContext, preserve_fn
Expand Down Expand Up @@ -312,7 +312,7 @@ def is_host_in_room(self, current_state):
return True
for (state_key, membership) in room_members:
if (
UserID.from_string(state_key).domain == self.hs.hostname
self.hs.is_mine_id(state_key)
and membership == Membership.JOIN
):
return True
Expand Down Expand Up @@ -437,9 +437,7 @@ def is_inviter_member_event(e):
try:
if k[0] == EventTypes.Member:
if s.content["membership"] == Membership.JOIN:
destinations.add(
UserID.from_string(s.state_key).domain
)
destinations.add(get_domian_from_id(s.state_key))
except SynapseError:
logger.warn(
"Failed to get destination from event %s", s.event_id
Expand Down
12 changes: 4 additions & 8 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from synapse.crypto.event_signing import (
compute_event_signature, add_hashes_and_signatures,
)
from synapse.types import UserID
from synapse.types import UserID, get_domian_from_id

from synapse.events.utils import prune_event

Expand Down Expand Up @@ -453,7 +453,7 @@ def get_domains_from_state(state):
joined_domains = {}
for u, d in joined_users:
try:
dom = UserID.from_string(u).domain
dom = get_domian_from_id(u)
old_d = joined_domains.get(dom)
if old_d:
joined_domains[dom] = min(d, old_d)
Expand Down Expand Up @@ -743,9 +743,7 @@ def on_send_join_request(self, origin, pdu):
try:
if k[0] == EventTypes.Member:
if s.content["membership"] == Membership.JOIN:
destinations.add(
UserID.from_string(s.state_key).domain
)
destinations.add(get_domian_from_id(s.state_key))
except:
logger.warn(
"Failed to get destination from event %s", s.event_id
Expand Down Expand Up @@ -970,9 +968,7 @@ def on_send_leave_request(self, origin, pdu):
try:
if k[0] == EventTypes.Member:
if s.content["membership"] == Membership.LEAVE:
destinations.add(
UserID.from_string(s.state_key).domain
)
destinations.add(get_domian_from_id(s.state_key))
except:
logger.warn(
"Failed to get destination from event %s", s.event_id
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from synapse.util.logutils import log_function
from synapse.util.metrics import Measure
from synapse.util.wheel_timer import WheelTimer
from synapse.types import UserID
from synapse.types import UserID, get_domian_from_id
import synapse.metrics

from ._base import BaseHandler
Expand Down Expand Up @@ -440,7 +440,7 @@ def _get_interested_parties(self, states):
if not local_states:
continue

host = UserID.from_string(user_id).domain
host = get_domian_from_id(user_id)
hosts_to_states.setdefault(host, []).extend(local_states)

# TODO: de-dup hosts_to_states, as a single host might have multiple
Expand Down
7 changes: 2 additions & 5 deletions synapse/storage/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from synapse.util.caches.descriptors import cached, cachedInlineCallbacks

from synapse.api.constants import Membership
from synapse.types import UserID
from synapse.types import get_domian_from_id

import logging

Expand Down Expand Up @@ -273,10 +273,7 @@ def _get_joined_hosts_for_room_txn(self, txn, room_id):
room_id, membership=Membership.JOIN
)

joined_domains = set(
UserID.from_string(r["user_id"]).domain
for r in rows
)
joined_domains = set(get_domian_from_id(r["user_id"]) for r in rows)

return joined_domains

Expand Down
4 changes: 4 additions & 0 deletions synapse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
Requester = namedtuple("Requester", ["user", "access_token_id", "is_guest"])


def get_domian_from_id(string):
return string.split(":", 1)[1]


class DomainSpecificString(
namedtuple("DomainSpecificString", ("localpart", "domain"))
):
Expand Down

0 comments on commit c9eb6df

Please sign in to comment.