AEM 6 - Classic UI Disable Set Password

Goal


Disable Set Password if a user doesn't have necessary permissions. Without this extension a user will still not be able to change the password if he doesnt have necessary permissions, but user can click on Set Password button and the dialog shows up giving user impression that he/she can change password

Demo | Package Install

If a user doesn't have necessary permissions (here user author doesn't have modify permission on node /home/users/geometrixx/author which stores user password )...




Set Password disabled for author




Solution


1) Login to CRXDE Lite (http://localhost:4502/crx/de) and create folder /apps/classic-ui-disable-set-password

2) Create node /apps/classic-ui-disable-set-password/clientlib of type cq:ClientLibraryFolder and add a String property categories with value cq.security

3) Create file (nt:file) /apps/classic-ui-disable-set-password/clientlib/js.txt and add

                       disable.js

4) Create file (nt:file) /apps/classic-ui-disable-set-password/clientlib/disable.js and add the following code.

(function(){
    //id set in \libs\cq\security\widgets\source\widgets\security\UserAdmin.js
    var USER_ADMIN_ID = "cq-useradmin";

    if(window.location.pathname == "/useradmin"){
        var UA_INTERVAL = setInterval(function(){
            var userAdmin = CQ.Ext.getCmp(USER_ADMIN_ID);

            if(userAdmin && userAdmin.userProperties && userAdmin.userProperties.pwdButtons){
                clearInterval(UA_INTERVAL);

                var pwdButtons = userAdmin.userProperties.pwdButtons;
                var setPassword = pwdButtons.filter("text", "Set Password").get(0);
                var authorizableList = userAdmin.list;

                authorizableList.getSelectionModel().on('selectionchange', function(sm){
                    var selected = sm.getSelected();

                    if(!selected){
                        return;
                    }

                    //var hasPerm = CQ.User.getCurrentUser().hasPermissionOn("modify", selected.data.home);

                    var user = CQ.User.getCurrentUser();

                    setPassword.setDisabled(true);

                    $.ajax({
                        url: "/.cqactions.json",
                        data: {
                            path: selected.data.home,
                            authorizableId: user.getUserID()
                        }
                    }).done(function(data){
                        setPassword.setDisabled(!data.entries[0].modify);
                    });
                });
            }
        }, 250);
    }
})();




No comments:

Post a Comment