|
11 | 11 | import com.liferay.portal.kernel.exception.SystemException;
|
12 | 12 | import com.liferay.portal.kernel.log.Log;
|
13 | 13 | import com.liferay.portal.kernel.log.LogFactoryUtil;
|
14 |
| -import com.liferay.portal.kernel.model.Layout; |
15 |
| -import com.liferay.portal.kernel.model.Resource; |
16 |
| -import com.liferay.portal.kernel.model.ResourceConstants; |
17 |
| -import com.liferay.portal.kernel.model.ResourcePermission; |
| 14 | +import com.liferay.portal.kernel.model.*; |
| 15 | +import com.liferay.portal.kernel.model.role.RoleConstants; |
18 | 16 | import com.liferay.portal.kernel.security.permission.ActionKeys;
|
19 | 17 | import com.liferay.portal.kernel.service.ResourceLocalServiceUtil;
|
20 | 18 | import com.liferay.portal.kernel.service.ResourcePermissionLocalServiceUtil;
|
@@ -43,29 +41,41 @@ public static void setupPortletPermissions(final ResourcePermissions resourcePer
|
43 | 41 | String roleName = actionsPerRoleEntry.getKey();
|
44 | 42 | try {
|
45 | 43 | long companyId = SetupConfigurationThreadLocal.getRunInCompanyId();
|
46 |
| - long roleId = RoleLocalServiceUtil.getRole(companyId, roleName).getRoleId(); |
| 44 | + com.liferay.portal.kernel.model.Role role = RoleLocalServiceUtil.getRole(companyId, roleName); |
| 45 | + long roleId = role.getRoleId(); |
47 | 46 | final Set<String> actionStrings = actionsPerRoleEntry.getValue();
|
48 | 47 | final String[] actionIds = actionStrings.toArray(new String[actionStrings.size()]);
|
49 | 48 |
|
50 |
| - /** |
51 |
| - * Individual permission is needed even though we set |
52 |
| - */ |
53 |
| - ResourcePermissionLocalServiceUtil.setResourcePermissions( |
54 |
| - companyId, |
55 |
| - resource.getResourceId(), |
56 |
| - ResourceConstants.SCOPE_INDIVIDUAL, |
57 |
| - String.valueOf(companyId), |
58 |
| - roleId, |
59 |
| - actionIds |
60 |
| - ); |
61 |
| - ResourcePermissionLocalServiceUtil.setResourcePermissions( |
62 |
| - companyId, |
63 |
| - resource.getResourceId(), |
64 |
| - ResourceConstants.SCOPE_COMPANY, |
65 |
| - String.valueOf(companyId), |
66 |
| - roleId, |
67 |
| - actionIds |
68 |
| - ); |
| 49 | + if (role.getType() == RoleConstants.TYPE_SITE || role.getType() == RoleConstants.TYPE_ORGANIZATION) { |
| 50 | + ResourcePermissionLocalServiceUtil.setResourcePermissions( |
| 51 | + companyId, |
| 52 | + resource.getResourceId(), |
| 53 | + ResourceConstants.SCOPE_GROUP_TEMPLATE, |
| 54 | + String.valueOf(companyId), |
| 55 | + roleId, |
| 56 | + actionIds |
| 57 | + ); |
| 58 | + } else { |
| 59 | + /** |
| 60 | + * Individual permission is needed even though we set |
| 61 | + */ |
| 62 | + ResourcePermissionLocalServiceUtil.setResourcePermissions( |
| 63 | + companyId, |
| 64 | + resource.getResourceId(), |
| 65 | + ResourceConstants.SCOPE_INDIVIDUAL, |
| 66 | + String.valueOf(companyId), |
| 67 | + roleId, |
| 68 | + actionIds |
| 69 | + ); |
| 70 | + ResourcePermissionLocalServiceUtil.setResourcePermissions( |
| 71 | + companyId, |
| 72 | + resource.getResourceId(), |
| 73 | + ResourceConstants.SCOPE_COMPANY, |
| 74 | + String.valueOf(companyId), |
| 75 | + roleId, |
| 76 | + actionIds |
| 77 | + ); |
| 78 | + } |
69 | 79 | LOG.info(String.format("Set permission for role: %1$s for action ids: %2$s", roleName, actionIds));
|
70 | 80 | } catch (NestableException e) {
|
71 | 81 | LOG.error(String.format("Could not set permission to resource :%1$s", resource.getResourceId()), e);
|
|
0 commit comments