Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: remove users 😵 #1344

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

Conversation

luke-mcfarlane-rocketlab
Copy link
Contributor

@luke-mcfarlane-rocketlab luke-mcfarlane-rocketlab commented Feb 26, 2025

JIRA Ticket

BSS-670

Description

Added the ability for cluster admins to remove users from the platform.

Proposed Changes

  • Added "cluster-admin" property to the user context provider
  • Updated get user API to return whether user is cluster admin
  • Added API endpoint for removing a user
  • Added function to remove user from couchdb
  • Added remove user dialog
  • Created _protected route to include all pages which require auth so that we can have pages which do not require auth

How to Test

  1. Log in as cluster admin
  2. Navigate to user list
  3. Delete a user which is not a cluster admin
  4. (Optional) Verify non cluster admins cannot remove users

Additional Information

I think we should consider removing the "reset password" functionality from the new conductor and replace it with an email flow in old conductor. The current approach would allow cluster-admins to impersonate users.

Checklist

  • I have confirmed all commits have been signed.
  • I have added JSDoc style comments to any new functions or classes.
  • Relevant documentation such as READMEs, guides, and class comments are updated.

Signed-off-by: Luke McFarlane <luke.mcfarlane@rocketlab.com.au>
Signed-off-by: Luke McFarlane <luke.mcfarlane@rocketlab.com.au>
Signed-off-by: Luke McFarlane <luke.mcfarlane@rocketlab.com.au>
Signed-off-by: Luke McFarlane <luke.mcfarlane@rocketlab.com.au>
Signed-off-by: Luke McFarlane <luke.mcfarlane@rocketlab.com.au>
@ranisa-gupta16
Copy link
Contributor

@luke-mcfarlane-rocketlab please resolve the conflicts. Thanks. :-)

Copy link
Contributor

@ranisa-gupta16 ranisa-gupta16 left a comment

Choose a reason for hiding this comment

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

This is one of the important features. Looking good,
I have left few comments to address, should be quick ones to address.
Let me know if you have any questions
Thanks! :-)

'Only cluster admins can remove users.'
);

if (!id) throw new Exceptions.ValidationException('User ID not specified');
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good validation , however can you please also add checks for invalid user?

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 I understand what you mean by invalid user? The user calling the API or the user being removed?

function RouteComponent() {
const auth = useAuth();

if (!auth.user) return <></>;
Copy link
Contributor

Choose a reason for hiding this comment

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

with the empty fragment, it causes the UI flickering, can you show a loading spinner instead?

* @param {string} userId - The ID of the user to remove.
* @returns {JSX.Element} The rendered RemoveUserDialog component.
*/
export const RemoveUserDialog = ({userId}: {userId: string}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

if userId is missing or invalid , can we disable the delete button, it might leadd to a bad request.

<Button
className="w-full"
onClick={async () => {
const response = await fetch(
Copy link
Contributor

Choose a reason for hiding this comment

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

directly fetching responses here is risky I believe,can you please wrap this in a try-catch block to handle network failures?

return;
}

QueryClient.invalidateQueries({queryKey: ['users', undefined]});
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't be the query key = 'users' instead of 'users', undefined? wouldn't it cause query caching issues? thinking out loud let me know what you think. :-)

);

removeUser(userToRemove);

Copy link
Contributor

Choose a reason for hiding this comment

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

would it be possible to wrap this in try-catch to handle possible database failures?


if (!users_db) throw new Error('Failed to connect to user database');

if (!user._id || !user._rev) throw new Error('User not found');
Copy link
Contributor

Choose a reason for hiding this comment

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

instead og generic error here, can we return a HTTP response code ? like 404 not found using exception handler?
we can say - throw new Exception.ItemNotFoundException('Usernot found in database.', 404);
let me know your thoughts. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not an endpoint - its just a function, but yes this is thrown from the endpoint


const {status} = await getUserDetails(token, refreshToken);

if (status === 'success') return;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we wrap this in try-catch please?
something like. if (status === 'success') return;
} catch (error) {
console.error('Failed to fetch user details:', error);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved at the provider

@ranisa-gupta16
Copy link
Contributor

Please also resolve the conflicts. :-) @luke-mcfarlane-rocketlab

Signed-off-by: Luke McFarlane <luke.mcfarlane@rocketlab.com.au>
Signed-off-by: Luke McFarlane <luke.mcfarlane@rocketlab.com.au>
@luke-mcfarlane-rocketlab
Copy link
Contributor Author

@ranisa-gupta16 all resolved

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants