-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Refactor permission variable names #3457
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?
Refactor permission variable names #3457
Conversation
…github.com/Balazs-Szucs/Stirling-PDF into Fixing-logically-inverted-add-password-API
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.
Pull Request Overview
This PR refactors permission variable names to improve clarity by renaming misleading boolean variables from the "can[Action]" convention to "prevent[Action]".
- Updated HTML checkbox input attributes in add-password.html
- Renamed variables and updated @Schema descriptions in AddPasswordRequest.java
- Refactored variable names and inversion logic in PasswordController.java
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/main/resources/templates/security/add-password.html | Updated checkbox IDs and names to use the new naming scheme |
src/main/java/stirling/software/SPDF/model/api/security/AddPasswordRequest.java | Refactored boolean variable names and schema annotations |
src/main/java/stirling/software/SPDF/controller/api/security/PasswordController.java | Renamed variable references and maintained inversion logic |
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 Ludy for the suggestion! I went through the security API again, a bit more thoroughly and noticed the GetInfoOnPDF and AnalysisController also used the can[Action] so beside your suggestion I also went ahead and renamed those. I think this should address everything relevant in the codebase. |
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.
Pull Request Overview
This PR refactors permission variable names for clarity by renaming misleading boolean flags (from can[Action] to prevent[Action]) in both backend and frontend files. The key changes include updates to variable names and associated schema descriptions, inversion of booleans when interfacing with PDFBox, and renaming of HTML attribute ids and names.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/main/resources/templates/security/change-permissions.html | Updated checkbox ids/names to use the new prevent[Action] convention |
src/main/resources/templates/security/add-password.html | Updated checkbox ids/names to match the new boolean naming scheme |
src/main/java/stirling/software/SPDF/model/api/security/AddPasswordRequest.java | Renamed fields and updated @Schema annotations for clarity |
src/main/java/stirling/software/SPDF/controller/api/security/PasswordController.java | Updated permission extraction and inversion to work with the new field names |
src/main/java/stirling/software/SPDF/controller/api/security/GetInfoOnPDF.java | Adjusted JSON output to reflect inverted permission states and new terminology |
src/main/java/stirling/software/SPDF/controller/api/AnalysisController.java | Updated JSON permission keys but with one naming inconsistency noted |
Comments suppressed due to low confidence (1)
src/main/java/stirling/software/SPDF/controller/api/AnalysisController.java:182
- The key name 'preventPrint' is inconsistent with the new naming convention used elsewhere (e.g., 'preventPrinting'). Consider renaming it for consistency.
permissions.put("preventPrint", !document.getCurrentAccessPermission().canPrint());
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.
Pull Request Overview
This PR renames confusing permission variables to clarify their intent by replacing the misleading can[Action] names with prevent[Action] names, while preserving the underlying inverted logic.
- Renamed variables and updated UI element attributes in HTML templates.
- Adjusted API request classes and controller logic to reflect the new naming conventions.
- Updated the permission state reporting in API controllers to align with the renaming.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/main/resources/templates/security/change-permissions.html | Updated checkbox ids/names and corresponding label references for permission actions. |
src/main/resources/templates/security/add-password.html | Updated checkbox ids/names and corresponding label references for permission actions. |
src/main/java/stirling/software/SPDF/model/api/security/AddPasswordRequest.java | Revised Schema descriptions and variable names to improve clarity. |
src/main/java/stirling/software/SPDF/controller/api/security/PasswordController.java | Updated variable references and boolean inversions to match the new naming. |
src/main/java/stirling/software/SPDF/controller/api/security/GetInfoOnPDF.java | Adjusted boolean inversion when reporting permission states to reflect naming changes. |
src/main/java/stirling/software/SPDF/controller/api/AnalysisController.java | Revised permission mapping keys and boolean inversions in the security info API. |
Comments suppressed due to low confidence (1)
src/main/java/stirling/software/SPDF/controller/api/AnalysisController.java:183
- Ensure that the mapping of permission keys in AnalysisController (e.g., 'preventModify') is consistent with the new naming convention and with UI/API consumers' expectations across the system.
permissions.put("preventModify", !document.getCurrentAccessPermission().canModify());
src/main/java/stirling/software/SPDF/controller/api/security/GetInfoOnPDF.java
Show resolved
Hide resolved
I just recently noticed that the get-info-on-pdf endpoint seem to broken. Strangely, my hosted instance (meaning mainstream version) of Stirling also seem be broken with my "setup". Can anyone verify if I am doing something wrong, or there is more going on. As for this pull the getPermissionState is inverted, so are the !ap.can[Action] so in theory atleast this pull request didn't actually change anything logic related (2 invertion = so the end result is the same but further review and some investigation would be much appreciated. |
To elaborate on my findings: It seems no matter what PDF I feed to the get-info-on-pdf (and no matter what kind permission the PDF has) it always seem show the "default" setting which is "allowed". Might be a problem with my setup and is actually unrelated to both the pull request and the codebase, but wanted to note that just in case. |
@Balazs-Szucs can you put the get info stuff into a new issue ticket and ill investigate |
Yes, @Frooodle. My apologies for the convoluted pull request, as for get info stuff it was just me testing locally, so it still entirely possible to be on my end, but I'll make mental note to raise a separate issue for it. |
Refactor: Improve clarity of permission variable names
Renamed confusing
can[Action]
boolean variables toprevent[Action]
(e.g.,canPrint
->preventPrinting
) inPasswordController.java
,AddPasswordRequest.java
, andadd-password.html
.The previous
can[Action]
convention was misleading, astrue
meant the action was disallowed. The newprevent[Action]
naming directly reflects the intent (true
= prevented), improving code clarity.Changes:
@Schema
descriptions inAddPasswordRequest.java
id
,name
,for
) inadd-password.html
Important Notes:
AccessPermission.setCanPrint(!preventPrinting)
).Why not invert the API logic
PDFBox
prevent[Action]
boolean (ap.setCanPrint(!preventPrinting)
) to correctly interact with the underlying PDFBox methods. No further renaming related to these permissions is necessary as the PDFBox methods themselves retain thecan[Action]
names.Underlying logic is not changed so it should work but just in case I tested locally on an Adobe PDF that contained form in Chrome.
New variable names in API
Related Issues:
Closes #3427
Closes #3420
Checklist
General
Documentation
UI Changes (if applicable)
Testing (if applicable)