Implement updating devices

You can update the displayname of devices now.
This commit is contained in:
Richard van der Hoff 2016-07-25 17:51:24 +01:00
parent 436bffd15f
commit 012b4c1913
5 changed files with 120 additions and 9 deletions

View file

@ -81,7 +81,7 @@ class DeviceStore(SQLBaseStore):
Args:
user_id (str): The ID of the user which owns the device
device_id (str): The ID of the device to retrieve
device_id (str): The ID of the device to delete
Returns:
defer.Deferred
"""
@ -91,6 +91,31 @@ class DeviceStore(SQLBaseStore):
desc="delete_device",
)
def update_device(self, user_id, device_id, new_display_name=None):
"""Update a device.
Args:
user_id (str): The ID of the user which owns the device
device_id (str): The ID of the device to update
new_display_name (str|None): new displayname for device; None
to leave unchanged
Raises:
StoreError: if the device is not found
Returns:
defer.Deferred
"""
updates = {}
if new_display_name is not None:
updates["display_name"] = new_display_name
if not updates:
return defer.succeed(None)
return self._simple_update_one(
table="devices",
keyvalues={"user_id": user_id, "device_id": device_id},
updatevalues=updates,
desc="update_device",
)
@defer.inlineCallbacks
def get_devices_by_user(self, user_id):
"""Retrieve all of a user's registered devices.