Commit 869fb181 authored by Takumaru Sekine's avatar Takumaru Sekine Committed by Yas Naoi
Browse files

Issue #3291742 by sekinet, Ryo Yamashita, yas: Add the function to revoke...

Issue #3291742 by sekinet, Ryo Yamashita, yas: Add the function to revoke Openstack Security Group in the SPA
parent 13b5bcaa
Loading
Loading
Loading
Loading
+17 −3
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/entity_info_template/openstack/security_group.ts: 17 added lines, 3 removed lines.
Original line number Diff line number Diff line
import EntityInfoTemplate from 'model/EntityInfoTemplate';
import EntityColumn from 'model/EntityColumn';
import { ROUTE_URL } from 'constant/other';

// Template for displaying detailed information about entities in OpenStack.
const COLUMN_RULES: EntityColumn[] = [
@@ -16,9 +17,22 @@ const COLUMN_RULES: EntityColumn[] = [
  { labelName: 'VPC ID', name: 'vpc_id', type: 'default' },
  { labelName: 'Peering connection ID', name: 'peering_connection_id', type: 'default' },
  { labelName: 'Description', name: 'description', type: 'default' },
  { labelName: 'Operation', name: '', type: 'default' }
];

const INBOUND_COLUMN_RULES: EntityColumn[] = COLUMN_RULES.concat([
  { labelName: 'Operation', name: 'operation', type: 'link',
    label: 'Revoke',
    url: `${ROUTE_URL}/{cloudServiceProvider}/{cloudContext}/{entityName}/{entityId}/revoke?type=ip_permission&position={index}`,
  }
]);

const OUTBOUND_COLUMN_RULES: EntityColumn[] = COLUMN_RULES.concat([
  { labelName: 'Operation', name: 'operation', type: 'link',
    label: 'Revoke',
    url: `${ROUTE_URL}/{cloudServiceProvider}/{cloudContext}/{entityName}/{entityId}/revoke?type=outbound_permission&position={index}`,
  }
]);

const OPENSTACK_SECURITY_GROUP_TEMPLATE: EntityInfoTemplate = {
  cloudServiceProvider: 'openstack',
  entityName: 'security_group',
@@ -37,8 +51,8 @@ const OPENSTACK_SECURITY_GROUP_TEMPLATE: EntityInfoTemplate = {
      panelName: 'Rules',
      tableRecordList: ['ip_permission', 'outbound_permission'],
      keyValueRecords: [
        { labelName: 'Inbound Rules', name: 'ip_permission', type: 'custom-table', column: COLUMN_RULES },
        { labelName: 'Outbound Rules', name: 'outbound_permission', type: 'custom-table', column: COLUMN_RULES },
        { labelName: 'Inbound Rules', name: 'ip_permission', type: 'custom-table', column: INBOUND_COLUMN_RULES },
        { labelName: 'Outbound Rules', name: 'outbound_permission', type: 'custom-table', column: OUTBOUND_COLUMN_RULES },
      ]
    },
    {
+12 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/openstack/security_group.ts: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -27,6 +27,18 @@ const OPENSTACK_SECURITY_GROUP_TEMPLATE: EntityFormTemplate[] = [
      },
    ],
    submitButtonLabel: 'Delete'
  },
  {
    cloudServiceProvider: 'openstack',
    entityName: 'security_group',
    actionType: 'revoke',
    entityRecords: [
      {
        type: 'label',
        text: 'Are you sure you want to revoke the following permission?'
      },
    ],
    submitButtonLabel: 'Revoke'
  }
]

+7 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/model/EntityColumn.ts: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -51,6 +51,13 @@ type EntityColumn = {
  type: 'select';
  url: string;
  readOnly?: boolean;
} | {
  labelName: string;
  name: string;
  type: 'link';
  url: string;
  label: string;
  readOnly?: boolean;
};

export default EntityColumn;
+30 −5
Changes for modules/cloud_dashboard/cloud_dashboard/src/molecules/TableBlock.tsx: 30 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,35 @@ import EntityInfoRecordData from 'model/EntityInfoRecordData';
import { Table } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';

const TdBlock = ({ text }: { text: string }) => {
  try {
    // For strings that can be parsed as JSON.
    const temp = JSON.parse(text);
    if (('type' in temp) && (temp['type'] === 'link')) {
      const url: string = temp['url'];
      const label: string = temp['label'];

      return <td className="word-break-all">
        <a href={url}>{label}</a>
      </td>;
    }

    return <td className="word-break-all">
      {text}
    </td>;
  } catch {
    if (text.includes('\n')) {
      return <td className="word-break-all">
        <pre>{text}</pre>
      </td>;
    }

    return <td className="word-break-all">
      {text}
    </td>;
  }
}

/**
 * Block of table view.
 *
@@ -58,11 +87,7 @@ const TableBlock = ({ record }: { record: EntityInfoRecordData }) => {
                return <tr className={index % 2 === 0 ? 'odd' : 'even'}>
                  {
                    keys.map((key, index2) => {
                      return <td className="word-break-all" key={index2}>{
                        r[key].includes('\n')
                          ? <pre>{r[key]}</pre>
                          : <>{r[key]}</>
                      }</td>;
                      return <TdBlock text={r[key]} />;
                    })
                  }
                </tr>;
+15 −7
Changes for modules/cloud_dashboard/cloud_dashboard/src/pages/EntityDetailPage.tsx: 15 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ import SideBar from 'organisms/SideBar';
import { useEffect, useState } from 'react';
import { Col, Container, Row } from 'react-bootstrap';
import { useParams } from 'react-router-dom';
import { convertDataForUI, readDataCache } from 'service/utility';
import { convertDataForUI, readDataCache, getReplacedUrl } from 'service/utility';

const getEntityInfoRecordData = async (
  getJsonData: GetJsonDataType,
@@ -42,21 +42,29 @@ const getEntityInfoRecordData = async (
    }
    case 'custom-table': {
      const keyVal: Record<string, string>[] = [];
      const temp: Record<string, string> = {};
      entityData.attributes[entityColumn.name].forEach((record: any, index: number) => {
        const temp: Record<string, string> = {};
        for (const column of entityColumn.column) {
        for (const record of entityData.attributes[entityColumn.name]) {
          if (!(column.name in record)) {
            continue;
          }
          const convertedText = convertDataForUI(
            record[column.name],
            column,
            dataCache
          );
          temp[column.name] = convertedText;
        }
          const convertedText2 = column.type === 'link'
            ? getReplacedUrl(
                convertedText,
                entityData.attributes['cloud_context'],
                entityName,
                entityData.attributes['drupal_internal__id'],
                cloudServiceProvider,
                index
              )
            : convertedText;
          temp[column.name] = convertedText2;
        }
        keyVal.push(temp);
      });
      return {
        type: 'table',
        title: entityColumn.labelName,
Loading