Skip to content

Commit

Permalink
fix(core.gbapp): Auto-publish fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Oct 27, 2020
1 parent 532fd51 commit 398b95d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
27 changes: 17 additions & 10 deletions packages/admin.gbapp/dialogs/AdminDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ export class AdminDialog extends IGBDialog {
if (AdminDialog.isIntentYes(locale, step.result)) {
let from = step.context.activity.from.id;

let canPublish = AdminDialog.canPublish(min, from);
let canPublish: Boolean;
if (step.activeDialog.state.options.firstTime) {
canPublish = true;
} else {
canPublish = AdminDialog.canPublish(min, from);
}

if (!canPublish) {
await step.beginDialog('/admin-auth');
Expand Down Expand Up @@ -277,7 +282,7 @@ export class AdminDialog extends IGBDialog {
if (packageName.indexOf('.') !== -1) {
cmd1 = `deployPackage ${process.env.STORAGE_SITE} /${process.env.STORAGE_LIBRARY}/${botId}.gbai/${packageName}`;
} else {
cmd1 = `deployPackage ${packageName}`;
cmd1 = `deployPackage ${packageName}`;
}
if ((await (deployer as any).getStoragePackageByName(min.instance.instanceId, packageName)) !== null) {
const cmd2 = `undeployPackage ${packageName}`;
Expand Down Expand Up @@ -311,14 +316,16 @@ export class AdminDialog extends IGBDialog {
* @param phone Phone number to check (eg.: +5521900002233)
*/
public static canPublish(min: GBMinInstance, phone: string): Boolean {
const list = process.env.SECURITY_CAN_PUBLISH.split(';');
let result = list.includes(phone);

if (!result && min.instance.params) {
const params = JSON.parse(min.instance.params);
return list.includes(params['Can Publish']);
if (process.env.SECURITY_CAN_PUBLISH !== undefined) {
const list = process.env.SECURITY_CAN_PUBLISH.split(';');
let result = list.includes(phone);

if (!result && min.instance.params) {
const params = JSON.parse(min.instance.params);
return list.includes(params['Can Publish']);
}
return result;
}
return result;
}

private static setupSecurityDialogs(min: GBMinInstance) {
Expand Down Expand Up @@ -353,7 +360,7 @@ export class AdminDialog extends IGBDialog {
min.adminService.setValue(min.instance.instanceId, 'AntiCSRFAttackState', state);

const url = `https://login.microsoftonline.com/${
min.instance.authenticatorTenant
step.activeDialog.state.authenticatorTenant
}/oauth2/authorize?client_id=${min.instance.marketplaceId}&response_type=code&redirect_uri=${urlJoin(
min.instance.botEndpoint,
min.instance.botId,
Expand Down
4 changes: 2 additions & 2 deletions packages/azuredeployer.gbapp/services/AzureDeployerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
keys = await this.cognitiveClient.accounts.listKeys(name, nlp.name);
const nlpAppId = await this.createNLPService(name, name, instance.cloudLocation, culture, instance.nlpAuthoringKey);

instance.nlpEndpoint = urlJoin(nlp.endpoint, 'apps');
instance.nlpEndpoint = nlp.endpoint;
instance.nlpKey = keys.key1;
instance.nlpAppId = nlpAppId;

Expand All @@ -388,7 +388,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
GBLog.info(`Deploying Bot Storage...`);
const administratorLogin = `sa${GBAdminService.getRndReadableIdentifier()}`;
const administratorPassword = GBAdminService.getRndPassword();
const storageServer = `${name.toLowerCase()}-storage-server2`;
const storageServer = `${name.toLowerCase()}-storage-server`;
const storageName = `${name}-storage`;
await this.createStorageServer(name, storageServer, administratorLogin,
administratorPassword, storageServer, instance.cloudLocation
Expand Down
18 changes: 9 additions & 9 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,10 @@ export class GBMinService {
'web',
member.name
);
if (step.context.activity.channelId === "msteams"){
persistedUser.conversationReference = JSON.stringify(TurnContext.getConversationReference(context.activity));
if (step.context.activity.channelId === 'msteams') {
persistedUser.conversationReference = JSON.stringify(
TurnContext.getConversationReference(context.activity)
);
await persistedUser.save();
}
const analytics = new AnalyticsService();
Expand Down Expand Up @@ -753,14 +755,12 @@ export class GBMinService {
} else if (context.activity.text.startsWith('{"title"')) {
await step.beginDialog('/menu', JSON.parse(context.activity.text));
// Otherwise, continue to the active dialog in the stack.
} else if (!(await this.deployer.getStoragePackageByName(min.instance.instanceId, `${min.instance.botId}.gbkb`))) {
await step.context.sendActivity(
`Oi, ainda não possuo pacotes de conhecimento publicados. Por favor, aguarde alguns segundos enquanto eu auto-publico alguns pacotes.`
);
await step.beginDialog('/publish', { confirm: true, firstTime: true });
} else {
if (!(await this.deployer.getStoragePackageByName(min.instance.instanceId, `${min.instance.botId}.gbkb`))) {
await step.context.sendActivity(
`Oi, ainda não possuo pacotes de conhecimento publicados. Por favor, aguarde alguns segundos enquanto eu auto-publico alguns pacotes.`
);
return await step.beginDialog('/publish', { confirm: true });
}

if (step.activeDialog !== undefined) {
await step.continueDialog();
} else {
Expand Down

0 comments on commit 398b95d

Please sign in to comment.