Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix for getting correct senstive settings #4908

Merged
merged 6 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export function useBotOperations() {
dispatcherState
);

const handleBotStart = async (projectId: string, config: IPublishConfig, botBuildRequired: boolean) => {
const handleBotStart = async (
projectId: string,
config: IPublishConfig,
sensitiveSettings,
botBuildRequired: boolean
) => {
resetBotRuntimeError(projectId);
setBotStatus(projectId, BotStatus.pending);
if (botBuildRequired) {
Expand All @@ -36,20 +41,20 @@ export function useBotOperations() {
}
} else {
// Regex recognizer
await botRuntimeOperations?.startBot(projectId);
await botRuntimeOperations?.startBot(projectId, sensitiveSettings);
}
};

const startRootBot = async (skipBuild?: boolean) => {
setProjectsToTrack([]);
await updateSettingsForSkillsWithoutManifest();
const { projectId, configuration, buildRequired, status } = builderEssentials[0];
const { projectId, configuration, buildRequired, status, sensitiveSettings } = builderEssentials[0];
if (status !== BotStatus.connected) {
let isBuildRequired = buildRequired;
if (skipBuild) {
isBuildRequired = false;
}
handleBotStart(projectId, configuration, isBuildRequired);
handleBotStart(projectId, configuration, sensitiveSettings, isBuildRequired);
}
};

Expand All @@ -72,8 +77,8 @@ export function useBotOperations() {
setProjectsToTrack(trackProjects);
for (const botBuildConfig of skillsBots) {
if (botBuildConfig.status !== BotStatus.connected) {
const { projectId, configuration, buildRequired } = botBuildConfig;
await handleBotStart(projectId, configuration, buildRequired);
const { projectId, configuration, buildRequired, sensitiveSettings } = botBuildConfig;
await handleBotStart(projectId, configuration, sensitiveSettings, buildRequired);
}
}
};
Expand All @@ -93,7 +98,7 @@ export function useBotOperations() {
if (skipBuild) {
isBuildRequired = false;
}
handleBotStart(projectId, botData?.configuration, isBuildRequired);
handleBotStart(projectId, botData?.configuration, botData.sensitiveSettings, isBuildRequired);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,22 @@ describe('useBotOperations', () => {
result.current.startSingleBot(state.skillId);
});
expect(mocks.resetBotRuntimeError).toHaveBeenLastCalledWith(state.skillId);
expect(mocks.publishToTarget).toHaveBeenLastCalledWith(state.skillId, defaultPublishConfig, { comment: '' }, {});
expect(mocks.publishToTarget).toHaveBeenLastCalledWith(
state.skillId,
defaultPublishConfig,
{ comment: '' },
{
MicrosoftAppPassword: '',
luis: {
authoringKey: '',
endpointKey: '',
},
qna: {
endpointKey: '',
subscriptionKey: '',
},
}
);
});

it('should stop a single bot', async () => {
Expand Down
6 changes: 3 additions & 3 deletions Composer/packages/client/src/pages/publish/Publish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { useRecoilValue } from 'recoil';
import { Toolbar, IToolbarItem } from '@bfc/ui-shared';

import { LeftRightSplit } from '../../components/Split/LeftRightSplit';
import settingsStorage from '../../utils/dialogSettingStorage';
import { projectContainer } from '../design/styles';
import {
dispatcherState,
Expand All @@ -24,6 +23,7 @@ import {
} from '../../recoilModel';
import { navigateTo } from '../../utils/navigation';
import { OpenConfirmModal } from '../../components/Modal/ConfirmDialog';
import { getSensitiveProperties } from '../../recoilModel/dispatchers/utils/project';

import { TargetList } from './targetList';
import { PublishDialog } from './publishDialog';
Expand Down Expand Up @@ -331,7 +331,7 @@ const Publish: React.FC<RouteComponentProps<{ projectId: string; targetName?: st

const rollbackToVersion = useMemo(
() => async (version) => {
const sensitiveSettings = settingsStorage.get(projectId);
const sensitiveSettings = getSensitiveProperties(settings);
await rollbackToVersionDispatcher(projectId, selectedTarget, version.id, sensitiveSettings);
},
[projectId, selectedTarget]
Expand All @@ -344,7 +344,7 @@ const Publish: React.FC<RouteComponentProps<{ projectId: string; targetName?: st
if (settings.qna && Object(settings.qna).subscriptionKey) {
await setQnASettings(projectId, Object(settings.qna).subscriptionKey);
}
const sensitiveSettings = settingsStorage.get(projectId);
const sensitiveSettings = getSensitiveProperties(settings);
await publishToTarget(projectId, selectedTarget, { comment: comment }, sensitiveSettings);

// update the target with a lastPublished date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import { stringify } from 'query-string';
import { CallbackInterface } from 'recoil';
import { v4 as uuid } from 'uuid';
import isEmpty from 'lodash/isEmpty';
import get from 'lodash/get';
import set from 'lodash/set';

import { BotStatus, QnABotTemplateId } from '../../../constants';
import settingStorage from '../../../utils/dialogSettingStorage';
Expand Down Expand Up @@ -84,7 +82,6 @@ import { undoHistoryState } from '../../undo/history';
import UndoHistory from '../../undo/undoHistory';
import { logMessage, setError } from '../shared';
import { setRootBotSettingState } from '../setting';
import settingsStorage from '../../../utils/dialogSettingStorage';

import { crossTrainConfigState } from './../../atoms/botState';
import { recognizersSelectorFamily } from './../../selectors/recognizers';
Expand Down Expand Up @@ -153,32 +150,24 @@ export const mergePropertiesManagedByRootBot = (projectId: string, rootBotProjec
const mergedSettings = cloneDeep(settings);
if (localSetting) {
for (const property of RootBotManagedProperties) {
const rootValue = get(localSetting, property, {}).root;
const rootValue = objectGet(localSetting, property, {}).root;
if (projectId === rootBotProjectId) {
objectSet(mergedSettings, property, rootValue ?? '');
}
if (projectId !== rootBotProjectId) {
const skillValue = get(localSetting, property, {})[projectId];
const skillValue = objectGet(localSetting, property, {})[projectId];
objectSet(mergedSettings, property, skillValue ?? '');
}
}
}
return mergedSettings;
};

export const getSensitiveProperties = (projectId: string, rootBotProjectId: string) => {
const rootBotLocalStorage = settingsStorage.get(rootBotProjectId);
const skillBotLocalStorage = settingsStorage.get(projectId);
export const getSensitiveProperties = (settings: DialogSetting) => {
const sensitiveProperties = {};
for (const property of SensitiveProperties) {
if (!RootBotManagedProperties.includes(property)) {
const value = get(skillBotLocalStorage, property, '');
set(sensitiveProperties, property, value);
} else {
const groupValue = get(rootBotLocalStorage, property, {});
const value = get(groupValue, projectId, '');
set(sensitiveProperties, property, value);
}
const value = objectGet(settings, property, '');
objectSet(sensitiveProperties, property, value);
}
return sensitiveProperties;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { defaultPublishConfig } from '@bfc/shared';
import { selector, selectorFamily } from 'recoil';
import { checkForPVASchema } from '@bfc/shared';

import settingsStorage from '../../utils/dialogSettingStorage';
import { BotStatus } from '../../constants';
import { isAbsHosted } from '../../utils/envUtil';
import {
Expand All @@ -19,9 +18,10 @@ import {
import { Dispatcher } from '../dispatchers';
import { dispatcherState } from '../DispatcherWrapper';
import { isBuildConfigComplete as isBuildConfigurationComplete, needsBuild } from '../../utils/buildUtil';
import { getSensitiveProperties } from '../dispatchers/utils/project';

import { validateDialogsSelectorFamily } from './validatedDialogs';
import { localBotsWithoutErrorsSelector } from './project';
import { localBotsWithoutErrorsSelector, rootBotProjectIdSelector } from './project';

export const trackBotStatusesSelector = selectorFamily({
key: 'trackBotStatusesSelector',
Expand Down Expand Up @@ -73,6 +73,7 @@ export const buildConfigurationSelector = selector({
key: 'buildConfigurationSelector',
get: ({ get }) => {
const localProjects = get(localBotsWithoutErrorsSelector);
const rootBotId = get(rootBotProjectIdSelector);

return localProjects
.filter((projectId: string) => {
Expand All @@ -84,7 +85,12 @@ export const buildConfigurationSelector = selector({
const result = get(buildEssentialsSelector(projectId));
const name = get(botDisplayNameState(projectId));
const dialogs = get(validateDialogsSelectorFamily(projectId));
return { ...result, name, dialogs };
const settings = get(settingsState(projectId));
let sensitiveSettings = {};
if (rootBotId) {
sensitiveSettings = getSensitiveProperties(settings);
}
return { ...result, name, dialogs, sensitiveSettings };
});
},
});
Expand Down Expand Up @@ -113,9 +119,8 @@ const botRuntimeAction = (dispatcher: Dispatcher) => {
await dispatcher.build(projectId, config.luis, config.qna);
}
},
startBot: async (projectId: string) => {
startBot: async (projectId: string, sensitiveSettings) => {
dispatcher.setBotStatus(projectId, BotStatus.reloading);
const sensitiveSettings = settingsStorage.get(projectId);
await dispatcher.publishToTarget(projectId, defaultPublishConfig, { comment: '' }, sensitiveSettings);
},
stopBot: async (projectId: string) => {
Expand Down