Skip to content

Commit

Permalink
feat: make app inaccessible if workspaceAccessibility is No
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe committed Apr 12, 2024
1 parent dec7c4f commit ff74dda
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/plugins/opensearch_dashboards_overview/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
AppStatus,
AppNavLinkStatus,
Branding,
WorkspaceAccessibility,
} from '../../../core/public';
import {
OpenSearchDashboardsOverviewPluginSetup,
Expand Down Expand Up @@ -106,6 +107,7 @@ export class OpenSearchDashboardsOverviewPlugin
// Render the application
return renderApp(coreStart, depsStart as AppPluginStartDependencies, params);
},
workspaceAccessibility: WorkspaceAccessibility.NO,
});

if (home) {
Expand Down
16 changes: 15 additions & 1 deletion src/plugins/workspace/public/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getSelectedFeatureQuantities,
isAppAccessibleInWorkspace,
} from './utils';
import { PublicAppInfo } from '../../../core/public';
import { PublicAppInfo, WorkspaceAccessibility } from '../../../core/public';
import { AppNavLinkStatus } from '../../../core/public';

describe('workspace utils: featureMatchesConfig', () => {
Expand Down Expand Up @@ -198,4 +198,18 @@ describe('workspace utils: isAppAccessibleInWorkspace', () => {
)
).toBe(true);
});

it('An app is not accessible if its workspaceAccessibility is no', () => {
expect(
isAppAccessibleInWorkspace(
{
id: 'home',
title: 'Any app',
mount: jest.fn(),
workspaceAccessibility: WorkspaceAccessibility.NO,
},
{ id: 'workspace_id', name: 'workspace name', features: [] }
)
).toBe(false);
});
});
8 changes: 8 additions & 0 deletions src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
AppNavLinkStatus,
DEFAULT_APP_CATEGORIES,
WorkspaceObject,
WorkspaceAccessibility,
} from '../../../core/public';

/**
Expand Down Expand Up @@ -94,6 +95,13 @@ export const getSelectedFeatureQuantities = (
* Check if an app is accessible in a workspace based on the workspace configured features
*/
export function isAppAccessibleInWorkspace(app: App, workspace: WorkspaceObject) {
/**
* App is not accessible within workspace if it explicitly declare itself as workspaceAccessibility.No
*/
if (app.workspaceAccessibility === WorkspaceAccessibility.NO) {
return false;
}

/**
* When workspace has no features configured, all apps are considered to be accessible
*/
Expand Down

0 comments on commit ff74dda

Please sign in to comment.