Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
feat: port drop user command to Rust
Browse files Browse the repository at this point in the history
Closes #1207
  • Loading branch information
bbangert committed May 10, 2018
1 parent af272df commit c1965be
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 63 deletions.
26 changes: 0 additions & 26 deletions autopush/tests/test_webpush_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from autopush.webpush_server import (
CheckStorage,
DeleteMessage,
DropUser,
MigrateUser,
Register,
StoreMessages,
Expand Down Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions autopush/webpush_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -264,22 +254,19 @@ 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,
store_messages=StoreMessages,
)
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,
Expand Down Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions autopush_rs/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ enum Call {
message_month: String,
},

DropUser {
uaid: String,
},

MigrateUser {
uaid: String,
message_month: String,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -252,12 +243,6 @@ impl Server {
return fut;
}

pub fn drop_user(&self, uaid: String) -> MyFuture<DropUserResponse> {
let (call, fut) = PythonCall::new(&Call::DropUser { uaid });
self.send_to_python(call);
return fut;
}

pub fn migrate_user(
&self,
uaid: String,
Expand Down
5 changes: 3 additions & 2 deletions autopush_rs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ where

#[state_machine_future(transitions(AuthDone))]
AwaitDropUser {
response: MyFuture<call::DropUserResponse>,
response: MyFuture<bool>,
data: AuthClientData<T>,
},

Expand Down Expand Up @@ -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 })
Expand Down
14 changes: 14 additions & 0 deletions autopush_rs/src/util/ddb_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,20 @@ impl DynamoStorage {
Box::new(response)
}

pub fn drop_uaid(
&self,
table_name: &str,
uaid: &Uuid,
) -> MyFuture<bool> {
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,
Expand Down

0 comments on commit c1965be

Please sign in to comment.