mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-03-13 02:18:16 +01:00
Refactor permission variable names (#3457)
## Refactor: Improve clarity of permission variable names Renamed confusing `can[Action]` boolean variables to `prevent[Action]` (e.g., `canPrint` -> `preventPrinting`) in `PasswordController.java`, `AddPasswordRequest.java`, and `add-password.html`. The previous `can[Action]` convention was misleading, as `true` meant the action was *disallowed*. The new `prevent[Action]` naming directly reflects the intent (`true` = prevented), improving code clarity. **Changes:** * Updated variable names in controller logic * Updated `@Schema` descriptions in `AddPasswordRequest.java` * Updated corresponding HTML element attributes (`id`, `name`, `for`) in `add-password.html` **Important Notes:** * The underlying logic still inverts the boolean when setting permissions (e.g., `AccessPermission.setCanPrint(!preventPrinting)`). * User-facing UI text remains unchanged per request of @Frooodle in #3420. **Why not invert the API logic** * Inverting API (to can[action] logic) would either invalidate the UI * Inverting API AND changing UI would warrant bigger translation effort to change it in all languages * This version is consistent (meaning what the UI says is actually done) and preserve the UI language (meaning no translations needed) however it is inconsistent with PDFBox methods naming scheme **PDFBox** * **PDFBox Interaction:** This refactor addresses the naming *within* Stirling-PDF's API and Front-end layers only. The controller logic intentionally inverts the `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 the `can[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 - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
This commit is contained in:
@@ -180,14 +180,15 @@ public class AnalysisController {
|
||||
|
||||
// Get permissions
|
||||
Map<String, Boolean> permissions = new HashMap<>();
|
||||
permissions.put("canPrint", document.getCurrentAccessPermission().canPrint());
|
||||
permissions.put("canModify", document.getCurrentAccessPermission().canModify());
|
||||
permissions.put("preventPrinting", !document.getCurrentAccessPermission().canPrint());
|
||||
permissions.put(
|
||||
"canExtractContent",
|
||||
document.getCurrentAccessPermission().canExtractContent());
|
||||
"preventModify", !document.getCurrentAccessPermission().canModify());
|
||||
permissions.put(
|
||||
"canModifyAnnotations",
|
||||
document.getCurrentAccessPermission().canModifyAnnotations());
|
||||
"preventExtractContent",
|
||||
!document.getCurrentAccessPermission().canExtractContent());
|
||||
permissions.put(
|
||||
"preventModifyAnnotations",
|
||||
!document.getCurrentAccessPermission().canModifyAnnotations());
|
||||
|
||||
securityInfo.put("permissions", permissions);
|
||||
} else {
|
||||
|
||||
@@ -622,8 +622,8 @@ public class GetInfoOnPDF {
|
||||
permissionsNode.put("Document Assembly", getPermissionState(ap.canAssembleDocument()));
|
||||
permissionsNode.put("Extracting Content", getPermissionState(ap.canExtractContent()));
|
||||
permissionsNode.put(
|
||||
"Extracting for accessibility",
|
||||
getPermissionState(ap.canExtractForAccessibility()));
|
||||
"Extracting for accessibility",
|
||||
getPermissionState(ap.canExtractForAccessibility()));
|
||||
permissionsNode.put("Form Filling", getPermissionState(ap.canFillInForm()));
|
||||
permissionsNode.put("Modifying", getPermissionState(ap.canModify()));
|
||||
permissionsNode.put("Modifying annotations", getPermissionState(ap.canModifyAnnotations()));
|
||||
|
||||
@@ -63,25 +63,25 @@ public class PasswordController {
|
||||
String ownerPassword = request.getOwnerPassword();
|
||||
String password = request.getPassword();
|
||||
int keyLength = request.getKeyLength();
|
||||
boolean canAssembleDocument = request.isCanAssembleDocument();
|
||||
boolean canExtractContent = request.isCanExtractContent();
|
||||
boolean canExtractForAccessibility = request.isCanExtractForAccessibility();
|
||||
boolean canFillInForm = request.isCanFillInForm();
|
||||
boolean canModify = request.isCanModify();
|
||||
boolean canModifyAnnotations = request.isCanModifyAnnotations();
|
||||
boolean canPrint = request.isCanPrint();
|
||||
boolean canPrintFaithful = request.isCanPrintFaithful();
|
||||
boolean preventAssembly = request.isPreventAssembly();
|
||||
boolean preventExtractContent = request.isPreventExtractContent();
|
||||
boolean preventExtractForAccessibility = request.isPreventExtractForAccessibility();
|
||||
boolean preventFillInForm = request.isPreventFillInForm();
|
||||
boolean preventModify = request.isPreventModify();
|
||||
boolean preventModifyAnnotations = request.isPreventModifyAnnotations();
|
||||
boolean preventPrinting = request.isPreventPrinting();
|
||||
boolean preventPrintingFaithful = request.isPreventPrintingFaithful();
|
||||
|
||||
PDDocument document = pdfDocumentFactory.load(fileInput);
|
||||
AccessPermission ap = new AccessPermission();
|
||||
ap.setCanAssembleDocument(!canAssembleDocument);
|
||||
ap.setCanExtractContent(!canExtractContent);
|
||||
ap.setCanExtractForAccessibility(!canExtractForAccessibility);
|
||||
ap.setCanFillInForm(!canFillInForm);
|
||||
ap.setCanModify(!canModify);
|
||||
ap.setCanModifyAnnotations(!canModifyAnnotations);
|
||||
ap.setCanPrint(!canPrint);
|
||||
ap.setCanPrintFaithful(!canPrintFaithful);
|
||||
ap.setCanAssembleDocument(!preventAssembly);
|
||||
ap.setCanExtractContent(!preventExtractContent);
|
||||
ap.setCanExtractForAccessibility(!preventExtractForAccessibility);
|
||||
ap.setCanFillInForm(!preventFillInForm);
|
||||
ap.setCanModify(!preventModify);
|
||||
ap.setCanModifyAnnotations(!preventModifyAnnotations);
|
||||
ap.setCanPrint(!preventPrinting);
|
||||
ap.setCanPrintFaithful(!preventPrintingFaithful);
|
||||
StandardProtectionPolicy spp = new StandardProtectionPolicy(ownerPassword, password, ap);
|
||||
|
||||
if (!"".equals(ownerPassword) || !"".equals(password)) {
|
||||
|
||||
@@ -29,31 +29,29 @@ public class AddPasswordRequest extends PDFFile {
|
||||
defaultValue = "256")
|
||||
private int keyLength = 256;
|
||||
|
||||
@Schema(description = "Whether the document assembly is allowed", example = "false")
|
||||
private boolean canAssembleDocument;
|
||||
@Schema(description = "Whether document assembly is prevented", example = "false")
|
||||
private boolean preventAssembly;
|
||||
|
||||
@Schema(description = "Whether content extraction is prevented", example = "false")
|
||||
private boolean preventExtractContent;
|
||||
|
||||
@Schema(
|
||||
description = "Whether content extraction for accessibility is allowed",
|
||||
description = "Whether content extraction for accessibility is prevented",
|
||||
example = "false")
|
||||
private boolean canExtractContent;
|
||||
private boolean preventExtractForAccessibility;
|
||||
|
||||
@Schema(
|
||||
description = "Whether content extraction for accessibility is allowed",
|
||||
example = "false")
|
||||
private boolean canExtractForAccessibility;
|
||||
@Schema(description = "Whether form filling is prevented", example = "false")
|
||||
private boolean preventFillInForm;
|
||||
|
||||
@Schema(description = "Whether form filling is allowed", example = "false")
|
||||
private boolean canFillInForm;
|
||||
@Schema(description = "Whether document modification is prevented", example = "false")
|
||||
private boolean preventModify;
|
||||
|
||||
@Schema(description = "Whether the document modification is allowed", example = "false")
|
||||
private boolean canModify;
|
||||
@Schema(description = "Whether modification of annotations is prevented", example = "false")
|
||||
private boolean preventModifyAnnotations;
|
||||
|
||||
@Schema(description = "Whether modification of annotations is allowed", example = "false")
|
||||
private boolean canModifyAnnotations;
|
||||
@Schema(description = "Whether printing of the document is prevented", example = "false")
|
||||
private boolean preventPrinting;
|
||||
|
||||
@Schema(description = "Whether printing of the document is allowed", example = "false")
|
||||
private boolean canPrint;
|
||||
|
||||
@Schema(description = "Whether faithful printing is allowed", example = "false")
|
||||
private boolean canPrintFaithful;
|
||||
@Schema(description = "Whether faithful printing is prevented", example = "false")
|
||||
private boolean preventPrintingFaithful;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user