Foren

not displaying control panel portlets

Daniel Wilmes, geändert vor 12 Jahren.

not displaying control panel portlets

Regular Member Beiträge: 164 Beitrittsdatum: 23.05.11 Neueste Beiträge
I am using liferay 6.0.5 and tomcat 6.0.29 and am having a problem with my custom portlet showing up no matter what. I followed this wik (hide portlet) , but I get an error when I add

<control-panel-entry-class> com.liferay.portlet.enterpriseadmin.UsersControlPanelEntry </control-panel-entry-class>

to my liferay-portlet.xml.

I am trying to make sure my portlet to not display based on user or permission. Permissions for liferay are pretty hard to comprehend especially when you are creating a ton of custom portlets.

Thanks,
Daniel
thumbnail
Thiago Leão Moreira, geändert vor 12 Jahren.

RE: not displaying control panel portlets

Liferay Legend Beiträge: 1449 Beitrittsdatum: 10.10.07 Neueste Beiträge
The problem is that the class UsersControlPanelEntry is not available to plugins, it belongs to the Liferay core. If you need to reproduce its behavior you must copy the code to your own class on your portlet.
Daniel Wilmes, geändert vor 12 Jahren.

RE: not displaying control panel portlets

Regular Member Beiträge: 164 Beitrittsdatum: 23.05.11 Neueste Beiträge
Thank you for the reply. I will try added a new class to my portlet and test it out. Are you aware of some good documentation for permissions? Thanks again.
Daniel Wilmes, geändert vor 12 Jahren.

RE: not displaying control panel portlets

Regular Member Beiträge: 164 Beitrittsdatum: 23.05.11 Neueste Beiträge
Okay here is my class and the node in my liferay-portal.xml
<control-panel-entry-class>com.portlet.security.ControlPanelEntry</control-panel-entry-class>
But that doesn't seem to affect the display of the portlet in the control panel.


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.portlet.security;

import com.liferay.portal.model.Portlet;
import com.liferay.portal.model.Role;
import com.liferay.portal.security.auth.CompanyThreadLocal;
import com.liferay.portal.service.RoleLocalServiceUtil;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portlet.BaseControlPanelEntry;
import java.util.List;
import java.util.Locale;

/**
 *
 * @author
 */
public class ControlPanelEntry extends BaseControlPanelEntry {
    public boolean isVisible(PermissionChecker permissionChecker, Portlet portlet) throws Exception {
        System.out.println("/************CHECKING ROLES***************/");
        List<role> roles = RoleLocalServiceUtil.getRoles(CompanyThreadLocal.getCompanyId());
        boolean flag = false;
        System.out.println(Integer.toString(roles.size()));
        for(Role role: roles) {
            if(role.getTitle(Locale.ENGLISH).equals("CUST Admin"))
            {
                flag = true;
            }
            System.out.println(role.getTitle(Locale.ENGLISH));
        }
         return flag;
    }
}

</role>


Any help would be great. Thanks.
thumbnail
Thiago Leão Moreira, geändert vor 12 Jahren.

RE: not displaying control panel portlets

Liferay Legend Beiträge: 1449 Beitrittsdatum: 10.10.07 Neueste Beiträge
Hey Daniel,

Your code iterate over all portal's roles not the current user logged role, so your portlet will always show up.
Daniel Wilmes, geändert vor 12 Jahren.

RE: not displaying control panel portlets

Regular Member Beiträge: 164 Beitrittsdatum: 23.05.11 Neueste Beiträge
Should my code look more like this?

      
        User w = UserServiceUtil.getUserById(Long.parseLong(actionRequest.getRemoteUser()));
        System.out.println(w.getFullName());
        List<role> roles = RoleLocalServiceUtil.getUserRoles(w.getUserId());
        boolean flag = false;
        System.out.println(Integer.toString(roles.size()));
        for(Role role: roles) {
            if(role.getTitle(Locale.ENGLISH).equals("CUST Admin")){
                flag = true;
            }
            System.out.println(role.getTitle(Locale.ENGLISH));
        }
</role>


Although I am not sure how to obtain the userId, because this class doesn't have access to ActionRequest/ActionResponse? Is there a simple way to get the current user?

Thanks
Daniel Wilmes, geändert vor 12 Jahren.

RE: not displaying control panel portlets

Regular Member Beiträge: 164 Beitrittsdatum: 23.05.11 Neueste Beiträge
I guess you can get the userId from the permissionChecker.getUserId() although I am still not getting any print outs from the class, so it is like I am not even executing the code inside the class.
thumbnail
Pankaj Kathiriya, geändert vor 12 Jahren.

RE: not displaying control panel portlets

Liferay Master Beiträge: 722 Beitrittsdatum: 05.08.10 Neueste Beiträge
Hi Daniel,
I have tried the same portlet provided by you and seems working fine.
Your code shows if user has Power User Role, then portlet should be shown in Control Panel.

Here you are comparing with "Power user" instead "Power User", that might be reason.

emoticon
Thanks,
Pankaj
Daniel Wilmes, geändert vor 12 Jahren.

RE: not displaying control panel portlets

Regular Member Beiträge: 164 Beitrittsdatum: 23.05.11 Neueste Beiträge
Thank you i tried what you suggested and it worked. Thank you for the help.