async def update_device(self, user_id: str, device_id: str, content: dict) -> None: """ Update the given device Args: user_id: The user to update devices of. device_id: The device to update. content: body of update request """ # Reject a new displayname which is too long. new_display_name = content.get("display_name") if new_display_name and len(new_display_name) > MAX_DEVICE_DISPLAY_NAME_LEN: raise SynapseError( 400, "Device display name is too long (max %i)" % (MAX_DEVICE_DISPLAY_NAME_LEN,), ) try: await self.store.update_device( user_id, device_id, new_display_name=new_display_name ) await self.notify_device_update(user_id, [device_id]) except errors.StoreError as e: if e.code == 404: raise errors.NotFoundError() else: raise
async def update_device(self, user_id: str, device_id: str, content: dict) -> None: """Update the given device Args: user_id: The user to update devices of. device_id: The device to update. content: body of update request """ # Reject a new displayname which is too long. new_display_name = content.get("display_name") self._check_device_name_length(new_display_name) try: await self.store.update_device(user_id, device_id, new_display_name=new_display_name) await self.notify_device_update(user_id, [device_id]) except errors.StoreError as e: if e.code == 404: raise errors.NotFoundError() else: raise
def update_device(self, user_id, device_id, content): """ Update the given device Args: user_id (str): device_id (str): content (dict): body of update request Returns: defer.Deferred: """ # Reject a new displayname which is too long. new_display_name = content.get("display_name") if new_display_name and len(new_display_name) > MAX_DEVICE_DISPLAY_NAME_LEN: raise SynapseError( 400, "Device display name is too long (max %i)" % (MAX_DEVICE_DISPLAY_NAME_LEN,), ) try: yield self.store.update_device( user_id, device_id, new_display_name=new_display_name ) yield self.notify_device_update(user_id, [device_id]) except errors.StoreError as e: if e.code == 404: raise errors.NotFoundError() else: raise
async def on_GET(self, request: SynapseRequest): requester = await self.auth.get_user_by_req(request) dehydrated_device = await self.device_handler.get_dehydrated_device( requester.user.to_string()) if dehydrated_device is not None: (device_id, device_data) = dehydrated_device result = {"device_id": device_id, "device_data": device_data} return (200, result) else: raise errors.NotFoundError("No dehydrated device available")
async def rehydrate_device(self, user_id: str, access_token: str, device_id: str) -> dict: """Process a rehydration request from the user. Args: user_id: the user who is rehydrating the device access_token: the access token used for the request device_id: the ID of the device that will be rehydrated Returns: a dict containing {"success": True} """ success = await self.store.remove_dehydrated_device(user_id, device_id) if not success: raise errors.NotFoundError() # If the dehydrated device was successfully deleted (the device ID # matched the stored dehydrated device), then modify the access # token to use the dehydrated device's ID and copy the old device # display name to the dehydrated device, and destroy the old device # ID old_device_id = await self.store.set_device_for_access_token( access_token, device_id) old_device = await self.store.get_device(user_id, old_device_id) if old_device is None: raise errors.NotFoundError() await self.store.update_device(user_id, device_id, old_device["display_name"]) # can't call self.delete_device because that will clobber the # access token so call the storage layer directly await self.store.delete_device(user_id, old_device_id) await self.store.delete_e2e_keys_by_device(user_id=user_id, device_id=old_device_id) # tell everyone that the old device is gone and that the dehydrated # device has a new display name await self.notify_device_update(user_id, [old_device_id, device_id]) return {"success": True}
def update_device(self, user_id, device_id, content): """ Update the given device Args: user_id (str): device_id (str): content (dict): body of update request Returns: defer.Deferred: """ try: yield self.store.update_device( user_id, device_id, new_display_name=content.get("display_name") ) yield self.notify_device_update(user_id, [device_id]) except errors.StoreError as e: if e.code == 404: raise errors.NotFoundError() else: raise
async def get_device(self, user_id: str, device_id: str) -> JsonDict: """Retrieve the given device Args: user_id: The user to get the device from device_id: The device to fetch. Returns: info on the device Raises: errors.NotFoundError: if the device was not found """ device = await self.store.get_device(user_id, device_id) if device is None: raise errors.NotFoundError() ips = await self.store.get_last_client_ip_by_device(user_id, device_id) _update_device_from_client_ips(device, ips) set_tag("device", device) set_tag("ips", ips) return device