Reputation: 560
Am trying to Hide some tabs in AEM Page Properties dialog.
However i can hide my custom tabs using rep:policy. but, How to hide OOTB personalization tab in page properties of a page for non admin users in AEM?
Upvotes: 1
Views: 682
Reputation: 2021
If you do not want to do overlay which is always an overhead then you can do the followings :
Write a servet to check user is admin or not
@Component(name = "com.aem.showcase.core.impl.AdminUserCheck",
service = Servlet.class, property = {
"service.description=Admin user check",
"sling.servlet.methods=GET",
"sling.servlet.paths=/bin/isadminuser" })
public class AdminUserCheck extends SlingSafeMethodsServlet{
protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("application/json");
resp.setCharacterEncoding("utf-8");
Session session = request.getResourceResolver().adaptTo(Session.class);
boolean isAdmin = Boolean.FALSE;
UserManager um;
try {
um = AccessControlUtil.getUserManager(session);
User currentUser = (User) um.getAuthorizable(session.getUserID());
isAdmin = currentUser.isAdmin();
JSONWriter jsonWriter = new JSONWriter(resp.getWriter());
jsonWriter.object();
jsonWriter.key("isadmin").value(isAdmin);
jsonWriter.endObject();
} catch (RepositoryException | JSONException e) {
e.printStackTrace();
}
}
}
Create a clientlibs under /apps/your-project/and add categorisation as “cq.personalization.wizard“
Add the below code
(function ($) {
'use strict';
$.getJSON('/bin/isadminuser',
function(data) {
if(!data.isadmin){
$( "coral-tab-label" ).each( function( index, element ){
if($( this ).html() === 'Personalization'){
$( this ).closest("coral-tab").hide();
}
});
}
});
}(jQuery));
Finally add extraClintLibs property to your page which is "cq.personalization.wizard". You need to add this under your project structure, I am taking we-retail as an example : /apps/weretail/components/structure/page/cq:dialog
Upvotes: 0
Reputation: 9753
This is an excellent use-case for Granite Render Conditions. I explained how they work and have an example and some resources in this blog.
using an ACL policy won’t work here, because even if you overlay the tab, the sling resource merger will still find the tab under /libs.
So here are the steps you need to do:
I think this should very straightforward. but if you’d like a working example, I can provide one today/tomorrow.
Upvotes: 2