Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Implement delete_devices API #1993

Merged
merged 3 commits into from Mar 14, 2017

Conversation

Projects
None yet
4 participants
Contributor

lukebarnard1 commented Mar 13, 2017 edited

This implements the proposal here https://docs.google.com/document/d/1C-25Gqz3TXy2jIAoeOKxpNtmme0jI4g3yFGqv5GlAAk for deleting multiple devices using a single request.

Implement delete_devices API
This implements the proposal here https://docs.google.com/document/d/1C-25Gqz3TXy2jIAoeOKxpNtmme0jI4g3yFGqv5GlAAk for deleting multiple devices at once in a single request.
synapse/rest/client/v2_alpha/devices.py
@@ -45,6 +45,52 @@ def on_GET(self, request):
)
defer.returnValue((200, {"devices": devices}))
+class DeleteDevicesRestServlet(servlet.RestServlet):
+ PATTERNS = client_v2_patterns("/delete_devices", releases=[], v2_alpha=False)
@erikjohnston

erikjohnston Mar 13, 2017

Owner

Could you add a docstring to say what this and what form the API roughly takes, e.g.:

API for bulk deletion of devices. Accepts a json object with a devices key which lists the device_ids to delete. Requires user interactive auth.

synapse/rest/client/v2_alpha/devices.py
+ """
+ Args:
+ hs (synapse.server.HomeServer): server
+ """
@erikjohnston

erikjohnston Mar 13, 2017

Owner

Pointless docstring is pointless

synapse/rest/client/v2_alpha/devices.py
+ def on_POST(self, request):
+ try:
+ body = servlet.parse_json_object_from_request(request)
+
@erikjohnston

erikjohnston Mar 13, 2017

Owner

Bit of a spurious newline here.

synapse/rest/client/v2_alpha/devices.py
+ # the same as those that pass an empty dict
+ body = {}
+ else:
+ raise
@erikjohnston

erikjohnston Mar 13, 2017

Owner

Generally its best to do raise e, as if you later add a yield foo then you will re-raise the wrong error

synapse/rest/client/v2_alpha/devices.py
+ defer.returnValue((401, result))
+
+ requester = yield self.auth.get_user_by_req(request)
+ for d_id in body['devices']:
@erikjohnston

erikjohnston Mar 13, 2017

Owner

This is fine for the first cut, but might be nice to change delete_device to delete_devices and then pass around the list through everywhere. This has a number of advantages: a) it reduces work as a lot of things are cheaper to do in bulk, b) it makes it easier to make the API either succeed or fail, rather than partially succeed if something fails halfway through

lukebarnard1 added some commits Mar 13, 2017

Implement _simple_delete_many_txn, use it to delete devices
(But this doesn't implement the same for deleting access tokens or e2e keys.

Also respond to code review.
Contributor

lukebarnard1 commented Mar 13, 2017

Owner

ara4n commented Mar 13, 2017 edited

what is the rationale for this ooi? (as I thought vector-im/riot-web#2464 was a sufficient fix...)

Owner

erikjohnston commented Mar 14, 2017

@ara4n Riot web cheekily implements bulk deletion of devices by caching the password temporarily, if i understand correctly, so I think it makes sense to have a bulk deletion API. (It also means we only notify about device changes once than for each individual device).

Owner

erikjohnston commented Mar 14, 2017

lgtm

Owner

ara4n commented Mar 14, 2017

ok... would be helpful if there was a matching riot bug for this, if nothing else to aid prioritisation relative to the other fires on the riot side (and to ensure the clientside of the api actually gets implemented!)

Contributor

lukebarnard1 commented Mar 14, 2017

@ara4n it's on my list of todos, and overlaps nicely with vector-im/riot-web#3268 as it will need a similar multi-select table

@lukebarnard1 lukebarnard1 merged commit f29d85d into develop Mar 14, 2017

7 of 8 checks passed

Sytest Dendron (Commit) Build #1666 origin/luke/delete-devices failed in 12 min
Details
Sytest Dendron (Merged PR) Build finished.
Details
Sytest Postgres (Commit) Build #2479 origin/luke/delete-devices succeeded in 8 min 8 sec
Details
Sytest Postgres (Merged PR) Build finished.
Details
Sytest SQLite (Commit) Build #2545 origin/luke/delete-devices succeeded in 6 min 35 sec
Details
Sytest SQLite (Merged PR) Build finished.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@lampholder lampholder removed the in progress label Mar 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment