|
19 | 19 |
|
20 | 20 | from twisted.web.server import Request
|
21 | 21 |
|
22 |
| -from synapse import event_auth |
23 | 22 | from synapse.api.auth_blocking import AuthBlocking
|
24 |
| -from synapse.api.constants import EventTypes, HistoryVisibility, Membership |
| 23 | +from synapse.api.constants import EventTypes |
25 | 24 | from synapse.api.errors import (
|
26 | 25 | AuthError,
|
27 | 26 | Codes,
|
28 | 27 | InvalidClientTokenError,
|
29 | 28 | MissingClientTokenError,
|
30 | 29 | )
|
31 | 30 | from synapse.appservice import ApplicationService
|
32 |
| -from synapse.events import EventBase |
33 | 31 | from synapse.http import get_request_user_agent
|
34 | 32 | from synapse.http.site import SynapseRequest
|
35 | 33 | from synapse.logging import opentracing as opentracing
|
36 | 34 | from synapse.storage.databases.main.registration import TokenLookupResult
|
37 |
| -from synapse.types import Requester, StateMap, UserID, create_requester |
| 35 | +from synapse.types import Requester, UserID, create_requester |
38 | 36 | from synapse.util.caches.lrucache import LruCache
|
39 | 37 | from synapse.util.macaroons import get_value_from_macaroon, satisfy_expiry
|
40 | 38 |
|
@@ -87,56 +85,6 @@ def __init__(self, hs: "HomeServer"):
|
87 | 85 | self._macaroon_secret_key = hs.config.macaroon_secret_key
|
88 | 86 | self._force_tracing_for_users = hs.config.tracing.force_tracing_for_users
|
89 | 87 |
|
90 |
| - async def check_user_in_room( |
91 |
| - self, |
92 |
| - room_id: str, |
93 |
| - user_id: str, |
94 |
| - current_state: Optional[StateMap[EventBase]] = None, |
95 |
| - allow_departed_users: bool = False, |
96 |
| - ) -> EventBase: |
97 |
| - """Check if the user is in the room, or was at some point. |
98 |
| - Args: |
99 |
| - room_id: The room to check. |
100 |
| -
|
101 |
| - user_id: The user to check. |
102 |
| -
|
103 |
| - current_state: Optional map of the current state of the room. |
104 |
| - If provided then that map is used to check whether they are a |
105 |
| - member of the room. Otherwise the current membership is |
106 |
| - loaded from the database. |
107 |
| -
|
108 |
| - allow_departed_users: if True, accept users that were previously |
109 |
| - members but have now departed. |
110 |
| -
|
111 |
| - Raises: |
112 |
| - AuthError if the user is/was not in the room. |
113 |
| - Returns: |
114 |
| - Membership event for the user if the user was in the |
115 |
| - room. This will be the join event if they are currently joined to |
116 |
| - the room. This will be the leave event if they have left the room. |
117 |
| - """ |
118 |
| - if current_state: |
119 |
| - member = current_state.get((EventTypes.Member, user_id), None) |
120 |
| - else: |
121 |
| - member = await self.state.get_current_state( |
122 |
| - room_id=room_id, event_type=EventTypes.Member, state_key=user_id |
123 |
| - ) |
124 |
| - |
125 |
| - if member: |
126 |
| - membership = member.membership |
127 |
| - |
128 |
| - if membership == Membership.JOIN: |
129 |
| - return member |
130 |
| - |
131 |
| - # XXX this looks totally bogus. Why do we not allow users who have been banned, |
132 |
| - # or those who were members previously and have been re-invited? |
133 |
| - if allow_departed_users and membership == Membership.LEAVE: |
134 |
| - forgot = await self.store.did_forget(user_id, room_id) |
135 |
| - if not forgot: |
136 |
| - return member |
137 |
| - |
138 |
| - raise AuthError(403, "User %s not in room %s" % (user_id, room_id)) |
139 |
| - |
140 | 88 | async def get_user_by_req(
|
141 | 89 | self,
|
142 | 90 | request: SynapseRequest,
|
@@ -467,40 +415,6 @@ async def is_server_admin(self, user: UserID) -> bool:
|
467 | 415 | """
|
468 | 416 | return await self.store.is_server_admin(user)
|
469 | 417 |
|
470 |
| - async def check_can_change_room_list(self, room_id: str, user: UserID) -> bool: |
471 |
| - """Determine whether the user is allowed to edit the room's entry in the |
472 |
| - published room list. |
473 |
| -
|
474 |
| - Args: |
475 |
| - room_id |
476 |
| - user |
477 |
| - """ |
478 |
| - |
479 |
| - is_admin = await self.is_server_admin(user) |
480 |
| - if is_admin: |
481 |
| - return True |
482 |
| - |
483 |
| - user_id = user.to_string() |
484 |
| - await self.check_user_in_room(room_id, user_id) |
485 |
| - |
486 |
| - # We currently require the user is a "moderator" in the room. We do this |
487 |
| - # by checking if they would (theoretically) be able to change the |
488 |
| - # m.room.canonical_alias events |
489 |
| - power_level_event = await self.state.get_current_state( |
490 |
| - room_id, EventTypes.PowerLevels, "" |
491 |
| - ) |
492 |
| - |
493 |
| - auth_events = {} |
494 |
| - if power_level_event: |
495 |
| - auth_events[(EventTypes.PowerLevels, "")] = power_level_event |
496 |
| - |
497 |
| - send_level = event_auth.get_send_level( |
498 |
| - EventTypes.CanonicalAlias, "", power_level_event |
499 |
| - ) |
500 |
| - user_level = event_auth.get_user_power_level(user_id, auth_events) |
501 |
| - |
502 |
| - return user_level >= send_level |
503 |
| - |
504 | 418 | @staticmethod
|
505 | 419 | def has_access_token(request: Request) -> bool:
|
506 | 420 | """Checks if the request has an access_token.
|
@@ -553,49 +467,5 @@ def get_access_token_from_request(request: Request) -> str:
|
553 | 467 |
|
554 | 468 | return query_params[0].decode("ascii")
|
555 | 469 |
|
556 |
| - async def check_user_in_room_or_world_readable( |
557 |
| - self, room_id: str, user_id: str, allow_departed_users: bool = False |
558 |
| - ) -> Tuple[str, Optional[str]]: |
559 |
| - """Checks that the user is or was in the room or the room is world |
560 |
| - readable. If it isn't then an exception is raised. |
561 |
| -
|
562 |
| - Args: |
563 |
| - room_id: room to check |
564 |
| - user_id: user to check |
565 |
| - allow_departed_users: if True, accept users that were previously |
566 |
| - members but have now departed |
567 |
| -
|
568 |
| - Returns: |
569 |
| - Resolves to the current membership of the user in the room and the |
570 |
| - membership event ID of the user. If the user is not in the room and |
571 |
| - never has been, then `(Membership.JOIN, None)` is returned. |
572 |
| - """ |
573 |
| - |
574 |
| - try: |
575 |
| - # check_user_in_room will return the most recent membership |
576 |
| - # event for the user if: |
577 |
| - # * The user is a non-guest user, and was ever in the room |
578 |
| - # * The user is a guest user, and has joined the room |
579 |
| - # else it will throw. |
580 |
| - member_event = await self.check_user_in_room( |
581 |
| - room_id, user_id, allow_departed_users=allow_departed_users |
582 |
| - ) |
583 |
| - return member_event.membership, member_event.event_id |
584 |
| - except AuthError: |
585 |
| - visibility = await self.state.get_current_state( |
586 |
| - room_id, EventTypes.RoomHistoryVisibility, "" |
587 |
| - ) |
588 |
| - if ( |
589 |
| - visibility |
590 |
| - and visibility.content.get("history_visibility") |
591 |
| - == HistoryVisibility.WORLD_READABLE |
592 |
| - ): |
593 |
| - return Membership.JOIN, None |
594 |
| - raise AuthError( |
595 |
| - 403, |
596 |
| - "User %s not in room %s, and room previews are disabled" |
597 |
| - % (user_id, room_id), |
598 |
| - ) |
599 |
| - |
600 | 470 | async def check_auth_blocking(self, *args, **kwargs) -> None:
|
601 | 471 | await self._auth_blocking.check_auth_blocking(*args, **kwargs)
|
0 commit comments