Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to hide/disable "Add Comment" section in Asset Timeline

Avatar

Level 3

I have a required to hide/disable comment section in the asset timeline for a particular user group? Any advice on how can this be achieved?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

One of the ways to customise this would be to :

1. Get the current userGroups and check if they fall in the group for which commenting should not be allowed. Lets, assume the variable as isUnallowedUg.

function getLoggedInUserID() {
    var currentUserId = "";
    var currentUserInfo;
    var CURRENT_USER_JSON_PATH = Granite.HTTP.externalize('/libs/granite/security/currentuser.json');
    var result = Granite.$.ajax({
        type: "GET",
        async: false,
        url: CURRENT_USER_JSON_PATH
    });

    if (result.status === 200) {
        currentUserInfo = JSON.parse(result.responseText);
        currentUserId = currentUserInfo.authorizableId;
    }
    return currentUserId;
}





function getUserGroups(userID)
    var isMemberOfGroupEveryOne=false;

    $.ajax({
        url: "/bin/security/authorizables.json?filter=" + userID +'&_charset_=utf-8',
        async: false,
        success: function(result) {
            if (result) {
                $.each(result.authorizables,function(index,authObj){
                    if( (authObj.id !== userID)){
                        return;
                    }else {

                        $.each(authObj.memberOf,function(index,memberOf){
                            if(memberOf.id === 'everyone'){
                                isMemberOfGroupEveryOne=true;
                            }
                        });
                    }
                });
            }
        }
    });
    return isMemberOfGroupEveryOne;
}

I have used everyone for demo, you could use your custom group.

2. if isUnallowedUg is true, you would be hiding the class cq-common-admin-timeline-toolbar using display: none in CSS.

Hope this helps, thanks!

View solution in original post

3 Replies

Avatar

Community Advisor

You can add a Deny Access Control Policy rule with jcr:read privilege on this node

 

/libs/wcm/core/content/sites/jcr:content/rails/timeline/items/timeline/items/toolbar/actions/createcomment

Avatar

Correct answer by
Employee Advisor

One of the ways to customise this would be to :

1. Get the current userGroups and check if they fall in the group for which commenting should not be allowed. Lets, assume the variable as isUnallowedUg.

function getLoggedInUserID() {
    var currentUserId = "";
    var currentUserInfo;
    var CURRENT_USER_JSON_PATH = Granite.HTTP.externalize('/libs/granite/security/currentuser.json');
    var result = Granite.$.ajax({
        type: "GET",
        async: false,
        url: CURRENT_USER_JSON_PATH
    });

    if (result.status === 200) {
        currentUserInfo = JSON.parse(result.responseText);
        currentUserId = currentUserInfo.authorizableId;
    }
    return currentUserId;
}





function getUserGroups(userID)
    var isMemberOfGroupEveryOne=false;

    $.ajax({
        url: "/bin/security/authorizables.json?filter=" + userID +'&_charset_=utf-8',
        async: false,
        success: function(result) {
            if (result) {
                $.each(result.authorizables,function(index,authObj){
                    if( (authObj.id !== userID)){
                        return;
                    }else {

                        $.each(authObj.memberOf,function(index,memberOf){
                            if(memberOf.id === 'everyone'){
                                isMemberOfGroupEveryOne=true;
                            }
                        });
                    }
                });
            }
        }
    });
    return isMemberOfGroupEveryOne;
}

I have used everyone for demo, you could use your custom group.

2. if isUnallowedUg is true, you would be hiding the class cq-common-admin-timeline-toolbar using display: none in CSS.

Hope this helps, thanks!