Message Boards

Setting permission for socialactivitiesportlet

Sandeep A, modified 2 Years ago.

Setting permission for socialactivitiesportlet

New Member Posts: 2 Join Date: 5/6/21 Recent Posts

I added a social acitity portlet to a welcomelayout and by default the portlet is visible to all users. I want to restrict the permissions only to site members. Please let me know how can i acheive this. 

Below is my code : 

 welcomeLayoutTypePortlet = (LayoutTypePortlet) welcomeLayout.getLayoutType();
               

               String journalPortletId = welcomeLayoutTypePortlet.addPortletId(userId, "com_liferay_social_activities_web_portlet_SocialActivitiesPortlet", "column-1", columnPosition, true);
               
               columnPosition += 100;
               
       
               welcomeLayout = LayoutLocalServiceUtil.updateLayout(welcomeLayout.getGroupId(), welcomeLayout.isPrivateLayout(),welcomeLayout.getLayoutId(), welcomeLayout.getTypeSettings());
               welcomeLayoutTypePortlet = (LayoutTypePortlet) welcomeLayout.getLayoutType();

               //Retrieve the portlet preferences for the journal portlet instance just created
               PortletPreferences prefs = PortletPreferencesLocalServiceUtil.getPreferences(companyId,
                       ownerId,
                       ownerType,
                       welcomeLayout.getPlid(),
                       journalPortletId);
               
            

                //update the portlet preferences
                PortletPreferencesLocalServiceUtil.updatePreferences(ownerId, ownerType, welcomeLayout.getPlid(), journalPortletId, prefs);

 

I understand I have to use ResourcePermissionLocalServiceUtil.setResourcePermissions method. I tried this but it did not work 

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, "com_liferay_social_activities_web_portlet_SocialActivitiesPortlet",
						ResourceConstants.SCOPE_INDIVIDUAL, (""+companyId+"_LAYOUT_com_liferay_social_activities_web_portlet_SocialActivitiesPortlet"), 
						siteAdministratorRole.getRoleId(), actionsRW_SiteAdministrator);

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, "com_liferay_social_activities_web_portlet_SocialActivitiesPortlet",
						ResourceConstants.SCOPE_INDIVIDUAL, (""+companyId+"_LAYOUT_com_liferay_social_activities_web_portlet_SocialActivitiesPortlet"), 
						siteAdministratorRole.getRoleId(), actionsRW_SiteAdministrator);

 

Sandeep A, modified 2 Years ago.

RE: Setting permission for socialactivitiesportlet

New Member Posts: 2 Join Date: 5/6/21 Recent Posts

I resolved the issue by doing the followig :

ResourcePermission resourcePermission = null;
				
				//Setting Permission for OWNER

				resourcePermission = ResourcePermissionLocalServiceUtil
						.createResourcePermission(CounterLocalServiceUtil.increment());
				resourcePermission.setCompanyId(companyId);
				resourcePermission.setName("com_liferay_social_activities_web_portlet_SocialActivitiesPortlet");
				resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
				resourcePermission.setPrimKey(("" + welcomeLayout.getPlid()
						+ "_LAYOUT_com_liferay_social_activities_web_portlet_SocialActivitiesPortlet"));
				resourcePermission
						.setRoleId(RoleLocalServiceUtil.getRole(welcomeLayout.getCompanyId(), "Owner").getRoleId());

				//ResourceAction resourceAction = ResourceActionLocalServiceUtil.getResourceAction(
						//"com_liferay_social_activities_web_portlet_SocialActivitiesPortlet", ActionKeys.VIEW);
				resourcePermission.setActionIds(31);// (ActionKeys.VIEW);
				ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);