Skip to content

Commit

Permalink
failing exports to HTML or PDF for when non-public nodes encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
Clay-Ferguson committed Dec 14, 2024
1 parent 35ab9f0 commit 0ada93c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
16 changes: 12 additions & 4 deletions src/main/java/quanta/service/exports/ExportArchiveBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,20 @@ public String export(String nodeId) {
}

Criteria criteria = null;
if (publishing) {
criteria = Criteria.where(SubNode.AC + "." + PrincipalName.PUBLIC.s()).ne(null);
}

/*
* NOTE: I decided to query ALL nodes, and we'll throw an exception if any are not public, this way
* the user knows that the export failed because of a non-public node. This is better than silently
* skipping non-public, and we do this check in preProcessTree() method.
*/
// if (publishing) {
// criteria = Criteria.where(SubNode.AC + "." + PrincipalName.PUBLIC.s()).ne(null);
// }

TreeNode rootNode = svc_mongoRead.getSubGraphTree(nodeId, criteria, null, null);
figNumStart = ExportUtil.prePocessTree(treeItemsByNodeName, figNumStart, rootNode);

boolean requirePublic = publishing || contentType.equals("html");
figNumStart = ExportUtil.prePocessTree(treeItemsByNodeName, figNumStart, rootNode, requirePublic);
node = rootNode.node;
baseSlashCount = StringUtils.countMatches(node.getPath(), "/");

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/quanta/service/exports/ExportServicePDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void exportNodeToFile(String nodeId) {
TreeNode rootNode = req.isThreadAsPDF() ? svc_mongoRead.getThreadGraphTree(nodeId) : //
svc_mongoRead.getSubGraphTree(nodeId, null, null, null);

figNumStart = ExportUtil.prePocessTree(treeItemsByNodeName, figNumStart, rootNode);
figNumStart = ExportUtil.prePocessTree(treeItemsByNodeName, figNumStart, rootNode, true);

SubNode exportNode = rootNode.node;
String fileName = svc_snUtil.getExportFileName(req.getFileName(), exportNode);
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/quanta/util/ExportUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import quanta.exception.MessageException;
import quanta.model.TreeNode;
import quanta.service.AclService;

public class ExportUtil {
private static Logger log = LoggerFactory.getLogger(ExportUtil.class);
Expand Down Expand Up @@ -54,7 +56,14 @@ public static String injectFigureLinks(HashMap<String, TreeNode> treeItemsByNode

// This method is used to pre-process the tree and set the figNumStart for each node
// and returns the current global figNumStart.
public static int prePocessTree(HashMap<String, TreeNode> treeItemsByNodeName, int figNumStart, TreeNode root) {
public static int prePocessTree(HashMap<String, TreeNode> treeItemsByNodeName, int figNumStart, TreeNode root,
boolean requirePublic) {
// if we're publishing and this node is NOT public then throw exception
if (requirePublic && !AclService.isPublic(root.node)) {
throw new MessageException(
"This export checks for only public nodes. This node is not public: " + root.node.getIdStr());
}

if (root.node.getAttachments() != null && root.node.getAttachments().size() > 0) {
root.figNumStart = figNumStart;
figNumStart += root.node.getAttachments().size();
Expand All @@ -73,7 +82,7 @@ public static int prePocessTree(HashMap<String, TreeNode> treeItemsByNodeName, i
return figNumStart;

for (TreeNode c : root.children) {
figNumStart = prePocessTree(treeItemsByNodeName, figNumStart, c);
figNumStart = prePocessTree(treeItemsByNodeName, figNumStart, c, requirePublic);
}
return figNumStart;
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/public/src/RpcUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ export class RpcUtil {
reject({ response: res });
S.util.showMessage("Content not visible to you.", "Message");
}
else if (res.status !== C.RESPONSE_CODE_OK) {
console.log("reject: res: " + S.util.prettyPrint(res) + " PATH=" + this.getRpcPath() + postName + " Bearer: " + S.quanta.authToken);
reject({ response: res });
}
else if (res.status === C.RESPONSE_CODE_SEE_OTHER) {
console.error("Message Error: " + postName + " RES: " + res);
reject({ response: res });
}
else if (res.status !== C.RESPONSE_CODE_OK) {
console.log("reject: res: " + S.util.prettyPrint(res) + " PATH=" + this.getRpcPath() + postName + " Bearer: " + S.quanta.authToken);
reject({ response: res });
}
else {
return res.text();
}
Expand Down Expand Up @@ -336,6 +336,7 @@ export class RpcUtil {
// AccountNode, and then open ConfigurAIDlg with that node. (todo-1)
// }
// else {
(res as any).errorShown = true;
S.util.showMessage(res.message, "Message");
// }
return;
Expand Down

0 comments on commit 0ada93c

Please sign in to comment.