Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to delete user #215

Merged
merged 3 commits into from
Mar 2, 2022
Merged

Conversation

vbmade2000
Copy link
Contributor

Addresses #83.

@ecton
Copy link
Member

ecton commented Mar 2, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@ecton ecton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for tackling this. I have left a few minor pieces of feedback. Great work!

@@ -326,6 +332,8 @@ pub enum ServerResponse {
/// The id of the user created.
id: u64,
},
/// A user was deleted.
UserDeleted,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is no information being returned, let's remove this variant and have the networking client use Response::Ok instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 735 to 741
// // Retrieve a user to delete
// let doc = self
// .admin()
// .await
// .collection::<User>()
// .get(primary_key)
// .await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this disabled code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

#[cfg_attr(feature = "actionable-traits", actionable(protection = "simple"))]
DeleteUser {
/// The unique primary key of the user to be deleted.
primary_key: NamedReference<'static, u64>,
Copy link
Member

@ecton ecton Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match the other networking requests, let's rename this to user. A NamedReference can be either a unique name (in this case, the username) or the primary key (in this case, u64). Since it can contain data that isn't the primary_key, that's why I used user instead on the other request types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@vbmade2000 vbmade2000 requested a review from ecton March 2, 2022 16:36
Copy link
Member

@ecton ecton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approved the changes before having a chance to run the full test suite -- cargo test --all-features. Once I ran it locally, I saw the failure and was surprised I missed the server implementation on review.

crates/bonsaidb-server/src/server.rs Show resolved Hide resolved
let doc = User::load(user, &admin)
.await?
.ok_or(bonsaidb_core::Error::UserNotFound)?;
self.admin().await.collection::<User>().delete(&doc).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.admin().await.collection::<User>().delete(&doc).await?;
doc.delete(&admin).await?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@vbmade2000 vbmade2000 requested a review from ecton March 2, 2022 17:50
@ecton ecton merged commit 9a023f2 into khonsulabs:main Mar 2, 2022
@ecton ecton mentioned this pull request Mar 2, 2022
2 tasks
ecton added a commit that referenced this pull request Mar 2, 2022
Also added more notes on what to run before pushing changes. I need to
get CI hooked up to pull requests.

Refs #215
@vbmade2000 vbmade2000 deleted the add_delete_user_83 branch March 4, 2022 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants