Skip to content

Commit

Permalink
[Backport 2.x] Fix cannot find module when import ResourceType in ser…
Browse files Browse the repository at this point in the history
…ver from public folder (#1705) (#1716)

Signed-off-by: Craig Perkins <[email protected]>
Co-authored-by: Yulong Ruan <[email protected]>
  • Loading branch information
cwperks and ruanyl authored Jan 4, 2024
1 parent 4019aa1 commit 1f55360
Show file tree
Hide file tree
Showing 29 changed files with 63 additions and 55 deletions.
11 changes: 11 additions & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ export enum AuthType {
ANONYMOUS = 'anonymous',
}

export enum ResourceType {
roles = 'roles',
users = 'users',
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: 2 additions & 1 deletion public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import { RoleEditMappedUser } from './panels/role-mapping/role-edit-mapped-user'
import { RoleView } from './panels/role-view/role-view';
import { TenantList } from './panels/tenant-list/tenant-list';
import { UserList } from './panels/user-list';
import { Action, ResourceType, RouteItem, SubAction } from './types';
import { Action, RouteItem, SubAction } from './types';
import { ResourceType } from '../../../common';
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 '../../types';
import { ResourceType } from '../../../../../common';
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 '../../types';
import { ResourceType } from '../../../../../common';
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 '../../../types';
import { ResourceType } from '../../../../../../common';

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 '../../../types';
import { ResourceType } from '../../../../../../common';
import {
SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT,
SUB_URL_FOR_GENERAL_SETTINGS_EDIT,
Expand Down
11 changes: 3 additions & 8 deletions public/apps/configuration/panels/get-started.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,12 @@ 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, buildUrl } from '../utils/url-builder';
import { Action, ResourceType, RouteItem } from '../types';
import { buildHashUrl } from '../utils/url-builder';
import { Action } from '../types';
import { ResourceType } from '../../../../common';
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,7 +26,8 @@ import {
} from '@elastic/eui';
import React, { useState } from 'react';
import { BreadcrumbsPageDependencies } from '../../../types';
import { InternalUserUpdate, ResourceType } from '../../types';
import { InternalUserUpdate } from '../../types';
import { ResourceType } from '../../../../../common';
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,7 +15,8 @@

import React, { Dispatch, SetStateAction } from 'react';
import { EuiForm, EuiFlexGroup, EuiFlexItem, EuiComboBox } from '@elastic/eui';
import { ComboBoxOptions, ResourceType } from '../../types';
import { ComboBoxOptions } from '../../types';
import { ResourceType } from '../../../../../common';
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,7 +25,8 @@ import {
} from '@elastic/eui';
import React, { Dispatch, Fragment, SetStateAction } from 'react';
import { isEmpty } from 'lodash';
import { RoleIndexPermission, ResourceType } from '../../types';
import { RoleIndexPermission } from '../../types';
import { ResourceType } from '../../../../../common';
import {
appendElementToArray,
removeElementFromArray,
Expand Down Expand Up @@ -141,9 +142,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: 2 additions & 1 deletion public/apps/configuration/panels/role-edit/role-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ import {
} from './tenant-panel';
import { RoleIndexPermissionStateClass, RoleTenantPermissionStateClass } from './types';
import { buildHashUrl, buildUrl } from '../../utils/url-builder';
import { ComboBoxOptions, ResourceType, Action, ActionGroupItem } from '../../types';
import { ComboBoxOptions, Action, ActionGroupItem } from '../../types';
import { ResourceType } from '../../../../../common';
import {
useToastState,
createUnknownErrorToast,
Expand Down
3 changes: 2 additions & 1 deletion public/apps/configuration/panels/role-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import {
fetchRoleMapping,
buildSearchFilterOptions,
} from '../utils/role-list-utils';
import { ResourceType, Action } from '../types';
import { Action } from '../types';
import { ResourceType } from '../../../../common';
import { buildHashUrl } from '../utils/url-builder';
import {
ExternalLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import { ExternalIdentityStateClass } from './types';
import { ComboBoxOptions } from '../../types';
import { stringToComboBoxOption, comboBoxOptionToString } from '../../utils/combo-box-utils';
import { buildHashUrl, buildUrl } from '../../utils/url-builder';
import { ResourceType, RoleMappingDetail, SubAction, Action } from '../../types';
import { RoleMappingDetail, SubAction, Action } from '../../types';
import { ResourceType } from '../../../../../common';
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,7 +19,8 @@ import { ComboBoxOptions } from '../../types';
import { PanelWithHeader } from '../../utils/panel-with-header';
import { FormRow } from '../../utils/form-row';
import { buildHashUrl } from '../../utils/url-builder';
import { ResourceType, Action } from '../../types';
import { Action } from '../../types';
import { ResourceType } from '../../../../../common';
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,7 +17,8 @@ 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, ResourceType, Action } from '../../types';
import { ActionGroupItem, DataObject, Action } from '../../types';
import { ResourceType } from '../../../../../common';
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,7 +39,6 @@ import { difference } from 'lodash';
import { BreadcrumbsPageDependencies } from '../../../types';
import { buildHashUrl, buildUrl } from '../../utils/url-builder';
import {
ResourceType,
Action,
SubAction,
RoleMappingDetail,
Expand All @@ -48,6 +47,7 @@ import {
RoleIndexPermissionView,
RoleTenantPermissionView,
} from '../../types';
import { ResourceType } from '../../../../../common';
import {
getRoleMappingData,
MappedUsersListing,
Expand Down
8 changes: 2 additions & 6 deletions public/apps/configuration/panels/role-view/tenants-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ import {
import { CoreStart } from 'opensearch-dashboards/public';
import { getCurrentUser } from '../../../../utils/auth-info-utils';
import { PanelWithHeader } from '../../utils/panel-with-header';
import {
RoleTenantPermissionView,
RoleTenantPermissionDetail,
ResourceType,
Action,
} from '../../types';
import { RoleTenantPermissionView, RoleTenantPermissionDetail, Action } from '../../types';
import { ResourceType } from '../../../../../common';
import { truncatedListView, tableItemsUIProps } from '../../utils/display-utils';
import {
fetchTenants,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { shallow } from 'enzyme';
import { ClusterPermissionPanel } from '../cluster-permission-panel';
import { EuiButton, EuiEmptyPrompt, EuiLoadingSpinner } from '@elastic/eui';
import { PermissionTree } from '../../permission-tree';
import { Action, ResourceType } from '../../../types';
import { Action } from '../../../types';
import { ResourceType } from '../../../../../../common';
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,7 +15,8 @@

import React from 'react';
import { shallow, mount } from 'enzyme';
import { Action, ResourceType, RoleIndexPermissionView } from '../../../types';
import { Action, RoleIndexPermissionView } from '../../../types';
import { ResourceType } from '../../../../../../common';
import {
renderFieldLevelSecurity,
renderRowExpanstionArrow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ 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, ResourceType, SubAction } from '../../../types';
import { Action, SubAction } from '../../../types';
import { ResourceType } from '../../../../../../common';
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,7 +18,8 @@ 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, ResourceType, RoleTenantPermissionDetail } from '../../../types';
import { Action, RoleTenantPermissionDetail } from '../../../types';
import { ResourceType } from '../../../../../../common';
import { RoleViewTenantInvalidText } from '../../../constants';

jest.mock('../../../utils/tenant-utils');
Expand Down
7 changes: 3 additions & 4 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, ResourceType, Tenant } from '../../types';
import { Action, Tenant } from '../../types';
import { ResourceType } from '../../../../../common';
import { ExternalLink, renderCustomization, tableItemsUIProps } from '../../utils/display-utils';
import {
fetchTenants,
Expand Down Expand Up @@ -481,8 +481,7 @@ export function ManageTab(props: AppDependencies) {
return (
<>
{/*{tenancyDisabledWarning}*/}
<EuiPageHeader>
</EuiPageHeader>
<EuiPageHeader></EuiPageHeader>
<EuiPageContent>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
Expand Down
3 changes: 2 additions & 1 deletion public/apps/configuration/panels/test/get-started.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import { shallow } from 'enzyme';
import React from 'react';
import { EuiSteps } from '@elastic/eui';
import { Action, ResourceType } from '../../types';
import { Action } from '../../types';
import { ResourceType } from '../../../../../common';
import { buildHashUrl } from '../../utils/url-builder';
import { GetStarted } from '../get-started';

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

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

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

describe('User list', () => {
describe('dictView', () => {
Expand Down
3 changes: 2 additions & 1 deletion public/apps/configuration/panels/user-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ 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, ResourceType } from '../types';
import { Action } from '../types';
import { ResourceType } from '../../../../common';
import { EMPTY_FIELD_VALUE } from '../ui-constants';
import { useContextMenuState } from '../utils/context-menu';
import { useDeleteConfirmState } from '../utils/delete-confirm-modal-utils';
Expand Down
11 changes: 0 additions & 11 deletions public/apps/configuration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ export type ComboBoxOptions = EuiComboBoxOptionOption[];

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

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

export enum Action {
view = 'view',
create = 'create',
Expand Down
3 changes: 2 additions & 1 deletion public/apps/configuration/utils/url-builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* permissions and limitations under the License.
*/

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

/**
* Build hash based url, encode the resourceId part
Expand Down

0 comments on commit 1f55360

Please sign in to comment.