Tuesday, March 1, 2016

Disable Activate and Deactivate Buttons in Sidekick based on user persmission in CQ5/AEM page

1) Create a folder skdisable under /apps i.e /apps/skdisable
2) Create a clientLibs folder under skdisable i.e /apps/skdisable/clientLib
    Add below property to this folder
    categories       String     cq.widgets
3) Create a buttonsdisable.js file under clientLib folder i.e  /apps/skdisable/clientLib/buttonsdisable.js
     Add below code in the buttondisable.js

(function(){
    if( ( window.location.pathname == "/cf" ) || ( window.location.pathname.indexOf("/content") == 0)){

        var SK_INTERVAL = setInterval(function(){
            var sk = CQ.WCM.getSidekick();
            var curPage = CQ.WCM.getPagePath();
           if(CQ.User.getCurrentUser().hasPermissionOn("replicate", [CQ.WCM.getSidekick().getPath()])!=true){

            if(sk && sk.panels){
                clearInterval(SK_INTERVAL);


                        var pagePanel = sk.panels["PAGE"];

                        var buttons = pagePanel.findBy(function(comp){
                            return comp["name"] == "PUBLISH" || comp["name"] == "DEACTIVATE";
                        }, pagePanel);

                        CQ.Ext.each(buttons, function(button){
                            button.setDisabled(true);
                        });

                }

           }else{
               return;
           }

        }, 250);
    }

})();


  4)  Create a js.txt file under clientLib folder i.e  /apps/skdisable/clientLib/js.txt
       Add below line in js.txt
  
                    buttonsdisable.js

5) Now go to http://localhost:4502/useradmin , Select an user and remove replication permission for /content/geometrix site. Login with that user credentials.

6) Open any geometrix page and check sidekick,you will see Activate and Deactivate buttons disabled.




No comments:

Post a Comment