Skip to content

Commit

Permalink
remove useraccess
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <[email protected]>
  • Loading branch information
raintygao committed Jun 4, 2024
1 parent 8c45d5a commit 2fc6e99
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 49 deletions.
3 changes: 1 addition & 2 deletions opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
"opensearchDashboardsUtils"
],
"optionalPlugins": [
"securityDashboards",
"dataSource",
"dataSourceManagement"
],
"configPath": [
"assistant"
"assistant"
]
}
5 changes: 0 additions & 5 deletions public/chat_header_button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ describe('<HeaderChatButton />', () => {
render(
<HeaderChatButton
application={applicationStart}
userHasAccess={true}
messageRenderers={{}}
actionExecutors={{}}
assistantActions={{} as AssistantActions}
Expand Down Expand Up @@ -142,7 +141,6 @@ describe('<HeaderChatButton />', () => {
render(
<HeaderChatButton
application={applicationServiceMock.createStartContract()}
userHasAccess={true}
messageRenderers={{}}
actionExecutors={{}}
assistantActions={{} as AssistantActions}
Expand All @@ -166,7 +164,6 @@ describe('<HeaderChatButton />', () => {
render(
<HeaderChatButton
application={applicationServiceMock.createStartContract()}
userHasAccess={true}
messageRenderers={{}}
actionExecutors={{}}
assistantActions={{} as AssistantActions}
Expand All @@ -187,7 +184,6 @@ describe('<HeaderChatButton />', () => {
render(
<HeaderChatButton
application={applicationServiceMock.createStartContract()}
userHasAccess={false}
messageRenderers={{}}
actionExecutors={{}}
assistantActions={{} as AssistantActions}
Expand All @@ -201,7 +197,6 @@ describe('<HeaderChatButton />', () => {
render(
<HeaderChatButton
application={applicationServiceMock.createStartContract()}
userHasAccess={false}
messageRenderers={{}}
actionExecutors={{}}
assistantActions={{} as AssistantActions}
Expand Down
9 changes: 1 addition & 8 deletions public/chat_header_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { MountPointPortal } from '../../../src/plugins/opensearch_dashboards_rea

interface HeaderChatButtonProps {
application: ApplicationStart;
userHasAccess: boolean;
messageRenderers: Record<string, MessageRenderer>;
actionExecutors: Record<string, ActionExecutor>;
assistantActions: AssistantActions;
Expand Down Expand Up @@ -74,7 +73,6 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
flyoutFullScreen,
setFlyoutVisible,
setFlyoutComponent,
userHasAccess: props.userHasAccess,
messageRenderers: props.messageRenderers,
actionExecutors: props.actionExecutors,
currentAccount: props.currentAccount,
Expand All @@ -92,7 +90,6 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
flyoutFullScreen,
selectedTabId,
preSelectedTabId,
props.userHasAccess,
props.messageRenderers,
props.actionExecutors,
props.currentAccount,
Expand Down Expand Up @@ -157,9 +154,6 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
}, []);

useEffect(() => {
if (!props.userHasAccess) {
return;
}
const onGlobalMouseUp = (e: KeyboardEvent) => {
if (e.ctrlKey && e.key === '/') {
inputRef.current?.focus();
Expand All @@ -170,7 +164,7 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
return () => {
document.removeEventListener('keydown', onGlobalMouseUp);
};
}, [props.userHasAccess]);
}, []);

useEffect(() => {
const handleSuggestion = (event: { suggestion: string }) => {
Expand Down Expand Up @@ -235,7 +229,6 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
)}
</span>
}
disabled={!props.userHasAccess}
/>
<ChatContext.Provider value={chatContextValue}>
<ChatStateProvider>
Expand Down
1 change: 0 additions & 1 deletion public/contexts/__tests__/chat_context.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('useChatContext', () => {
flyoutFullScreen: true,
setFlyoutVisible: jest.fn(),
setFlyoutComponent: jest.fn(),
userHasAccess: true,
messageRenderers: {},
actionExecutors: {},
currentAccount: { username: 'foo', tenant: '' },
Expand Down
1 change: 0 additions & 1 deletion public/contexts/chat_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface IChatContext {
flyoutFullScreen: boolean;
setFlyoutVisible: React.Dispatch<React.SetStateAction<boolean>>;
setFlyoutComponent: React.Dispatch<React.SetStateAction<React.ReactNode | null>>;
userHasAccess: boolean;
messageRenderers: Record<string, MessageRenderer>;
actionExecutors: Record<string, ActionExecutor>;
currentAccount?: UserAccount;
Expand Down
1 change: 0 additions & 1 deletion public/hooks/use_chat_actions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ describe('useChatActions hook', () => {
setInteractionId: setInteractionIdMock,
flyoutVisible: false,
flyoutFullScreen: false,
userHasAccess: false,
messageRenderers: {},
currentAccount: {
username: '',
Expand Down
26 changes: 1 addition & 25 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,6 @@ export class AssistantPlugin
const messageRenderers: Record<string, MessageRenderer> = {};
const actionExecutors: Record<string, ActionExecutor> = {};
const assistantActions: AssistantActions = {} as AssistantActions;
/**
* Returns {@link UserAccountResponse}. Provides default roles and user
* name if security plugin call fails.
*/
const getAccount: () => Promise<UserAccountResponse> = (() => {
let account: UserAccountResponse;
return async () => {
if (setupDeps.securityDashboards === undefined)
return { data: { roles: ['all_access'], user_name: 'dashboards_user' } };
if (account === undefined) {
account = await core.http
.get<UserAccountResponse>('/api/v1/configuration/account')
.catch((e) => {
console.error(`Failed to request user account information: ${String(e.body || e)}`);
return { data: { roles: [], user_name: '' } };
});
}
return account;
};
})();
const checkAccess = (account: Awaited<ReturnType<typeof getAccount>>) =>
account.data.roles.some((role) => ['all_access', 'assistant_user'].includes(role));

const dataSourceSetupResult = this.dataSourceService.setup({
uiSettings: core.uiSettings,
Expand All @@ -115,7 +93,7 @@ export class AssistantPlugin
conversations: new ConversationsService(coreStart.http, this.dataSourceService),
dataSource: this.dataSourceService,
});
const account = await getAccount();
const account = { data: { user_name: '', user_requested_tenant: '' } };
const username = account.data.user_name;
const tenant = account.data.user_requested_tenant ?? '';
this.incontextInsightRegistry?.setIsEnabled(this.config.incontextInsight.enabled);
Expand All @@ -126,7 +104,6 @@ export class AssistantPlugin
<CoreContext.Provider>
<HeaderChatButton
application={coreStart.application}
userHasAccess={checkAccess(account)}
messageRenderers={messageRenderers}
actionExecutors={actionExecutors}
assistantActions={assistantActions}
Expand All @@ -152,7 +129,6 @@ export class AssistantPlugin
actionExecutors[actionType] = execute;
},
chatEnabled: () => this.config.chat.enabled,
userHasAccess: async () => await getAccount().then(checkAccess),
assistantActions,
registerIncontextInsight: this.incontextInsightRegistry.register.bind(
this.incontextInsightRegistry
Expand Down
2 changes: 1 addition & 1 deletion public/tabs/chat/chat_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const ChatPage: React.FC<ChatPageProps> = (props) => {
<EuiSpacer size="xs" />
<ChatInputControls
loading={chatState.llmResponding}
disabled={messagesLoading || chatState.llmResponding || !chatContext.userHasAccess}
disabled={messagesLoading || chatState.llmResponding}
/>
<EuiSpacer size="s" />
</EuiFlyoutFooter>
Expand Down
5 changes: 0 additions & 5 deletions public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export interface AssistantPluginStartDependencies {

export interface AssistantPluginSetupDependencies {
embeddable: EmbeddableSetup;
securityDashboards?: {};
dataSourceManagement?: DataSourceManagementPluginSetup;
}

Expand All @@ -54,10 +53,6 @@ export interface AssistantSetup {
* Returns true if chat UI is enabled.
*/
chatEnabled: () => boolean;
/**
* Returns true if current user has permission to use assistant features.
*/
userHasAccess: () => Promise<boolean>;
assistantActions: Omit<AssistantActions, 'executeAction'>;
registerIncontextInsight: IncontextInsightRegistry['register'];
renderIncontextInsight: (component: React.ReactNode) => React.ReactNode;
Expand Down

0 comments on commit 2fc6e99

Please sign in to comment.