From c1965becf16bfe70029abed2fede87b3b63bb51e Mon Sep 17 00:00:00 2001 From: Ben Bangert Date: Thu, 10 May 2018 10:55:48 -0700 Subject: [PATCH] feat: port drop user command to Rust Closes #1207 --- autopush/tests/test_webpush_server.py | 26 -------------------------- autopush/webpush_server.py | 20 -------------------- autopush_rs/src/call.rs | 15 --------------- autopush_rs/src/client.rs | 5 +++-- autopush_rs/src/util/ddb_helpers.rs | 14 ++++++++++++++ 5 files changed, 17 insertions(+), 63 deletions(-) diff --git a/autopush/tests/test_webpush_server.py b/autopush/tests/test_webpush_server.py index 953af1eb..4dff61ef 100644 --- a/autopush/tests/test_webpush_server.py +++ b/autopush/tests/test_webpush_server.py @@ -26,7 +26,6 @@ from autopush.webpush_server import ( CheckStorage, DeleteMessage, - DropUser, MigrateUser, Register, StoreMessages, @@ -232,31 +231,6 @@ def test_delete_message(self): assert len(results.messages) == 5 -class TestDropUserProcessor(BaseSetup): - def _makeFUT(self): - from autopush.webpush_server import DropUserCommand - return DropUserCommand(self.conf, self.db) - - def test_drop_user(self): - drop_command = self._makeFUT() - - # Create a user - user = UserItemFactory() - uaid = user["uaid"] - self.db.router.register_user(user) - - # Check that its there - item = self.db.router.get_uaid(uaid) - assert item is not None - - # Drop it - drop_command.process(DropUser(uaid=uaid)) - - # Verify its gone - with pytest.raises(ItemNotFound): - self.db.router.get_uaid(uaid) - - class TestMigrateUserProcessor(BaseSetup): def _makeFUT(self): from autopush.webpush_server import MigrateUserCommand diff --git a/autopush/webpush_server.py b/autopush/webpush_server.py index 1396bb03..42249b66 100644 --- a/autopush/webpush_server.py +++ b/autopush/webpush_server.py @@ -139,11 +139,6 @@ class DeleteMessage(InputCommand): message = attrib(convert=dict_to_webpush_message) # type: WebPushMessage -@attrs(slots=True) -class DropUser(InputCommand): - uaid = attrib(convert=uaid_from_str) # type: UUID - - @attrs(slots=True) class MigrateUser(InputCommand): uaid = attrib(convert=uaid_from_str) # type: UUID @@ -180,11 +175,6 @@ class DeleteMessageResponse(OutputCommand): success = attrib(default=True) # type: bool -@attrs(slots=True) -class DropUserResponse(OutputCommand): - success = attrib(default=True) # type: bool - - @attrs(slots=True) class MigrateUserResponse(OutputCommand): message_month = attrib() # type: str @@ -264,14 +254,12 @@ def __init__(self, conf, db): self.db = db self.check_storage_processor = CheckStorageCommand(conf, db) self.delete_message_processor = DeleteMessageCommand(conf, db) - self.drop_user_processor = DropUserCommand(conf, db) self.migrate_user_proocessor = MigrateUserCommand(conf, db) self.register_process = RegisterCommand(conf, db) self.unregister_process = UnregisterCommand(conf, db) self.store_messages_process = StoreMessagesUserCommand(conf, db) self.deserialize = dict( delete_message=DeleteMessage, - drop_user=DropUser, migrate_user=MigrateUser, register=Register, unregister=Unregister, @@ -279,7 +267,6 @@ def __init__(self, conf, db): ) self.command_dict = dict( delete_message=self.delete_message_processor, - drop_user=self.drop_user_processor, migrate_user=self.migrate_user_proocessor, register=self.register_process, unregister=self.unregister_process, @@ -379,13 +366,6 @@ def process(self, command): return DeleteMessageResponse() -class DropUserCommand(ProcessorCommand): - def process(self, command): - # type: (DropUser) -> DropUserResponse - self.db.router.drop_user(command.uaid.hex) - return DropUserResponse() - - class MigrateUserCommand(ProcessorCommand): def process(self, command): # type: (MigrateUser) -> MigrateUserResponse diff --git a/autopush_rs/src/call.rs b/autopush_rs/src/call.rs index 2420a53b..d3b747a4 100644 --- a/autopush_rs/src/call.rs +++ b/autopush_rs/src/call.rs @@ -135,10 +135,6 @@ enum Call { message_month: String, }, - DropUser { - uaid: String, - }, - MigrateUser { uaid: String, message_month: String, @@ -189,11 +185,6 @@ pub struct DeleteMessageResponse { pub success: bool, } -#[derive(Deserialize)] -pub struct DropUserResponse { - pub success: bool, -} - #[derive(Deserialize)] pub struct MigrateUserResponse { pub message_month: String, @@ -252,12 +243,6 @@ impl Server { return fut; } - pub fn drop_user(&self, uaid: String) -> MyFuture { - let (call, fut) = PythonCall::new(&Call::DropUser { uaid }); - self.send_to_python(call); - return fut; - } - pub fn migrate_user( &self, uaid: String, diff --git a/autopush_rs/src/client.rs b/autopush_rs/src/client.rs index 4e6e96fe..5bfb463b 100644 --- a/autopush_rs/src/client.rs +++ b/autopush_rs/src/client.rs @@ -592,7 +592,7 @@ where #[state_machine_future(transitions(AuthDone))] AwaitDropUser { - response: MyFuture, + response: MyFuture, data: AuthClientData, }, @@ -696,7 +696,8 @@ where ); transition!(AwaitMigrateUser { response, data }); } else if all_acked && webpush.flags.reset_uaid { - let response = data.srv.drop_user(webpush.uaid.simple().to_string()); + + let response = data.srv.ddb.drop_uaid(&data.srv.opts.router_table_name, &webpush.uaid); transition!(AwaitDropUser { response, data }); } transition!(AwaitInput { data }) diff --git a/autopush_rs/src/util/ddb_helpers.rs b/autopush_rs/src/util/ddb_helpers.rs index dc5d9930..0dae2e88 100644 --- a/autopush_rs/src/util/ddb_helpers.rs +++ b/autopush_rs/src/util/ddb_helpers.rs @@ -777,6 +777,20 @@ impl DynamoStorage { Box::new(response) } + pub fn drop_uaid( + &self, + table_name: &str, + uaid: &Uuid, + ) -> MyFuture { + let ddb = self.ddb.clone(); + let response = DynamoStorage::drop_user(ddb, uaid, table_name) + .and_then(move |_| -> MyFuture<_> { + Box::new(future::ok(true)) + }) + .chain_err(|| "Unable to drop user record"); + Box::new(response) + } + pub fn check_storage( &self, table_name: &str,