Expand my Community achievements bar.

Restrict Page Creation Based on Condition

Avatar

Community Advisor

Hello,
I have a requirement to restrict page creation based on some conditions.

For Example,
When an author wants to create a page I need to check some validity from my Java code

Sady_Rifat_0-1681713494259.png

As soon as I found anything wrong I need to restrict the author from creating the page and show some error. (This error could be the exception message).

 

For this, I tried implementing EventListener, but Event is triggered after the page creation.

public JackrabbitEventFilter createPageEvent (String path) {
        JackrabbitEventFilter jackrabbitEventFilterPage = new JackrabbitEventFilter();

        return jackrabbitEventFilterPage.setAbsPath(path)
                .setEventTypes(Event.NODE_ADDED)
                .setIsDeep(true)
                .setNodeTypes(new String[]{NT_PAGE, NT_TAG});
    }

In the OnEvent I throw an exception,

@Override
public void onEvent(EventIterator events) {
    throw new AccessControlException("Restricted");
    // Or any kind of exception
}

But this is not working. 

How I can achieve this?
Note: I also need to get the page properties that are filled up by the author.

2 Replies

Avatar

Community Advisor

@Sady_Rifat :Instead of writing the event listener .Can you try below. 

 

in the create page wizard, the below validation happens from the below validations.js file . You can write your validation in the below JS file.

 

JS file location: /libs/cq/gui/components/siteadmin/admin/clientlibs/validations/js/validations.js

 

 

SivakumarKanoori_0-1681718511843.png

 

SO its better to overlay and customize this js file instead of writing event listener.

 

Thanks,
Siva

Avatar

Community Advisor

Using clientlib is possible. But the requirement is to use Java directly. If it's not possible to solve by Java directly then I will go for the clientlib solution.