public void deletePermission(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long roleId = ParamUtil.getLong(actionRequest, "roleId");
    String name = ParamUtil.getString(actionRequest, "name");
    int scope = ParamUtil.getInteger(actionRequest, "scope");
    String primKey = ParamUtil.getString(actionRequest, "primKey");
    String actionId = ParamUtil.getString(actionRequest, "actionId");

    Role role = RoleLocalServiceUtil.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_OWNER)
        || roleName.equals(RoleConstants.OWNER)
        || roleName.equals(RoleConstants.SITE_ADMINISTRATOR)
        || roleName.equals(RoleConstants.SITE_OWNER)) {

      throw new RolePermissionsException(roleName);
    }

    if (ResourceBlockLocalServiceUtil.isSupported(name)) {
      if (scope == ResourceConstants.SCOPE_GROUP) {
        ResourceBlockServiceUtil.removeGroupScopePermission(
            themeDisplay.getScopeGroupId(),
            themeDisplay.getCompanyId(),
            GetterUtil.getLong(primKey),
            name,
            roleId,
            actionId);
      } else {
        ResourceBlockServiceUtil.removeCompanyScopePermission(
            themeDisplay.getScopeGroupId(), themeDisplay.getCompanyId(), name, roleId, actionId);
      }
    } else {
      ResourcePermissionServiceUtil.removeResourcePermission(
          themeDisplay.getScopeGroupId(),
          themeDisplay.getCompanyId(),
          name,
          scope,
          primKey,
          roleId,
          actionId);
    }

    // Send redirect

    SessionMessages.add(actionRequest, "permissionDeleted");

    String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

    if (Validator.isNotNull(redirect)) {
      actionResponse.sendRedirect(redirect);
    }
  }
  /**
   * Revokes permission at the scope from the role to perform the action on resources of the type.
   * For example, this method could be used to revoke a group scope permission to edit blog posts.
   *
   * <p>Depending on the scope, the value of <code>primKey</code> will have different meanings. For
   * more information, see {@link com.liferay.portal.model.impl.ResourcePermissionImpl}.
   *
   * @param groupId the primary key of the group
   * @param companyId the primary key of the company
   * @param name the resource's name, which can be either a class name or a portlet ID
   * @param scope the scope
   * @param primKey the primary key
   * @param roleId the primary key of the role
   * @param actionId the action ID
   * @throws PortalException if the user did not have permission to remove resource permissions, or
   *     if a role with the primary key or a resource action with the name and action ID could not
   *     be found
   * @throws SystemException if a system exception occurred
   */
  public static void removeResourcePermission(
      long groupId,
      long companyId,
      java.lang.String name,
      int scope,
      java.lang.String primKey,
      long roleId,
      java.lang.String actionId)
      throws RemoteException {
    try {
      ResourcePermissionServiceUtil.removeResourcePermission(
          groupId, companyId, name, scope, primKey, roleId, actionId);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }