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 ed005e6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 36 deletions.
19 changes: 0 additions & 19 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 @@ -271,15 +261,13 @@ def __init__(self, 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 +367,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 ed005e6

Please sign in to comment.