Skip to content

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,15 @@ public Map<String, Object> getSecurityInfo(@ModelAttribute PDFFile file) throws

// 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,19 +619,20 @@ public ResponseEntity<byte[]> getPdfInfo(@ModelAttribute PDFFile request) throws
private void setNodePermissions(PDDocument pdfBoxDoc, ObjectNode permissionsNode) {
AccessPermission ap = pdfBoxDoc.getCurrentAccessPermission();

permissionsNode.put("Document Assembly", getPermissionState(ap.canAssembleDocument()));
permissionsNode.put("Extracting Content", getPermissionState(ap.canExtractContent()));
permissionsNode.put("Document Assembly", getPermissionState(!ap.canAssembleDocument()));
permissionsNode.put("Extracting Content", getPermissionState(!ap.canExtractContent()));
permissionsNode.put(
"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()));
permissionsNode.put("Printing", getPermissionState(ap.canPrint()));
getPermissionState(!ap.canExtractForAccessibility()));
permissionsNode.put("Form Filling", getPermissionState(!ap.canFillInForm()));
permissionsNode.put("Modifying", getPermissionState(!ap.canModify()));
permissionsNode.put(
"Modifying annotations", getPermissionState(!ap.canModifyAnnotations()));
permissionsNode.put("Printing", getPermissionState(!ap.canPrint()));
}

private String getPermissionState(boolean state) {
return state ? "Allowed" : "Not Allowed";
return state ? "Prevented" : "Allowed";
}

public String getPageOrientation(double width, double height) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,25 @@ public ResponseEntity<byte[]> addPassword(@ModelAttribute AddPasswordRequest req
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 for accessibility is allowed",
example = "false")
private boolean canExtractContent;
@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 canExtractForAccessibility;
private boolean preventExtractForAccessibility;

@Schema(description = "Whether form filling is allowed", example = "false")
private boolean canFillInForm;
@Schema(description = "Whether form filling is prevented", example = "false")
private boolean preventFillInForm;

@Schema(description = "Whether the document modification is allowed", example = "false")
private boolean canModify;
@Schema(description = "Whether document modification is prevented", example = "false")
private boolean preventModify;

@Schema(description = "Whether modification of annotations is allowed", example = "false")
private boolean canModifyAnnotations;
@Schema(description = "Whether modification of annotations is prevented", example = "false")
private boolean preventModifyAnnotations;

@Schema(description = "Whether printing of the document is allowed", example = "false")
private boolean canPrint;
@Schema(description = "Whether printing of the document is prevented", example = "false")
private boolean preventPrinting;

@Schema(description = "Whether faithful printing is allowed", example = "false")
private boolean canPrintFaithful;
@Schema(description = "Whether faithful printing is prevented", example = "false")
private boolean preventPrintingFaithful;
}
32 changes: 16 additions & 16 deletions src/main/resources/templates/security/add-password.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,36 @@
<div class="mb-3">
<label class="mb-2" th:text="#{addPassword.selectText.5}"></label>
<div class="form-check ms-3">
<input type="checkbox" id="canAssembleDocument" name="canAssembleDocument">
<label for="canAssembleDocument" th:text="#{addPassword.selectText.6}"></label>
<input type="checkbox" id="preventAssembly" name="preventAssembly">
<label for="preventAssembly" th:text="#{addPassword.selectText.6}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canExtractContent" name="canExtractContent">
<label for="canExtractContent" th:text="#{addPassword.selectText.7}"></label>
<input type="checkbox" id="preventExtractContent" name="preventExtractContent">
<label for="preventExtractContent" th:text="#{addPassword.selectText.7}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canExtractForAccessibility" name="canExtractForAccessibility">
<label for="canExtractForAccessibility" th:text="#{addPassword.selectText.8}"></label>
<input type="checkbox" id="preventExtractForAccessibility" name="preventExtractForAccessibility">
<label for="preventExtractForAccessibility" th:text="#{addPassword.selectText.8}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canFillInForm" name="canFillInForm">
<label for="canFillInForm" th:text="#{addPassword.selectText.9}"></label>
<input type="checkbox" id="preventFillInForm" name="preventFillInForm">
<label for="preventFillInForm" th:text="#{addPassword.selectText.9}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canModify" name="canModify">
<label for="canModify" th:text="#{addPassword.selectText.10}"></label>
<input type="checkbox" id="preventModify" name="preventModify">
<label for="preventModify" th:text="#{addPassword.selectText.10}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canModifyAnnotations" name="canModifyAnnotations">
<label for="canModifyAnnotations" th:text="#{addPassword.selectText.11}"></label>
<input type="checkbox" id="preventModifyAnnotations" name="preventModifyAnnotations">
<label for="preventModifyAnnotations" th:text="#{addPassword.selectText.11}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canPrint" name="canPrint">
<label for="canPrint" th:text="#{addPassword.selectText.12}"></label>
<input type="checkbox" id="preventPrinting" name="preventPrinting">
<label for="preventPrinting" th:text="#{addPassword.selectText.12}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canPrintFaithful" name="canPrintFaithful">
<label for="canPrintFaithful" th:text="#{addPassword.selectText.13}"></label>
<input type="checkbox" id="preventPrintingFaithful" name="preventPrintingFaithful">
<label for="preventPrintingFaithful" th:text="#{addPassword.selectText.13}"></label>
</div>
</div>
<br>
Expand Down
32 changes: 16 additions & 16 deletions src/main/resources/templates/security/change-permissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@
<div class="mb-3">
<label class="mb-2" th:text="#{permissions.selectText.2}"></label>
<div class="form-check ms-3">
<input type="checkbox" id="canAssembleDocument" name="canAssembleDocument">
<label for="canAssembleDocument" th:text="#{permissions.selectText.3}"></label>
<input type="checkbox" id="preventAssembly" name="preventAssembly">
<label for="preventAssembly" th:text="#{permissions.selectText.3}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canExtractContent" name="canExtractContent">
<label for="canExtractContent" th:text="#{permissions.selectText.4}"></label>
<input type="checkbox" id="preventExtractContent" name="preventExtractContent">
<label for="preventExtractContent" th:text="#{permissions.selectText.4}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canExtractForAccessibility" name="canExtractForAccessibility">
<label for="canExtractForAccessibility" th:text="#{permissions.selectText.5}"></label>
<input type="checkbox" id="preventExtractForAccessibility" name="preventExtractForAccessibility">
<label for="preventExtractForAccessibility" th:text="#{permissions.selectText.5}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canFillInForm" name="canFillInForm">
<label for="canFillInForm" th:text="#{permissions.selectText.6}"></label>
<input type="checkbox" id="preventFillInForm" name="preventFillInForm">
<label for="preventFillInForm" th:text="#{permissions.selectText.6}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canModify" name="canModify">
<label for="canModify" th:text="#{permissions.selectText.7}"></label>
<input type="checkbox" id="preventModify" name="preventModify">
<label for="preventModify" th:text="#{permissions.selectText.7}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canModifyAnnotations" name="canModifyAnnotations">
<label for="canModifyAnnotations" th:text="#{permissions.selectText.8}"></label>
<input type="checkbox" id="preventModifyAnnotations" name="preventModifyAnnotations">
<label for="preventModifyAnnotations" th:text="#{permissions.selectText.8}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canPrint" name="canPrint">
<label for="canPrint" th:text="#{permissions.selectText.9}"></label>
<input type="checkbox" id="preventPrinting" name="preventPrinting">
<label for="preventPrinting" th:text="#{permissions.selectText.9}"></label>
</div>
<div class="form-check ms-3">
<input type="checkbox" id="canPrintFaithful" name="canPrintFaithful">
<label for="canPrintFaithful" th:text="#{permissions.selectText.10}"></label>
<input type="checkbox" id="preventPrintingFaithful" name="preventPrintingFaithful">
<label for="preventPrintingFaithful" th:text="#{permissions.selectText.10}"></label>
</div>
</div>
<br>
Expand Down