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

Commit

Permalink
Merge pull request #1223 from mozilla-services/feat/issue-1207
Browse files Browse the repository at this point in the history
feat: port drop user command to Rust
  • Loading branch information
bbangert authored May 11, 2018
2 parents 616248a + a9cd4ae commit 4ef30e0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 64 deletions.
27 changes: 0 additions & 27 deletions autopush/tests/test_webpush_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import factory
from mock import Mock
from twisted.logger import globalLogPublisher
import pytest

from autopush.db import (
DatabaseManager,
Expand All @@ -26,7 +25,6 @@
from autopush.webpush_server import (
CheckStorage,
DeleteMessage,
DropUser,
MigrateUser,
StoreMessages,
Unregister,
Expand Down Expand Up @@ -231,31 +229,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,20 +254,17 @@ 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.unregister_process = UnregisterCommand(conf, db)
self.store_messages_process = StoreMessagesUserCommand(conf, db)
self.deserialize = dict(
delete_message=DeleteMessage,
drop_user=DropUser,
migrate_user=MigrateUser,
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,
unregister=self.unregister_process,
store_messages=self.store_messages_process,
Expand Down Expand Up @@ -376,13 +363,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 @@ -128,10 +128,6 @@ enum Call {
message_month: String,
},

DropUser {
uaid: String,
},

MigrateUser {
uaid: String,
message_month: String,
Expand Down Expand Up @@ -168,11 +164,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 @@ -214,12 +205,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<()>,
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 @@ -855,6 +855,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(()))
})
.chain_err(|| "Unable to drop user record");
Box::new(response)
}

pub fn check_storage(
&self,
table_name: &str,
Expand Down

0 comments on commit 4ef30e0

Please sign in to comment.