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

rename membership and adopt newtype pattern #5320

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

stefan0xC
Copy link
Contributor

I've been working on improving Vaultwarden's legibility by renaming the UsersOrganizations to simply Membership and making it clearer when something is referring to the User and when to a Membership relation.

After doing that I was motivated to try my hands on using the newtype pattern so that the Rust type system can be used to check on compile time if we always call the right uuid because there are a lot of Strings that can be used interchangeably otherwise.

For example I noticed that we are passing the wrong id here:

let mut group_entry = GroupUser::new(String::from(group), user.uuid.clone());

Because in contrast to CollectionUser the GroupUser::new actually expects a different id:

pub fn new(groups_uuid: String, users_organizations_uuid: String) -> Self {
This was probably overlooked because it's not a major issue when a user is not correctly invited to a group and it only shows up as a small warning in the logs:

[2024-12-22 21:23:47.022][request][INFO] POST /api/organizations/152bd996-19f9-40ee-b991-e52333a7e719/users/invite
[2024-12-22 21:23:47.031][vaultwarden::db::models::group][WARN] User could not be found!
[2024-12-22 21:23:48.082][response][INFO] (send_invite) POST /api/organizations/<org_id>/users/invite => 200 OK

src/api/core/sends.rs Outdated Show resolved Hide resolved
Copy link
Owner

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

Love this, I've been meaning for a while to do something about all the untyped string ids and never put much time into it as it seemed like a huge task. Thanks for the great work @stefan0xC!

Gave it a quick look and it looks pretty good, just have a couple of questions

src/db/models/user.rs Outdated Show resolved Hide resolved
src/db/models/user.rs Show resolved Hide resolved
@dfunkt
Copy link
Contributor

dfunkt commented Jan 5, 2025

Encountered this when trying to build:

0.831 error: failed to load manifest for workspace member `/app/macros`
0.831 referenced by workspace at `/app/Cargo.toml`
0.831 
0.831 Caused by:
0.831   failed to read `/app/macros/Cargo.toml`
0.831 
0.831 Caused by:
0.831   No such file or directory (os error 2)

I needed to add:

diff --git a/.dockerignore b/.dockerignore
index 05c2a8e3..e11cb4ba 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -11,5 +11,6 @@
 !build.rs
 !Cargo.lock
 !Cargo.toml
+!macros
 !rustfmt.toml
 !rust-toolchain.toml
diff --git a/docker/Dockerfile.alpine b/docker/Dockerfile.alpine
index bc69fd7e..5341f1fd 100644
--- a/docker/Dockerfile.alpine
+++ b/docker/Dockerfile.alpine
@@ -81,6 +81,7 @@ RUN source /env-cargo && \

 # Copies over *only* your manifests and build files
 COPY ./Cargo.* ./rust-toolchain.toml ./build.rs ./
+COPY ./macros ./macros

 ARG CARGO_PROFILE=release

diff --git a/docker/Dockerfile.debian b/docker/Dockerfile.debian
index 896adf85..075d3759 100644
--- a/docker/Dockerfile.debian
+++ b/docker/Dockerfile.debian
@@ -120,6 +120,7 @@ RUN source /env-cargo && \

 # Copies over *only* your manifests and build files
 COPY ./Cargo.* ./rust-toolchain.toml ./build.rs ./
+COPY ./macros ./macros

 ARG CARGO_PROFILE=release

diff --git a/docker/Dockerfile.j2 b/docker/Dockerfile.j2
index 797501ed..66db34eb 100644
--- a/docker/Dockerfile.j2
+++ b/docker/Dockerfile.j2
@@ -147,6 +147,7 @@ RUN source /env-cargo && \

 # Copies over *only* your manifests and build files
 COPY ./Cargo.* ./rust-toolchain.toml ./build.rs ./
+COPY ./macros ./macros

 ARG CARGO_PROFILE=release

@stefan0xC
Copy link
Contributor Author

@dfunkt Thanks for catching that.

dani-garcia
dani-garcia previously approved these changes Jan 8, 2025
Copy link
Owner

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

LGTM, there's a few conflicts that need to be resolved before merging. Thanks for your work on this!

stefan0xC and others added 5 commits January 9, 2025 00:11
rename UserOrganization to Membership to clarify the relation
and prevent confusion whether something refers to a member(ship) or user
@tessus
Copy link
Contributor

tessus commented Jan 9, 2025

@dani-garcia I am afraid you will have to approve this again.

P.S.: sorry for the ping, but github doesn't send notification if a previous approval got invalidated

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.

5 participants