Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Daniel Wilmes
not displaying control panel portlets
19. Juli 2011 11:37
Antwort

Daniel Wilmes

Rang: Regular Member

Nachrichten: 164

Eintrittsdatum: 23. Mai 2011

Neue 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
Thiago Leão Moreira
RE: not displaying control panel portlets
19. Juli 2011 14:16
Antwort

Thiago Leão Moreira

LIFERAY STAFF

Rang: Liferay Legend

Nachrichten: 1431

Eintrittsdatum: 10. Oktober 2007

Neue 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
RE: not displaying control panel portlets
20. Juli 2011 06:14
Antwort

Daniel Wilmes

Rang: Regular Member

Nachrichten: 164

Eintrittsdatum: 23. Mai 2011

Neue 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
RE: not displaying control panel portlets
20. Juli 2011 08:46
Antwort

Daniel Wilmes

Rang: Regular Member

Nachrichten: 164

Eintrittsdatum: 23. Mai 2011

Neue 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.

 1
 2/*
 3 * To change this template, choose Tools | Templates
 4 * and open the template in the editor.
 5 */
 6package com.portlet.security;
 7
 8import com.liferay.portal.model.Portlet;
 9import com.liferay.portal.model.Role;
10import com.liferay.portal.security.auth.CompanyThreadLocal;
11import com.liferay.portal.service.RoleLocalServiceUtil;
12import com.liferay.portal.security.permission.PermissionChecker;
13import com.liferay.portlet.BaseControlPanelEntry;
14import java.util.List;
15import java.util.Locale;
16
17/**
18 *
19 * @author
20 */
21public class ControlPanelEntry extends BaseControlPanelEntry {
22    public boolean isVisible(PermissionChecker permissionChecker, Portlet portlet) throws Exception {
23        System.out.println("/************CHECKING ROLES***************/");
24        List<Role> roles = RoleLocalServiceUtil.getRoles(CompanyThreadLocal.getCompanyId());
25        boolean flag = false;
26        System.out.println(Integer.toString(roles.size()));
27        for(Role role: roles) {
28            if(role.getTitle(Locale.ENGLISH).equals("CUST Admin"))
29            {
30                flag = true;
31            }
32            System.out.println(role.getTitle(Locale.ENGLISH));
33        }
34         return flag;
35    }
36}


Any help would be great. Thanks.
Thiago Leão Moreira
RE: not displaying control panel portlets
20. Juli 2011 11:14
Antwort

Thiago Leão Moreira

LIFERAY STAFF

Rang: Liferay Legend

Nachrichten: 1431

Eintrittsdatum: 10. Oktober 2007

Neue 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
RE: not displaying control panel portlets
20. Juli 2011 10:30
Antwort

Daniel Wilmes

Rang: Regular Member

Nachrichten: 164

Eintrittsdatum: 23. Mai 2011

Neue Beiträge

Should my code look more like this?

 1      
 2        User w = UserServiceUtil.getUserById(Long.parseLong(actionRequest.getRemoteUser()));
 3        System.out.println(w.getFullName());
 4        List<Role> roles = RoleLocalServiceUtil.getUserRoles(w.getUserId());
 5        boolean flag = false;
 6        System.out.println(Integer.toString(roles.size()));
 7        for(Role role: roles) {
 8            if(role.getTitle(Locale.ENGLISH).equals("CUST Admin")){
 9                flag = true;
10            }
11            System.out.println(role.getTitle(Locale.ENGLISH));
12        }


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
RE: not displaying control panel portlets
20. Juli 2011 10:38
Antwort

Daniel Wilmes

Rang: Regular Member

Nachrichten: 164

Eintrittsdatum: 23. Mai 2011

Neue 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.
Pankaj Kathiriya
RE: not displaying control panel portlets
23. Juli 2011 10:26
Antwort

Pankaj Kathiriya

Rang: Liferay Master

Nachrichten: 697

Eintrittsdatum: 4. August 2010

Neue 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
RE: not displaying control panel portlets
25. Juli 2011 05:02
Antwort

Daniel Wilmes

Rang: Regular Member

Nachrichten: 164

Eintrittsdatum: 23. Mai 2011

Neue Beiträge

Thank you i tried what you suggested and it worked. Thank you for the help.