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

Mrc-5324 Update return values of Create/update/delete + add role/user-update endpoint #68

Merged
merged 25 commits into from
May 20, 2024

Conversation

absternator
Copy link
Contributor

@absternator absternator commented May 7, 2024

As per previious PR comments, we are no longer returning the x has been created . for creation and update we are returning to. For deletion returning nocontent

Also I have added another endpoint role/update-users... this is the opposite of the user/update-roles endpoint... found would be good to have both for the FE when doing mockups...These are both extracted into UserRoleService... this endpoint has added in this PR and not part of role.update PR as had more DTos and structure

Copy link

codecov bot commented May 7, 2024

Codecov Report

Attention: Patch coverage is 98.03922% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 94.29%. Comparing base (0b8e756) to head (bcb06dc).
Report is 18 commits behind head on main.

Files Patch % Lines
...pp/src/app/components/login/UpdatePasswordForm.tsx 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #68      +/-   ##
==========================================
+ Coverage   93.98%   94.29%   +0.30%     
==========================================
  Files          67       71       +4     
  Lines         532      578      +46     
  Branches      131      146      +15     
==========================================
+ Hits          500      545      +45     
- Misses         30       31       +1     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@absternator absternator changed the title Mrc-5234 Update return values of Create/update/delete Mrc-5234 Update return values of Create/update/delete + add role/user-update endpoint May 10, 2024
@absternator absternator mentioned this pull request May 13, 2024
Base automatically changed from mrc-5317-user-delete to main May 14, 2024 14:13
Copy link
Contributor

@EmmaLRussell EmmaLRussell left a comment

Choose a reason for hiding this comment

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

Looks good, just some minor comments. 👍

@@ -45,6 +48,17 @@ class RoleController(private val roleService: RoleService)
return ResponseEntity.noContent().build()
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're now returning the updated role on PUT of users, for consistency should do the same when PUT permissions. Similarly for any other PUTs.

{
@PostMapping("/basic")
fun createBasicUser(
@RequestBody @Validated createBasicUser: CreateBasicUser
): ResponseEntity<Map<String, String?>>
): ResponseEntity<UserDto?>
Copy link
Contributor

Choose a reason for hiding this comment

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

Response type here shouldn't need to be nullable I don't think? It isn't for create role.

@@ -34,7 +37,7 @@ class RoleController(private val roleService: RoleService)
return ResponseEntity.noContent().build()
}

@PutMapping("/update-permissions/{roleName}")
@PutMapping("/{roleName}/permissions")
Copy link
Contributor

Choose a reason for hiding this comment

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

The Delete function above should have return type ResponseEntity<Unit> too - similarly any others which now return noContent

fun updateUsersToRole(
@RequestBody @Validated usersToUpdate: UpdateRoleUsers,
@PathVariable roleName: String
): ResponseEntity<RoleDto?>
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, don't think this should need to be nullable?

val user = userService.getByUsername(username)
?: throw PackitException("userNotFound", HttpStatus.NOT_FOUND)

val rolesToUpdate = getRolesForUpdate(updateUserRoles.roleNamesToAdd + updateUserRoles.roleNamesToRemove)
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels a bit odd to concatenate the role names like this to fetch the roles, and then have to filter the returned role list for the add and remove. Feels like a bit of a false economy, when you could just make two calls to getRolesForUpdate and keep them separate all along.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the main reason for this is to save a db hit...if I called both separate that would hit db twice

Comment on lines +62 to +63
user.roles.add(role)
role.users.add(user)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to do both of these? Shouldn't just one add the row to the link table? It's the user that you're saving in the calling method, so should just need to update the user entity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are correct updating the user entity is enough to persist data.... the updating of role is mainly so we can return the role back with correct users

return userService.saveUser(user)
}

override fun updateRoleUsers(roleName: String, usersToUpdate: UpdateRoleUsers): Role
Copy link
Contributor

Choose a reason for hiding this comment

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

We might also want to consider adding a check that a user isn't attempting to remove themselves from the ADMIN role..

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 feel like if they want to they should be able to 😄 ... eg. you give some ADMIN rights but want to retract that later

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case it wouldn't be them removing their own role...probably! Or maybe should make sure there's always at least one admin? Well, can add that later if we need to.

Copy link
Contributor

@EmmaLRussell EmmaLRussell left a comment

Choose a reason for hiding this comment

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

Looks good - I still think it would be good to change deleteRole in RoleController to return a ResponseEntity<Unit>, though that wasn't done in this changeset.

@absternator absternator changed the title Mrc-5234 Update return values of Create/update/delete + add role/user-update endpoint Mrc-5324 Update return values of Create/update/delete + add role/user-update endpoint May 20, 2024
@absternator absternator merged commit b8a7133 into main May 20, 2024
5 checks passed
@absternator absternator deleted the mrc-5324-update-endpoints-return-data branch May 20, 2024 06:51
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