-
Notifications
You must be signed in to change notification settings - Fork 60
Fixes null Check where a template is created with an admin (null) user #1292
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Avinash Niyas <[email protected]>
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (14.28%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1292 +/- ##
============================================
- Coverage 77.46% 77.43% -0.03%
- Complexity 1260 1263 +3
============================================
Files 106 106
Lines 5901 5904 +3
Branches 612 614 +2
============================================
+ Hits 4571 4572 +1
Misses 1034 1034
- Partials 296 298 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dbwiddis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this fix! A suggestion to combine the conditionals into one.
Also need a unit test or integ test validating this new behavior, and a CHANGELOG entry.
| if (requestedUser == null || resourceUser == null) { | ||
| return false; | ||
| } | ||
| if (resourceUser.getBackendRoles() == null || requestedUser.getBackendRoles() == null) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines can probably be combined into one conditional, or maybe we can create a helper method taking varargs User... that we can iterate over and just call if (nullOrNoRoles(requestedUser, resourceUsers)) { return false; }.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbwiddis Thanks for the feedback. Sure, will take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Avinash1423 sorry for slowness with the holidays and catching up this week. I'll take a good look at this this weekend.
…ackend roles. Signed-off-by: Avinash Niyas <[email protected]>
dbwiddis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great progress, see comments below.
| private static boolean hasUsersAndRoles(User requestedUser, User resourceUser) { | ||
|
|
||
| return requestedUser != null | ||
| && resourceUser != null | ||
| && resourceUser.getBackendRoles() != null | ||
| && requestedUser.getBackendRoles() != null; | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private static boolean hasUsersAndRoles(User requestedUser, User resourceUser) { | |
| return requestedUser != null | |
| && resourceUser != null | |
| && resourceUser.getBackendRoles() != null | |
| && requestedUser.getBackendRoles() != null; | |
| } | |
| private static boolean hasUsersAndRoles(User... users) { | |
| boolean nonNull = true; | |
| for (User user: users) { | |
| if (user == null || user.getBakendRoles() == null) { | |
| nonNull = false; | |
| break; | |
| } | |
| } | |
| return nonNull; | |
| } |
Or you can possibly use a stream.
| return false; | ||
| } | ||
|
|
||
| if (!hasUsersAndRoles(requestedUser, resourceUser)) return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but given the negation we may want to make the helper method nullUsersOrRoles and reverse the true/false in it.
| return false; | ||
| } | ||
|
|
||
| // method to expose checkUserPermissions for testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to just make the existing method package private with this comment than have a wrapper method to do the same thing.
It actually wouldn't hurt to just make the method public.
| public void testCheckUserPermissionsWithNullUsers() throws Exception { | ||
|
|
||
| User mockrequestedUser = null; | ||
| User mockresourceUser = new User(); | ||
| String mockWorkFlowId = "mockWorkFlowId"; | ||
|
|
||
| boolean res = ParseUtils.exposeCheckUserPermissions(mockrequestedUser, mockresourceUser, mockWorkFlowId); | ||
|
|
||
| assertFalse(res); | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good test case but you need to test all the conditional cases (null/non-null on both requested and resource user).
| ### Features | ||
| ### Enhancements | ||
| ### Bug Fixes | ||
| - Fixed user permission validation to correctly handle null users and backend roles. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the format of our change log entries (see the release notes for where they eventually go) and add a blank line after this so the markdown properly renders.
Fix for #1201
Discription:
Added null Check for checkUserPermissions and moved isAdmin() to be executed prior to the checkUserPermissions().