Foren

How to hide default user roles,user,communites for other user?

thumbnail
Mani kandan, geändert vor 12 Jahren.

How to hide default user roles,user,communites for other user?

Expert Beiträge: 492 Beitrittsdatum: 15.09.10 Neueste Beiträge
Hi all,

I have created one user called "Admin" and I gave him some permission for Managing Users, Roles and Communities only in Control Panel.

My problem is, Liferay has default Roles (Administrator,Community Content Reviewer,Community Administrator etc.,) and default User(test).

I want to hide all default roles and default user for "Admin" which i have created. That is, "Admin" can able to add new users, new roles but he cant able to view default roles and user.

How to achieve it?
Oliver Bayer, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
Hi Mani,

to hide the default roles you can use the class "RoleConstants" and check e.g. for "SYSTEM_ORGANIZATION_ROLES" or "SYSTEM_ROLES" or "SYSTEM_SITE_ROLES".

HTH Oli
thumbnail
Mani kandan, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Expert Beiträge: 492 Beitrittsdatum: 15.09.10 Neueste Beiträge
Hi Oliver,

Thanks for the reply, I don't want to hide the roles for "Administrator" user.

I want to hide the default roles only for "Admin" user which I have created newly.

Pls read my above requirement once again.
Oliver Bayer, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
Hi Mani,

I've read your requirements twice but my hint is still valid - at least I think emoticon.

All default roles (like Administrator ...) are defined in the "RoleConstants" class so all you have to do is to check if the current user is your newly created "Admin" user and then iterate over the default roles defined in RoleConstants.

Here some pseudo-code snippet:
List<role> rolesToShow = new ArrayList<role>();

if (currentUser == "Admin")
{
	List<role> allRoles = getAllRolesFromAUtilClass();
	
	for (allRoles as currentRole)
	{
		if (currentRole NOT IN RoleConstants)
		{
			// currentRole is not a default role -&gt; add the current role of RoleConstants to the array (rolesToShow)
			rolesToShow.add(currentRole);
		}
	}
}
else
{
	// here is the original Liferay code to show ALL roles (including the default ones from RoleConstants)
}</role></role></role>

Greets Oli
thumbnail
Mani kandan, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Expert Beiträge: 492 Beitrittsdatum: 15.09.10 Neueste Beiträge
Hey Oliver,

Where can I get this values?

List<role> allRoles = getAllRolesFromAUtilClass();</role>


And I couldn't understand this code line,

for (allRoles as currentRole)
    {
        if (currentRole NOT IN RoleConstants)
        
thumbnail
Sandeep Nair, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
Hi Mani,

As Oliver is saying you have to create that utility method which would get all the roles in the system. Then just filter Liferay Roles by iterating over all the roles that are mentioned in RoleConstants.

He has given pseudocode for logic, not actual code.You may have to write the proper java code in the direction tha he has mentioned

Regards,
Sandeep
thumbnail
Mani kandan, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Expert Beiträge: 492 Beitrittsdatum: 15.09.10 Neueste Beiträge
Hi sandeep,
Do you know the code?
Oliver Bayer, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
Hi Mani,

as Sandeep and I are trying to explain you should get all roles in the system and then check each role if it is a default role (defined in RoleConstants).

If you want to modify the jsp which creates the permission page (I don't know which jsp exactly creates the list) you don't have to worry about retrieving all roles because this Util call must be already in this specific jsp.

Otherwise if you want to write sth on your own you should be able to use "List<Role> RoleLocalServiceUtil.getRoles(long companyId)". You can get the companyId by using the ThemeDisplay object.

Now move on to the filtering if the currentUser equals "Admin". Refer to my pseudo-code from above.

Greets Oli
thumbnail
Sandeep Nair, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
Hi Mani,

Please find the code below with explanation. I havent tried it in any editor or eclipse so there may be syntax errors.

//we are going to store the filtered roles in this arraylis
List<string> adminUserAllowedRoles = new ArrayList<string>();

//We will retrieve all the roles in the system.
List<role> allRoles = RoleLocalServiceUtil.getRoles(-1,-1);

//populating arraylist with liferay default roles. call of method is made here
List<role> liferayDefaultRoles = getSystemRoles();

//we will check if user to whom the filtered roles will be visible is the new user that you created
if(PortalUtil.getUser(request).getScreename().equals("adminUser")){
  
    //iterating over all the roles
    for(Role currentRole : allRoles){
      //check if the current role is not there in system role  
      if(!liferayDefaultRoles .contains(currentRole .getRoleName()){
            
           //add the role to the arraylist that we have reserved for filtering which doesnot have system roles
           adminUserAllowedRoles.add(currentRole);
        }
    }

   //At this point you have adminUserAllowedRoles which has only roles that are not Liferay roles
   System.out.println("Just for checking "+:adminUserAllowedRoles.toString());
}

//Method which would return system roles
public static List<string> getSystemRoles(){
 //arraylist to populate systemRoles
  List <string> systemRoles = new ArrayList<string>();
 
 //Adding all the liferay portal system roles
 systemRoles.addAll(Arrays.asList(RoleConstants.SYSTEM_ROLES));

 //Adding all the liferay community system roles
 systemRoles.addAll(Arrays.asList(RoleConstants.SYSTEM_COMMUNITY_ROLES));
 
 //Adding all the liferay organization system roles
 systemRoles.addAll(Arrays.asList(RoleConstants.SYSTEM_ORGANIZATION_ROLES));

  //here we have all the systemroles now
  return systemRoles;
}</string></string></string></role></role></string></string>


Regards,
Sandeep
thumbnail
Mani kandan, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Expert Beiträge: 492 Beitrittsdatum: 15.09.10 Neueste Beiträge
Hi sandeep,

I want to do this in \html\portlet\enterprise_admin\view_roles.jsp file which is displaying all the roles.

Could you pls correct my jsp file. Check the attachment file.

To get the system roles,
I have included this code,


		//arraylist to populate systemRoles
		  List <string> systemRoles = new ArrayList<string>();

		//Adding all the liferay portal system roles
		systemRoles.addAll(Arrays.asList(RoleConstants.SYSTEM_ROLES));

		//Adding all the liferay community system roles
		systemRoles.addAll(Arrays.asList(RoleConstants.SYSTEM_COMMUNITY_ROLES));

		//Adding all the liferay organization system roles
		systemRoles.addAll(Arrays.asList(RoleConstants.SYSTEM_ORGANIZATION_ROLES));

		  //here we have all the systemroles now
		  return systemRoles;
		}
</string></string>
thumbnail
Sandeep Nair, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
if(!liferayDefaultRoles .contains(currentRole.getRoleId()))

The above will line will fail since ArrayList contains string and you are doing contains on RoleId which is long.


if(!liferayDefaultRoles .contains(currentRole.getRoleName()))

Regards,
Sandeep
thumbnail
Mani kandan, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Expert Beiträge: 492 Beitrittsdatum: 15.09.10 Neueste Beiträge
See the attachment.
The following code is generating the list of roles in that jsp file.

How can I include your code in the below codes?

&lt;%
List resultRows = searchContainer.getResultRows();
//System.out.println("Results.size() ######"+results.size());
Role role1 = (Role)results.get(0);
for (int i = 0; i &lt; results.size(); i++) {

	Role role = (Role)results.get(i);
	role = role.toEscapedModel();
	ResultRow row = new ResultRow(role, role.getRoleId(), i);
	PortletURL rowURL = null;
	if (RolePermissionUtil.contains(permissionChecker, role.getRoleId(), ActionKeys.UPDATE)) {
		rowURL = renderResponse.createRenderURL();

		rowURL.setParameter("struts_action", "/enterprise_admin/edit_role");
		rowURL.setParameter("redirect", searchContainer.getIteratorURL().toString());
		rowURL.setParameter("roleId", String.valueOf(role.getRoleId()));
	}
	
	// Name

	row.addText(HtmlUtil.escape(role.getName()), rowURL);

	// Type

	row.addText(LanguageUtil.get(pageContext, role.getTypeLabel()), rowURL);

	// Description

	row.addText(role.getDescription(), rowURL);

	// Action
	
	row.addJSP("right", SearchEntry.DEFAULT_VALIGN, "/html/portlet/enterprise_admin/role_action.jsp");

	// CSS

	row.setClassName(EnterpriseAdminUtil.getCssClassName(role));
	row.setClassHoverName(EnterpriseAdminUtil.getCssClassName(role));

	// Add result row

	resultRows.add(row);
}
%&gt;
Oliver Bayer, geändert vor 12 Jahren.

RE: How to hide default user roles,user,communites for other user?

Liferay Master Beiträge: 894 Beitrittsdatum: 18.02.09 Neueste Beiträge
Hi Mani,

it seems that you've defined the variable "systemRoles" of the wrong type. It has to be "List<String>" but from the given error message it seems that it's defined as "List<Role>".

HTH Oli