comments watcha

pull/187/head watcha-20240528T102955-d92e2cc
DevSymbioide 2 years ago
parent 9964d9931d
commit d92e2cc7e7
  1. 15
      synapse/handlers/watcha_administration.py
  2. 24
      synapse/handlers/watcha_nextcloud.py
  3. 15
      synapse/handlers/watcha_registration.py
  4. 3
      synapse/rest/client/watcha.py

@ -2,7 +2,7 @@ import logging
from synapse.api.errors import SynapseError
from synapse.types import UserID
from synapse.types import Requester
from synapse.types import Requester # watcha+
from synapse.util.watcha import build_log_message
logger = logging.getLogger(__name__)
@ -58,16 +58,23 @@ class AdministrationHandler:
await self.store.update_user_role(user_id, target_role)
return target_role
""" watcha!
async def get_user_role(self, user_id):
!watcha"""
async def get_user_role(self, requester: Requester):
async def get_user_role(self, requester: Requester): # watcha+
"""Retrieve user role [administrator|collaborator|partner]
Returns:
The user role.
"""
user_id = requester.user.to_string()
user_id = requester.user.to_string() # watcha+
is_partner = await self.auth_handler.is_partner(user_id)
is_admin = await self.auth.is_server_admin(requester)
""" watcha!
is_admin = await self.auth.is_server_admin(UserID.from_string(user_id))
!watcha"""
is_admin = await self.auth.is_server_admin(requester) # watcha+
if is_partner and is_admin:
raise SynapseError(

@ -44,10 +44,18 @@ class NextcloudHandler:
async def handle_room_member_event(
self, requester: Requester, room_id: str, user_id: str, membership: str
):
""" watcha!
if (
await self.administration_handler.get_user_role(user_id) == "partner"
and not self.config.watcha.external_authentication_for_partners
):
!watcha """
# watcha+
if (
await self.administration_handler.get_user_role(requester) == "partner"
and not self.config.watcha.external_authentication_for_partners
):
# +watcha
return
if await self.store.get_share_id(room_id):
@ -84,8 +92,14 @@ class NextcloudHandler:
# file sharing
# ============
"""watcha!
async def update_share(self, room_id: str, user_id: str, event_content: dict):
await self.auth.check_user_in_room(room_id, user_id)
!watcha"""
# watcha+
async def update_share(self, room_id: str, requester: Requester, event_content: dict):
await self.auth.check_user_in_room(room_id, requester)
# +watcha
nextcloud_url = event_content["nextcloudShare"]
@ -100,10 +114,16 @@ class NextcloudHandler:
),
)
nextcloud_folder_path = url_query["dir"][0]
await self.bind(requester.user.to_string(), room_id, nextcloud_folder_path)
"""watcha!
await self.bind(user_id, room_id, nextcloud_folder_path)
!watcha"""
await self.bind(requester.user.to_string(), room_id, nextcloud_folder_path) # watcha+
else:
await self.unbind(requester.user.to_string(), room_id)
"""watcha!
await self.unbind(user_id, room_id)
!watcha"""
await self.unbind(requester.user.to_string(), room_id) # watcha+
async def bind(self, requester_id: str, room_id: str, path: str):
"""Bind a Nextcloud folder with a room in three steps :

@ -3,9 +3,12 @@ import uuid
from typing import Optional, TYPE_CHECKING
from synapse.api.errors import HttpResponseException
""" watcha!
from synapse.config.emailconfig import ThreepidBehaviour
!watcha"""
from synapse.push.mailer import Mailer
from synapse.util.watcha import ActionStatus, Secrets, build_log_message
from synapse.types import UserID
from synapse.types import UserID # watcha+
if TYPE_CHECKING:
from synapse.server import HomeServer
@ -25,7 +28,10 @@ class RegistrationHandler:
self.nextcloud_client = hs.get_nextcloud_client()
self.secrets = Secrets()
if hs.config.email.can_verify_email:
""" watcha!
if hs.config.email.threepid_behaviour_email == ThreepidBehaviour.LOCAL:
!watcha"""
if hs.config.email.can_verify_email: # watcha+
self.mailer = Mailer(
hs=hs,
app_name=hs.config.email.email_app_name,
@ -133,7 +139,10 @@ class RegistrationHandler:
)
if self.hs.config.userdirectory.user_directory_search_all_users:
profile = await self.store.get_profileinfo(UserID.from_string(user_id))
"""watcha!
profile = await self.store.get_profileinfo(localpart)
!watcha"""
profile = await self.store.get_profileinfo(UserID.from_string(user_id)) # watcha+
await self.user_directory_handler.handle_local_profile_change(
user_id, profile
)

@ -8,6 +8,9 @@ from synapse.api.errors import (
NextcloudError,
SynapseError,
)
""" watcha!
from synapse.config.emailconfig import ThreepidBehaviour
!watcha"""
from synapse.http.servlet import RestServlet, parse_json_object_from_request
from synapse.push.mailer import Mailer
from synapse.rest.admin._base import assert_requester_is_admin, assert_user_is_admin

Loading…
Cancel
Save