Skip to content

Avoid naming dialog nodes and IPE nodes 'config' (Rockstart 2019 OakPAL Interactive Demo)

Mark Adamcin edited this page Mar 25, 2019 · 1 revision

It is easy for developers to miss this simple cause for inconsistent behavior for IPEs and dialogs, where developers and admin users see correct behavior, but authors and other non-admin users see incorrect behavior.

This is actually documented as a Known Limitation of the Rich Text editor, but it really applies to any nodes named config that contribute to the authoring UI.

This simple text component cq:editConfig demonstrates the issue when the child of cq:inplaceEditing is named config:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:primaryType="cq:EditConfig">
    <cq:inplaceEditing
        jcr:primaryType="cq:InplaceEditingConfig"
        active="{Boolean}true"
        editorType="text">
        <config jcr:primaryType="nt:unstructured">
            <rtePlugins jcr:primaryType="nt:unstructured">
                <links
                    jcr:primaryType="nt:unstructured"
                    features="-"/>
                <lists
                    jcr:primaryType="nt:unstructured"
                    enableLists="{Boolean}false"
                    features="-"/>
                <justify
                    jcr:primaryType="nt:unstructured"
                    features="-"/>
                <format
                    jcr:primaryType="nt:unstructured"
                    features="bold"/>
            </rtePlugins>
        </config>
    </cq:inplaceEditing>
</jcr:root>

When a developer uses the in-place editor mode for the component, he or she sees the desired minimal set of features in the toolbar.

When an author use the same component in in-place editing mode, he or she sees the DEFAULT set of features in the toolbar, because they are denied the read permission on the config node and its children by the OOTB ACE that protects OSGi configs.

This simple script check will flag any descendants of cq:Component nodes that are named config to indicate that they should be renamed.

/**
 * Notified when package importer adds, modifies, or leaves a node untouched.
 *
 * @param packageId         the current package
 * @param path              the imported path
 * @param node              the imported JCR node
 */
function importedPath(packageId /* PackageId */, path /* String */, node /* Node */) {
    if (path.startsWith("/apps/") && node.getName() === "config" && isComponent(node)) {
        oakpal.majorViolation(path + ": avoid naming dialog nodes 'config'", packageId);
    }
}

function isComponent(node) {
    return node.isNodeType("cq:Component") || (node.getDepth() > 0 && isComponent(node.getParent()));
}