2

Im trying to hide unnecessary parts from drop-down menu. To be precise Notifications, Shared Content, My Submissions, My Workflow Tasks etc..

I was able to remove them via Control panel -> Users -> Roles -> User -> Permissions

Is there way to achieve same result through Hooks or through config file?

Im running docker with liferay/portal:7.3.0-ga1 image and therefore need to be able to achieve this without GUI.

Peter Andreus
  • 84
  • 1
  • 8

1 Answers1

1

After various research i came up with this:

private void removePermissions() throws PortalException {
    List<String> portletList = Arrays.asList("com_liferay_users_admin_web_portlet_MyOrganizationsPortlet",
            "com_liferay_my_account_web_portlet_MyAccountPortlet",
            "com_liferay_portal_workflow_web_internal_portlet_UserWorkflowPortlet",
            "com_liferay_portal_workflow_task_web_portlet_MyWorkflowTaskPortlet",
            "com_liferay_notifications_web_portlet_NotificationsPortlet",
            "com_liferay_sharing_web_portlet_SharedAssetsPortlet",
            "com_liferay_oauth2_provider_web_internal_portlet_OAuth2ConnectedApplicationsPortlet"
    );

    String primKey = String.valueOf(company.getPrimaryKey());

    for (String portlet : portletList) {
        ResourcePermissionLocalServiceUtil.removeResourcePermission(
                companyId,
                portlet,
                ResourceConstants.SCOPE_COMPANY,
                primKey,
                userRole.getRoleId(),
                "ACCESS_IN_CONTROL_PANEL");
    }

}

companyId, userRole can be achieved via RoleLocalServiceUtil and CompanyLocalServiceUtil. PrimKey is differs based on scope, this blog helped me a lot understanding it. I sniffed names of portlets through developer console when removing permissions through GUI. I haven't found cleaner solution.

Peter Andreus
  • 84
  • 1
  • 8
  • 1
    Hi @peter-andreus, check this repository https://github.com/slemarchand/liferay-gogo-scripts or the older version of it: https://github.com/slemarchand/liferay-admin-scripts by https://stackoverflow.com/users/5943100/s%c3%a9bastien-le-marchand to further extend the idea. – Pawel Kruszewski Jul 14 '20 at 11:43