Skip to content

Commit

Permalink
fixed bugs with org app installations
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengill committed Aug 4, 2020
1 parent 02b2e8c commit 91163fe
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,13 @@ export default class App {
this.authorize = (this.receiver as ExpressReceiver).installer!.authorize as Authorize;
this.orgAuthorize = (this.receiver as ExpressReceiver).installer!.orgAuthorize as Authorize;
} else if (authorize === undefined && orgAuthorize !== undefined && !usingOauth) {
// only supporting org installs
this.orgAuthorize = orgAuthorize;
} else if (authorize !== undefined && orgAuthorize === undefined && !usingOauth) {
// only supporting non org installs
this.authorize = authorize;
} else if (authorize !== undefined && orgAuthorize !== undefined && !usingOauth) {
// supporting both org installs and non org installs
this.authorize = authorize;
this.orgAuthorize = orgAuthorize;
} else {
Expand Down Expand Up @@ -542,7 +545,10 @@ export default class App {

let authorizeResult;
let source;
if (bodyArg.is_enterprise_install) {
if (type === IncomingEventType.Event
&& (bodyArg as SlackEventMiddlewareArgs['body']).authorizations !== undefined
&& (bodyArg as SlackEventMiddlewareArgs['body']).authorizations![0] !== undefined
&& (bodyArg as SlackEventMiddlewareArgs['body']).authorizations![0].is_enterprise_install) {
// This is an org app
// Initialize context (shallow copy to enforce object identity separation)
source = buildSource(type, conversationId, bodyArg);
Expand Down Expand Up @@ -749,10 +755,8 @@ function buildSource(
// if this makes it prettier, great! but we should probably check perf before committing to any specific optimization.

let source: AuthorizeSourceData | OrgAuthorizeSourceData;
// let source: OrgAuthorizeSourceData;
// tslint:disable:max-line-length
if (body.is_enterprise_install) {

source = {
teamId:
((type === IncomingEventType.Event || type === IncomingEventType.Command) ? (body as (SlackEventMiddlewareArgs | SlackCommandMiddlewareArgs)['body']).team_id as string :
Expand Down Expand Up @@ -780,7 +784,7 @@ function buildSource(
teamId:
((type === IncomingEventType.Event || type === IncomingEventType.Command) ? (body as (SlackEventMiddlewareArgs | SlackCommandMiddlewareArgs)['body']).team_id as string :
(type === IncomingEventType.Action || type === IncomingEventType.Options || type === IncomingEventType.ViewAction || type === IncomingEventType.Shortcut) ? (body as (SlackActionMiddlewareArgs | SlackOptionsMiddlewareArgs | SlackViewMiddlewareArgs | SlackShortcutMiddlewareArgs)['body']).team!.id as string :
assertNever(type)), // TODO: empty string for teamID is wrong, should be assertNever
assertNever(type)),
enterpriseId:
((type === IncomingEventType.Event || type === IncomingEventType.Command) ? (body as (SlackEventMiddlewareArgs | SlackCommandMiddlewareArgs)['body']).enterprise_id as string :
((type === IncomingEventType.Action || type === IncomingEventType.Options || type === IncomingEventType.ViewAction || type === IncomingEventType.Shortcut) && body.team !== null) ? (body as (SlackActionMiddlewareArgs | SlackOptionsMiddlewareArgs | SlackViewMiddlewareArgs | SlackShortcutMiddlewareArgs)['body']).team!.enterprise_id as string :
Expand All @@ -800,7 +804,6 @@ function buildSource(
};
}
// tslint:enable:max-line-length

return source;
}

Expand Down

0 comments on commit 91163fe

Please sign in to comment.