Skip to content

Comments

feat: implement delete role action#423

Merged
NathaelB merged 7 commits intoferriskey:mainfrom
Ptrskay3:feat/delete-role
Sep 3, 2025
Merged

feat: implement delete role action#423
NathaelB merged 7 commits intoferriskey:mainfrom
Ptrskay3:feat/delete-role

Conversation

@Ptrskay3
Copy link
Contributor

@Ptrskay3 Ptrskay3 commented Sep 3, 2025

Closes #378.

Still WIP.

@Ptrskay3
Copy link
Contributor Author

Ptrskay3 commented Sep 3, 2025

Sorry, the PR may not be broken up into small focused commits. If you want, I can rebase later.

@NathaelB
Copy link
Member

NathaelB commented Sep 3, 2025

Yes, thank you so much for you time.
Yes you can rebase when you have the time.

Copy link
Contributor Author

@Ptrskay3 Ptrskay3 left a comment

Choose a reason for hiding this comment

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

Marked some ambiguous parts and future improvements

Comment on lines 73 to 77
let users_affected = self
.user_role_service
.delete_role_relations_by_id(params.role_id)
.await
.map_err(|_| RoleError::InternalServerError)?;
Copy link
Contributor Author

@Ptrskay3 Ptrskay3 Sep 3, 2025

Choose a reason for hiding this comment

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

Deleting a role should somehow interact with existing users. Basically there are two options:

  • Don't allow deleting a role if any users have it. It's probably correct to do that, but in my opinion that is a horrible user experience, since you may have to care about tons of users and unassign/replace the existing role.
  • Wipe all user relations tied to the role. This is what I ended up doing.

I'm not sure which path is better tho, I'm happy to hear your opinion.

Copy link
Member

Choose a reason for hiding this comment

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

I think that for the sake of convenience, if a role is deleted, the relationships --> should be automatically deleted.

I just looked at the migrations and we have an ON DELETE CASCADE.

Copy link
Contributor Author

@Ptrskay3 Ptrskay3 Sep 3, 2025

Choose a reason for hiding this comment

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

Sure, I missed the ON DELETE CASCADE part. Deleted this whole logic , along with the users_affected return value in 4f519eb

Comment on lines 152 to 155
fn delete_role_relations_by_id(
&self,
role_id: Uuid,
) -> impl Future<Output = Result<u64, UserError>> + Send;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure this is the right place or the right name for this fn, but it does the thing.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it is not necessary, because by default the relation is deleted when the user or the role is deleted.

Comment on lines +68 to +71
self.role_service
.delete_by_id(params.role_id)
.await
.map_err(|_| RoleError::InternalServerError)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently there is no protection to delete all roles, even system-level ones, that may break the whole Ferriskey instance.

Copy link
Member

Choose a reason for hiding this comment

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

Yes is similar to keycloak, in keycloak you can update the realm master name, and its finish xD

Maybe later , add the defensive system for this use-case.

@LeadcodeDev LeadcodeDev changed the title Feat/delete role feat: implement delete role action Sep 3, 2025
Comment on lines +98 to +99
// FIXME: there is no bulk delete endpoint, and this one may be inefficient, and the
// stacked toast messages will look bad.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Arguably there shouldn't be a bulk delete endpoint for this, but the issue in the comment is somewhat real. I'm no React magician by any means, but happy to hear suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

For now it's good I think.

pub async fn get_role(
Path(realm_name): Path<String>,
Path(role_id): Path<Uuid>,
Path((realm_name, role_id)): Path<(String, Uuid)>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm using 0.8.4 axum, and these changes were necessary for me to avoid a panic, namely

 Note that multiple parameters must be extracted with a tuple `Path<(_, _)>` or a struct `Path<YourParams>

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we had to use non-typed routes, and during migration we put a lot of endpoints in this case. I fix them when I come across them.

@NathaelB
Copy link
Member

NathaelB commented Sep 3, 2025

It's ready for review ?

@Ptrskay3 Ptrskay3 marked this pull request as ready for review September 3, 2025 09:27
@Ptrskay3
Copy link
Contributor Author

Ptrskay3 commented Sep 3, 2025

Yes. A cargo fmt is missing, will do it soon.

@NathaelB NathaelB self-requested a review September 3, 2025 09:52
Copy link
Member

@NathaelB NathaelB 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 for your time, for all the fixes you suggested, and for the role deletion feature.

@NathaelB NathaelB merged commit ba29434 into ferriskey:main Sep 3, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

implement delete role

2 participants