Fix readonly mode triggering permission denied error in FormMeta - #5001
Conversation
maxpatiiuk
left a comment
There was a problem hiding this comment.
hmm, could you please explain what was causing the bug and why this fixes it?
it's hard without any context to know if this is a good fix or not.
i.e is there an issue with this particular check in this one place, or is it a more systematic failure that could affect all such checks anywhere in the codebase?
and what change lead to this error to start appearing where as it did not before?
|
@maxpatiiuk My bad, forgot to add my notes here. NOTES: specify7/specifyweb/frontend/js_src/lib/components/FormMeta/index.tsx Lines 221 to 228 in b62a79b When readonly mode is enabled, the user no longer has update permissions on the table and so we see the permission denied error. With my change, we still check for table permission but simply don't render the merge record button when the form is readonly (or if the user has no permission) |
melton-jason
left a comment
There was a problem hiding this comment.
While this does fix the issue in this case, the ProtectedTable would still cause the error dialog in another case: when viewing any LoanPreparation Query.
Is this intended? I would instead think disabling or hiding the button in this case would be more user-friendly (rather than make the query completely non-functional in ReadOnly Mode)
Screen.Recording.2024-06-13.at.11.00.50.AM.mov
specify7/specifyweb/frontend/js_src/lib/components/QueryBuilder/Header.tsx
Lines 112 to 128 in bb328a3
This raises questions about the general behavior of permissions in Specify, especially relating to tools such as these. I don't think that raising an error in these cases is ever helpful (at least in the current state. It would be better if the Error Dialog was dismissible).
In these cases, I would imagine the intended behavior is to either disable the tool/button, or not render it in the first place.
In my opinion, raising the error dialog should only occur when the user explicitly tries to do something against their permissions, such as navigating to a form they don't have read access to. Small tools/buttons such as the Enable Read Only Mode or Return Loan Records buttons are already in the Interface while the user is trying to accomplish another task entirely.
In the case of Return Loan Records in the QueryBuilder, the user is likely there to Query on records rather than Return the Loans Preparations, so violating the table create permission should be approached with less severity/notice to the user.
We already hide the button without raising an error in the InteractionsDialog.
Also, I would think the Dismiss button on the Permission Denied Dialog redirecting the user back to the home page is unintentional.
|
@melton-jason I agree that permission denied should only be shown when the user actively attempts to do something against their permissions. I think the |
|
Thank you for the details
Yeah, ideally the permission denied dialog would only be shown in two cases:
Given the above, I think we should try to follow this rule:
If we are careful about where we use function check and where we use the component check, most issues with readonly should be resolved. If that is not enough however, we could add a check inside the component check to not display an error dialog if user is in readonly mode Given the above, it becomes more clear that the use of Protected component checks for a button is incorrect - permission function check should be used instead. As far as the other places were permission checks are used, it would be great if someone could check them (maybe one of the student programmers), though that would have to be compared to the other priorities |
melton-jason
left a comment
There was a problem hiding this comment.
I agree with #5001 (comment) in that we should also go through the other uses of the Protected components (ProtectedAction, ProtectedTool, ProtectedTable) and the hasPermission functions to ensure no other error like this is present.
It would be a great exercise for another student developer!
Also from #5001 (review)
Also, I would think the
Dismissbutton on the Permission Denied Dialog redirecting the user back to the home page is unintentional.
I would imagine this is a bug.
Although neither of these Issues likely have to be resolved in this PR: the PR might become too big, and testing instructions would be a nightmare! (As well as keep potential merge conflicts to a minimum).
This smaller scope works for now. Nice changes!
emenslin
left a comment
There was a problem hiding this comment.
Testing instructions
- Go to any pre-existing form (e.g. Collection Object)
- Click on the form meta button in the top right
- Click on 'Enable Read-Only Mode'
- Click on form meta again
- Verify there is no permission denied error and read only mode can be disabled again
- Re-run the same steps for a form with merge records enabled (Agent, Locality, PaleoContext, CollectingEvent)
Additional test:
- In Readonly mode, make a query on LoanPreparation
- Verify the page loads correctly and there is no permission denied error dialog
Looks good, I did not run into any other errors with read only
Areyes42
left a comment
There was a problem hiding this comment.
Testing instructions
- Go to any pre-existing form (e.g. Collection Object)
- Click on the form meta button in the top right
- Click on 'Enable Read-Only Mode'
- Click on form meta again
- Verify there is no permission denied error and read only mode can be disabled again
- Re-run the same steps for a form with merge records enabled (Agent, Locality, PaleoContext, CollectingEvent)
Additional test:
- In Readonly mode, make a query on LoanPreparation
- Verify the page loads correctly and there is no permission denied error dialog
Looks good now, no longer throwing error dialogs
lexiclevenger
left a comment
There was a problem hiding this comment.
Testing instructions
- Go to any pre-existing form (e.g. Collection Object)
- Click on the form meta button in the top right
- Click on 'Enable Read-Only Mode'
- Click on form meta again
- Verify there is no permission denied error and read only mode can be disabled again
- Re-run the same steps for a form with merge records enabled (Agent, Locality, PaleoContext, CollectingEvent)
Additional test:
- In Readonly mode, make a query on LoanPreparation
- Verify the page loads correctly and there is no permission denied error dialog
Looks good!
Screen.Recording.2024-06-14.at.2.07.43.PM.mov
I tested querying for Loan Preparations and some other tables with no issue.
Fixes #4997
Checklist
and self-explanatory (or properly documented)
Testing instructions
Additional test: