Skip to content

Commit

Permalink
Revert "fix Cannot find module when import ResourceType in server fro…
Browse files Browse the repository at this point in the history
…m public folder (opensearch-project#1705)"

This reverts commit 09b2f59.

Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed Jan 16, 2024
1 parent 2f16e4e commit 2de58e3
Show file tree
Hide file tree
Showing 33 changed files with 60 additions and 71 deletions.
12 changes: 0 additions & 12 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ export enum AuthType {
ANONYMOUS = 'anonymous',
}

export enum ResourceType {
roles = 'roles',
users = 'users',
serviceAccounts = 'serviceAccounts',
permissions = 'permissions',
tenants = 'tenants',
tenantsManageTab = 'tenantsManageTab',
tenantsConfigureTab = 'tenantsConfigureTab',
auth = 'auth',
auditLogging = 'auditLogging',
}

/**
* A valid resource name should not containing percent sign (%) as they raise url injection issue.
* And also should not be empty.
Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import { RoleView } from './panels/role-view/role-view';
import { TenantList } from './panels/tenant-list/tenant-list';
import { UserList } from './panels/user-list';
import { ServiceAccountList } from './panels/service-account-list';
import { Action, RouteItem, SubAction } from './types';
import { ResourceType } from '../../../common';
import { Action, ResourceType, RouteItem, SubAction } from './types';
import { buildHashUrl, buildUrl } from './utils/url-builder';
import { CrossPageToast } from './cross-page-toast';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { SETTING_GROUPS, SettingMapItem } from './constants';
import { EditSettingGroup } from './edit-setting-group';
import { AuditLoggingSettings } from './types';
import { buildHashUrl, buildUrl } from '../../utils/url-builder';
import { ResourceType } from '../../../../../common';
import { ResourceType } from '../../types';
import { getAuditLogging, updateAuditLogging } from '../../utils/audit-logging-utils';
import { useToastState } from '../../utils/toast-utils';
import { setCrossPageToast } from '../../utils/storage-utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import React from 'react';
import { FormattedMessage } from '@osd/i18n/react';
import { AppDependencies } from '../../../types';
import { ResourceType } from '../../../../../common';
import { ResourceType } from '../../types';
import { getAuditLogging, updateAuditLogging } from '../../utils/audit-logging-utils';
import { displayBoolean, ExternalLink } from '../../utils/display-utils';
import { buildHashUrl } from '../../utils/url-builder';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AuditLoggingEditSettings } from '../audit-logging-edit-settings';
import React from 'react';
import { ComplianceSettings, GeneralSettings } from '../types';
import { buildHashUrl } from '../../../utils/url-builder';
import { ResourceType } from '../../../../../../common';
import { ResourceType } from '../../../types';

jest.mock('../../../utils/audit-logging-utils');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AuditLogging, renderComplianceSettings, renderGeneralSettings } from '.
import React from 'react';
import { EuiSwitch } from '@elastic/eui';
import { buildHashUrl } from '../../../utils/url-builder';
import { ResourceType } from '../../../../../../common';
import { ResourceType } from '../../../types';
import {
SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT,
SUB_URL_FOR_GENERAL_SETTINGS_EDIT,
Expand Down
11 changes: 8 additions & 3 deletions public/apps/configuration/panels/get-started.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ import {
} from '@elastic/eui';
import React from 'react';
import { FormattedMessage } from '@osd/i18n/react';
import { flow } from 'lodash';
import { HashRouter as Router, Route } from 'react-router-dom';
import { AppDependencies } from '../../types';
import { buildHashUrl } from '../utils/url-builder';
import { Action } from '../types';
import { ResourceType } from '../../../../common';
import { buildHashUrl, buildUrl } from '../utils/url-builder';
import { Action, ResourceType, RouteItem } from '../types';
import { API_ENDPOINT_CACHE, DocLinks } from '../constants';
import { ExternalLink, ExternalLinkButton } from '../utils/display-utils';
import { TenantList } from './tenant-list/tenant-list';
import { getBreadcrumbs } from '../app-router';

import { CrossPageToast } from '../cross-page-toast';

const addBackendStep = {
title: 'Add backends',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import {
} from '@elastic/eui';
import React, { useState } from 'react';
import { BreadcrumbsPageDependencies } from '../../../types';
import { InternalUserUpdate } from '../../types';
import { ResourceType } from '../../../../../common';
import { InternalUserUpdate, ResourceType } from '../../types';
import { getUserDetail, updateUser } from '../../utils/internal-user-detail-utils';
import { PanelWithHeader } from '../../utils/panel-with-header';
import { PasswordEditPanel } from '../../utils/password-edit-panel';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

import React, { Dispatch, SetStateAction } from 'react';
import { EuiForm, EuiFlexGroup, EuiFlexItem, EuiComboBox } from '@elastic/eui';
import { ComboBoxOptions } from '../../types';
import { ResourceType } from '../../../../../common';
import { ComboBoxOptions, ResourceType } from '../../types';
import { PanelWithHeader } from '../../utils/panel-with-header';
import { FormRow } from '../../utils/form-row';
import { LIMIT_WIDTH_INPUT_CLASS } from '../../constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import {
} from '@elastic/eui';
import React, { Dispatch, Fragment, SetStateAction } from 'react';
import { isEmpty } from 'lodash';
import { RoleIndexPermission } from '../../types';
import { ResourceType } from '../../../../../common';
import { RoleIndexPermission, ResourceType } from '../../types';
import {
appendElementToArray,
removeElementFromArray,
Expand Down Expand Up @@ -142,9 +141,9 @@ export function IndexPermissionRow(props: {
return (
<FormRow
headerText="Index permissions"
headerSubText="You can specify permissions using both action groups or single permissions.
headerSubText="You can specify permissions using both action groups or single permissions.
A permission group is a list of single permissions.
You can often achieve your desired security posture using some combination of the default permission groups.
You can often achieve your desired security posture using some combination of the default permission groups.
You can also create your own reusable permission groups."
>
<EuiFlexGroup>
Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/panels/role-edit/role-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ import {
} from './tenant-panel';
import { RoleIndexPermissionStateClass, RoleTenantPermissionStateClass } from './types';
import { buildHashUrl, buildUrl } from '../../utils/url-builder';
import { ComboBoxOptions, Action, ActionGroupItem } from '../../types';
import { ResourceType } from '../../../../../common';
import { ComboBoxOptions, ResourceType, Action, ActionGroupItem } from '../../types';
import {
useToastState,
createUnknownErrorToast,
Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/panels/role-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ import {
fetchRoleMapping,
buildSearchFilterOptions,
} from '../utils/role-list-utils';
import { Action } from '../types';
import { ResourceType } from '../../../../common';
import { ResourceType, Action } from '../types';
import { buildHashUrl } from '../utils/url-builder';
import {
ExternalLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import { ExternalIdentityStateClass } from './types';
import { ComboBoxOptions } from '../../types';
import { stringToComboBoxOption, comboBoxOptionToString } from '../../utils/combo-box-utils';
import { buildHashUrl, buildUrl } from '../../utils/url-builder';
import { RoleMappingDetail, SubAction, Action } from '../../types';
import { ResourceType } from '../../../../../common';
import { ResourceType, RoleMappingDetail, SubAction, Action } from '../../types';
import { fetchUserNameList } from '../../utils/internal-user-list-utils';
import { updateRoleMapping, getRoleMappingData } from '../../utils/role-mapping-utils';
import { createErrorToast, createUnknownErrorToast, useToastState } from '../../utils/toast-utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import { ComboBoxOptions } from '../../types';
import { PanelWithHeader } from '../../utils/panel-with-header';
import { FormRow } from '../../utils/form-row';
import { buildHashUrl } from '../../utils/url-builder';
import { Action } from '../../types';
import { ResourceType } from '../../../../../common';
import { ResourceType, Action } from '../../types';
import { ExternalLinkButton } from '../../utils/display-utils';
import { DocLinks } from '../../constants';
import { appendOptionToComboBoxHandler } from '../../utils/combo-box-utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import React from 'react';
import { EuiEmptyPrompt, EuiButton } from '@elastic/eui';
import { PanelWithHeader } from '../../utils/panel-with-header';
import { PermissionTree } from '../permission-tree';
import { ActionGroupItem, DataObject, Action } from '../../types';
import { ResourceType } from '../../../../../common';
import { ActionGroupItem, DataObject, ResourceType, Action } from '../../types';
import { buildHashUrl } from '../../utils/url-builder';
import { loadingSpinner } from '../../utils/loading-spinner-utils';
import { DocLinks } from '../../constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import {
ActionGroupItem,
ExpandedRowMapInterface,
RoleIndexPermissionView,
ResourceType,
Action,
} from '../../types';
import { ResourceType } from '../../../../../common';
import { truncatedListView, displayArray, tableItemsUIProps } from '../../utils/display-utils';
import { PermissionTree } from '../permission-tree';
import { getFieldLevelSecurityMethod } from '../../utils/index-permission-utils';
Expand Down
2 changes: 1 addition & 1 deletion public/apps/configuration/panels/role-view/role-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { difference } from 'lodash';
import { BreadcrumbsPageDependencies } from '../../../types';
import { buildHashUrl, buildUrl } from '../../utils/url-builder';
import {
ResourceType,
Action,
SubAction,
RoleMappingDetail,
Expand All @@ -47,7 +48,6 @@ import {
RoleIndexPermissionView,
RoleTenantPermissionView,
} from '../../types';
import { ResourceType } from '../../../../../common';
import {
getRoleMappingData,
MappedUsersListing,
Expand Down
8 changes: 6 additions & 2 deletions public/apps/configuration/panels/role-view/tenants-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ import {
import { CoreStart } from 'opensearch-dashboards/public';
import { getCurrentUser } from '../../../../utils/auth-info-utils';
import { PanelWithHeader } from '../../utils/panel-with-header';
import { RoleTenantPermissionView, RoleTenantPermissionDetail, Action } from '../../types';
import { ResourceType } from '../../../../../common';
import {
RoleTenantPermissionView,
RoleTenantPermissionDetail,
ResourceType,
Action,
} from '../../types';
import { truncatedListView, tableItemsUIProps } from '../../utils/display-utils';
import {
fetchTenants,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { shallow } from 'enzyme';
import { ClusterPermissionPanel } from '../cluster-permission-panel';
import { EuiButton, EuiEmptyPrompt, EuiLoadingSpinner } from '@elastic/eui';
import { PermissionTree } from '../../permission-tree';
import { Action } from '../../../types';
import { ResourceType } from '../../../../../../common';
import { Action, ResourceType } from '../../../types';
import { buildHashUrl } from '../../../utils/url-builder';

describe('Role view - cluster permission panel', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

import React from 'react';
import { shallow, mount } from 'enzyme';
import { Action, RoleIndexPermissionView } from '../../../types';
import { ResourceType } from '../../../../../../common';
import { Action, ResourceType, RoleIndexPermissionView } from '../../../types';
import {
renderFieldLevelSecurity,
renderRowExpanstionArrow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import { getRoleDetail } from '../../../utils/role-detail-utils';
import { transformRoleIndexPermissions } from '../../../utils/index-permission-utils';
import { useDeleteConfirmState } from '../../../utils/delete-confirm-modal-utils';
import { requestDeleteRoles } from '../../../utils/role-list-utils';
import { Action, SubAction } from '../../../types';
import { ResourceType } from '../../../../../../common';
import { Action, ResourceType, SubAction } from '../../../types';
import { buildHashUrl } from '../../../utils/url-builder';
import { createUnknownErrorToast } from '../../../utils/toast-utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { mount, shallow } from 'enzyme';
import { TenantsPanel } from '../tenants-panel';
import { EuiEmptyPrompt, EuiInMemoryTable, EuiTableFieldDataColumnType } from '@elastic/eui';
import { buildHashUrl } from '../../../utils/url-builder';
import { Action, RoleTenantPermissionDetail } from '../../../types';
import { ResourceType } from '../../../../../../common';
import { Action, ResourceType, RoleTenantPermissionDetail } from '../../../types';
import { RoleViewTenantInvalidText } from '../../../constants';

jest.mock('../../../utils/tenant-utils');
Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/panels/service-account-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import React, { useState } from 'react';
import { getAuthInfo } from '../../../utils/auth-info-utils';
import { AppDependencies } from '../../types';
import { API_ENDPOINT_SERVICEACCOUNTS, DocLinks } from '../constants';
import { Action } from '../types';
import { ResourceType } from '../../../../common';
import { Action, ResourceType } from '../types';
import { EMPTY_FIELD_VALUE } from '../ui-constants';
import { useContextMenuState } from '../utils/context-menu';
import { ExternalLink, tableItemsUIProps, truncatedListView } from '../utils/display-utils';
Expand Down
7 changes: 4 additions & 3 deletions public/apps/configuration/panels/tenant-list/manage_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import React, { ReactNode, useState, useCallback } from 'react';
import { difference } from 'lodash';
import { HashRouter as Router, Route } from 'react-router-dom';
import { flow } from 'lodash';
import { TenancyConfigSettings } from '../tenancy-config/types';
import { getCurrentUser } from '../../../../utils/auth-info-utils';
import { AppDependencies } from '../../../types';
import { Action, Tenant } from '../../types';
import { ResourceType } from '../../../../../common';
import { Action, ResourceType, Tenant } from '../../types';
import { ExternalLink, renderCustomization, tableItemsUIProps } from '../../utils/display-utils';
import {
fetchTenants,
Expand Down Expand Up @@ -481,7 +481,8 @@ export function ManageTab(props: AppDependencies) {
return (
<>
{/*{tenancyDisabledWarning}*/}
<EuiPageHeader></EuiPageHeader>
<EuiPageHeader>
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/panels/test/get-started.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import { shallow } from 'enzyme';
import React from 'react';
import { EuiSteps } from '@elastic/eui';
import { Action } from '../../types';
import { ResourceType } from '../../../../../common';
import { Action, ResourceType } from '../../types';
import { buildHashUrl } from '../../utils/url-builder';
import { GetStarted } from '../get-started';

Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/panels/test/role-list.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { mount, shallow } from 'enzyme';
import React from 'react';
import { EuiInMemoryTable, EuiTableFieldDataColumnType } from '@elastic/eui';
import { buildHashUrl } from '../../utils/url-builder';
import { Action } from '../../types';
import { ResourceType } from '../../../../../common';
import { Action, ResourceType } from '../../types';
import { RoleListing } from '../../utils/role-list-utils';
import { useDeleteConfirmState } from '../../utils/delete-confirm-modal-utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ jest.mock('../../utils/context-menu', () => ({

import { getAuthInfo } from '../../../../utils/auth-info-utils';
import { buildHashUrl } from '../../utils/url-builder';
import { Action } from '../../types';
import { ResourceType } from '../../../../../common';
import { ResourceType, Action } from '../../types';

describe('User list', () => {
describe('dictView', () => {
Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/panels/test/user-list.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ jest.mock('../../utils/context-menu', () => ({

import { getAuthInfo } from '../../../../utils/auth-info-utils';
import { buildHashUrl } from '../../utils/url-builder';
import { Action } from '../../types';
import { ResourceType } from '../../../../../common';
import { ResourceType, Action } from '../../types';

describe('User list', () => {
describe('dictView', () => {
Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/panels/user-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import React, { useState } from 'react';
import { getAuthInfo } from '../../../utils/auth-info-utils';
import { AppDependencies } from '../../types';
import { API_ENDPOINT_INTERNALUSERS, DocLinks } from '../constants';
import { Action } from '../types';
import { ResourceType } from '../../../../common';
import { Action, ResourceType } from '../types';
import { EMPTY_FIELD_VALUE } from '../ui-constants';
import { useContextMenuState } from '../utils/context-menu';
import { useDeleteConfirmState } from '../utils/delete-confirm-modal-utils';
Expand Down
12 changes: 12 additions & 0 deletions public/apps/configuration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ export type ComboBoxOptions = EuiComboBoxOptionOption[];

export type FieldLevelSecurityMethod = 'exclude' | 'include';

export enum ResourceType {
roles = 'roles',
users = 'users',
serviceAccounts = 'serviceAccounts',
permissions = 'permissions',
tenants = 'tenants',
tenantsManageTab = 'tenantsManageTab',
tenantsConfigureTab = 'tenantsConfigureTab',
auth = 'auth',
auditLogging = 'auditLogging',
}

export enum Action {
view = 'view',
create = 'create',
Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/utils/internal-user-list-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
API_ENDPOINT_INTERNALUSERS,
API_ENDPOINT_SERVICEACCOUNTS,
} from '../constants';
import { DataObject, InternalUser, ObjectsMessage } from '../types';
import { ResourceType } from '../../../../common';
import { DataObject, InternalUser, ObjectsMessage, ResourceType } from '../types';
import { httpDelete, httpGet } from './request-utils';
import { getResourceUrl } from './resource-utils';

Expand Down
3 changes: 1 addition & 2 deletions public/apps/configuration/utils/url-builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
* permissions and limitations under the License.
*/

import { Action } from '../types';
import { ResourceType } from '../../../../common';
import { ResourceType, Action } from '../types';

/**
* Build hash based url, encode the resourceId part
Expand Down
2 changes: 1 addition & 1 deletion server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
OpenSearchDashboardsResponseFactory,
} from 'opensearch-dashboards/server';
import { API_PREFIX, CONFIGURATION_API_PREFIX, isValidResourceName } from '../../common';
import { ResourceType } from '../../common';
import { ResourceType } from '../../public/apps/configuration/types';

// TODO: consider to extract entity CRUD operations and put it into a client class
export function defineRoutes(router: IRouter) {
Expand Down

0 comments on commit 2de58e3

Please sign in to comment.