Skip to content

Conversation

@Vitaliistf
Copy link
Collaborator

@Vitaliistf Vitaliistf commented Sep 23, 2024

Added logic to handle user self-accessing activity to the check user permissions hook.

Comment on lines 19 to 27
const resourceId = (params as { id?: string }).id;
const isUsersRoute = url.includes(APIPath.USERS);
const isCurrentUserRoute = isUsersRoute && Number(resourceId) === user.id;

if (isCurrentUserRoute) {
done();

return;
}
Copy link
Collaborator

@liza-veis liza-veis Sep 23, 2024

Choose a reason for hiding this comment

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

This logic shouldn't be in checkUserPermissions hook. This hook is for common permission case and should now nothing about specific routes and their logic. Instead let's use DELETE /authenticated-user and PATCH /authenticated-user in auth controller for current user, and move the logic related to this routes to auth module

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually let's do it simpler and user DELETE /users, PATCH /users to update or delete current user

Copy link
Collaborator Author

@Vitaliistf Vitaliistf Sep 23, 2024

Choose a reason for hiding this comment

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

So, you mean, user that wants to delete/update his own account now should send a request without id, and the admin that wants to delete other user should use id (permissions will be checked of course), right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes

@what1s1ove what1s1ove merged commit 5e017f5 into main Sep 24, 2024
This was referenced Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

5 participants