Skip to content

Commit

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

* fix Cannot find module

Signed-off-by: Yulong Ruan <[email protected]>

* fix prettier error

Signed-off-by: Yulong Ruan <[email protected]>

* fix failed tests

Signed-off-by: Yulong Ruan <[email protected]>

---------

Signed-off-by: Yulong Ruan <[email protected]>
Co-authored-by: Craig Perkins <[email protected]>
  • Loading branch information
ruanyl and cwperks authored Jan 3, 2024
1 parent 9c3ba49 commit 09b2f59
Show file tree
Hide file tree
Showing 33 changed files with 71 additions and 60 deletions.
12 changes: 12 additions & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ 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: 2 additions & 1 deletion public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ 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, 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
3 changes: 2 additions & 1 deletion public/apps/configuration/panels/service-account-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ 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, 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 { ExternalLink, tableItemsUIProps, truncatedListView } from '../utils/display-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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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/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
12 changes: 0 additions & 12 deletions public/apps/configuration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ 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: 2 additions & 1 deletion public/apps/configuration/utils/internal-user-list-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
API_ENDPOINT_INTERNALUSERS,
API_ENDPOINT_SERVICEACCOUNTS,
} from '../constants';
import { DataObject, InternalUser, ObjectsMessage, ResourceType } from '../types';
import { DataObject, InternalUser, ObjectsMessage } from '../types';
import { ResourceType } from '../../../../common';
import { httpDelete, httpGet } from './request-utils';
import { getResourceUrl } from './resource-utils';

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
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 '../../public/apps/configuration/types';
import { ResourceType } from '../../common';

// 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 09b2f59

Please sign in to comment.