Пример #1
0
  protected void fixOrganizationRolePermissions() throws Exception {
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(ResourcePermission.class);

    dynamicQuery.add(RestrictionsFactoryUtil.eq("name", Organization.class.getName()));

    List<ResourcePermission> resourcePermissions =
        ResourcePermissionLocalServiceUtil.dynamicQuery(dynamicQuery);

    for (ResourcePermission resourcePermission : resourcePermissions) {
      ResourcePermission groupResourcePermission = null;

      try {
        groupResourcePermission =
            ResourcePermissionLocalServiceUtil.getResourcePermission(
                resourcePermission.getCompanyId(),
                Group.class.getName(),
                resourcePermission.getScope(),
                resourcePermission.getPrimKey(),
                resourcePermission.getRoleId());
      } catch (Exception e) {
        ResourcePermissionLocalServiceUtil.setResourcePermissions(
            resourcePermission.getCompanyId(),
            Group.class.getName(),
            resourcePermission.getScope(),
            resourcePermission.getPrimKey(),
            resourcePermission.getRoleId(),
            ResourcePermissionLocalServiceImpl.EMPTY_ACTION_IDS);

        groupResourcePermission =
            ResourcePermissionLocalServiceUtil.getResourcePermission(
                resourcePermission.getCompanyId(),
                Group.class.getName(),
                resourcePermission.getScope(),
                resourcePermission.getPrimKey(),
                resourcePermission.getRoleId());
      }

      long organizationActions = resourcePermission.getActionIds();
      long groupActions = groupResourcePermission.getActionIds();

      for (Object[] actionIdToMask : _ORGANIZATION_ACTION_IDS_TO_MASKS) {
        long organizationActionMask = (Long) actionIdToMask[1];
        long groupActionMask = (Long) actionIdToMask[2];

        if ((organizationActions & organizationActionMask) == organizationActionMask) {

          organizationActions = organizationActions & (~organizationActionMask);
          groupActions = groupActions | groupActionMask;
        }
      }

      try {
        resourcePermission.resetOriginalValues();

        resourcePermission.setActionIds(organizationActions);

        ResourcePermissionLocalServiceUtil.updateResourcePermission(resourcePermission);

        groupResourcePermission.resetOriginalValues();
        groupResourcePermission.setActionIds(groupActions);

        ResourcePermissionLocalServiceUtil.updateResourcePermission(groupResourcePermission);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    PermissionCacheUtil.clearCache();
  }
 /*
  * NOTE FOR DEVELOPERS:
  *
  * Never modify or reference this class directly. All methods that expect a resource permission model instance should use the {@link ResourcePermission} interface instead.
  */
 public void save() throws SystemException {
   ResourcePermissionLocalServiceUtil.updateResourcePermission(this);
 }