Fix-issue-370 (#9996)
Fixes the issue from introduced when alowing gmail and outlook. fixes https://github.com/twentyhq/core-team-issues/issues/370
This commit is contained in:
@ -26,6 +26,16 @@ export class MicrosoftAPIsOauthExchangeCodeForTokenGuard extends AuthGuard(
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const state = JSON.parse(request.query.state);
|
||||
|
||||
if (
|
||||
!this.environmentService.get('MESSAGING_PROVIDER_MICROSOFT_ENABLED') &&
|
||||
!this.environmentService.get('CALENDAR_PROVIDER_MICROSOFT_ENABLED')
|
||||
) {
|
||||
throw new AuthException(
|
||||
'Microsoft apis auth is not enabled',
|
||||
AuthExceptionCode.MICROSOFT_API_AUTH_DISABLED,
|
||||
);
|
||||
}
|
||||
|
||||
new MicrosoftAPIsOauthExchangeCodeForTokenStrategy(
|
||||
this.environmentService,
|
||||
);
|
||||
|
||||
@ -4,6 +4,10 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import {
|
||||
AuthException,
|
||||
AuthExceptionCode,
|
||||
} from 'src/engine/core-modules/auth/auth.exception';
|
||||
import { MicrosoftAPIsOauthRequestCodeStrategy } from 'src/engine/core-modules/auth/strategies/microsoft-apis-oauth-request-code.auth.strategy';
|
||||
import { TransientTokenService } from 'src/engine/core-modules/auth/token/services/transient-token.service';
|
||||
import { setRequestExtraParams } from 'src/engine/core-modules/auth/utils/google-apis-set-request-extra-params.util';
|
||||
@ -33,6 +37,16 @@ export class MicrosoftAPIsOauthRequestCodeGuard extends AuthGuard(
|
||||
let workspace: Workspace | null = null;
|
||||
|
||||
try {
|
||||
if (
|
||||
!this.environmentService.get('MESSAGING_PROVIDER_MICROSOFT_ENABLED') &&
|
||||
!this.environmentService.get('CALENDAR_PROVIDER_MICROSOFT_ENABLED')
|
||||
) {
|
||||
throw new AuthException(
|
||||
'Microsoft apis auth is not enabled',
|
||||
AuthExceptionCode.MICROSOFT_API_AUTH_DISABLED,
|
||||
);
|
||||
}
|
||||
|
||||
const request = context.switchToHttp().getRequest();
|
||||
|
||||
const { workspaceId } =
|
||||
|
||||
@ -7,6 +7,7 @@ import { v4 } from 'uuid';
|
||||
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import { getMicrosoftApisOauthScopes } from 'src/engine/core-modules/auth/utils/get-microsoft-apis-oauth-scopes';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
@ -48,6 +49,7 @@ export class MicrosoftAPIsService {
|
||||
private readonly workspaceEventEmitter: WorkspaceEventEmitter,
|
||||
@InjectRepository(ObjectMetadataEntity, 'metadata')
|
||||
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
) {}
|
||||
|
||||
async refreshMicrosoftRefreshToken(input: {
|
||||
@ -167,37 +169,42 @@ export class MicrosoftAPIsService {
|
||||
workspaceId,
|
||||
});
|
||||
|
||||
const newCalendarChannel = await calendarChannelRepository.save(
|
||||
{
|
||||
id: v4(),
|
||||
connectedAccountId: newOrExistingConnectedAccountId,
|
||||
handle,
|
||||
visibility:
|
||||
calendarVisibility || CalendarChannelVisibility.SHARE_EVERYTHING,
|
||||
},
|
||||
{},
|
||||
manager,
|
||||
);
|
||||
|
||||
const calendarChannelMetadata =
|
||||
await this.objectMetadataRepository.findOneOrFail({
|
||||
where: { nameSingular: 'calendarChannel', workspaceId },
|
||||
});
|
||||
|
||||
this.workspaceEventEmitter.emitDatabaseBatchEvent({
|
||||
objectMetadataNameSingular: 'calendarChannel',
|
||||
action: DatabaseEventAction.CREATED,
|
||||
events: [
|
||||
if (
|
||||
this.environmentService.get('CALENDAR_PROVIDER_MICROSOFT_ENABLED')
|
||||
) {
|
||||
const newCalendarChannel = await calendarChannelRepository.save(
|
||||
{
|
||||
recordId: newCalendarChannel.id,
|
||||
objectMetadata: calendarChannelMetadata,
|
||||
properties: {
|
||||
after: newCalendarChannel,
|
||||
},
|
||||
id: v4(),
|
||||
connectedAccountId: newOrExistingConnectedAccountId,
|
||||
handle,
|
||||
visibility:
|
||||
calendarVisibility ||
|
||||
CalendarChannelVisibility.SHARE_EVERYTHING,
|
||||
},
|
||||
],
|
||||
workspaceId,
|
||||
});
|
||||
{},
|
||||
manager,
|
||||
);
|
||||
|
||||
const calendarChannelMetadata =
|
||||
await this.objectMetadataRepository.findOneOrFail({
|
||||
where: { nameSingular: 'calendarChannel', workspaceId },
|
||||
});
|
||||
|
||||
this.workspaceEventEmitter.emitDatabaseBatchEvent({
|
||||
objectMetadataNameSingular: 'calendarChannel',
|
||||
action: DatabaseEventAction.CREATED,
|
||||
events: [
|
||||
{
|
||||
recordId: newCalendarChannel.id,
|
||||
objectMetadata: calendarChannelMetadata,
|
||||
properties: {
|
||||
after: newCalendarChannel,
|
||||
},
|
||||
},
|
||||
],
|
||||
workspaceId,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const updatedConnectedAccount = await connectedAccountRepository.update(
|
||||
{
|
||||
@ -291,36 +298,40 @@ export class MicrosoftAPIsService {
|
||||
}
|
||||
});
|
||||
|
||||
const messageChannels = await messageChannelRepository.find({
|
||||
where: {
|
||||
connectedAccountId: newOrExistingConnectedAccountId,
|
||||
},
|
||||
});
|
||||
|
||||
for (const messageChannel of messageChannels) {
|
||||
await this.messageQueueService.add<MessagingMessageListFetchJobData>(
|
||||
MessagingMessageListFetchJob.name,
|
||||
{
|
||||
workspaceId,
|
||||
messageChannelId: messageChannel.id,
|
||||
if (this.environmentService.get('MESSAGING_PROVIDER_MICROSOFT_ENABLED')) {
|
||||
const messageChannels = await messageChannelRepository.find({
|
||||
where: {
|
||||
connectedAccountId: newOrExistingConnectedAccountId,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
for (const messageChannel of messageChannels) {
|
||||
await this.messageQueueService.add<MessagingMessageListFetchJobData>(
|
||||
MessagingMessageListFetchJob.name,
|
||||
{
|
||||
workspaceId,
|
||||
messageChannelId: messageChannel.id,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const calendarChannels = await calendarChannelRepository.find({
|
||||
where: {
|
||||
connectedAccountId: newOrExistingConnectedAccountId,
|
||||
},
|
||||
});
|
||||
|
||||
for (const calendarChannel of calendarChannels) {
|
||||
await this.calendarQueueService.add<CalendarEventListFetchJobData>(
|
||||
CalendarEventListFetchJob.name,
|
||||
{
|
||||
calendarChannelId: calendarChannel.id,
|
||||
workspaceId,
|
||||
if (this.environmentService.get('CALENDAR_PROVIDER_MICROSOFT_ENABLED')) {
|
||||
const calendarChannels = await calendarChannelRepository.find({
|
||||
where: {
|
||||
connectedAccountId: newOrExistingConnectedAccountId,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
for (const calendarChannel of calendarChannels) {
|
||||
await this.calendarQueueService.add<CalendarEventListFetchJobData>(
|
||||
CalendarEventListFetchJob.name,
|
||||
{
|
||||
calendarChannelId: calendarChannel.id,
|
||||
workspaceId,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,4 +127,16 @@ export class ClientConfig {
|
||||
|
||||
@Field(() => [PublicFeatureFlag])
|
||||
publicFeatureFlags: PublicFeatureFlag[];
|
||||
|
||||
@Field(() => Boolean)
|
||||
isMicrosoftMessagingEnabled: boolean;
|
||||
|
||||
@Field(() => Boolean)
|
||||
isMicrosoftCalendarEnabled: boolean;
|
||||
|
||||
@Field(() => Boolean)
|
||||
isGoogleMessagingEnabled: boolean;
|
||||
|
||||
@Field(() => Boolean)
|
||||
isGoogleCalendarEnabled: boolean;
|
||||
}
|
||||
|
||||
@ -77,6 +77,18 @@ export class ClientConfigResolver {
|
||||
this.environmentService.get('DEBUG_MODE') ||
|
||||
this.environmentService.get('IS_BILLING_ENABLED'),
|
||||
publicFeatureFlags: PUBLIC_FEATURE_FLAGS,
|
||||
isMicrosoftMessagingEnabled: this.environmentService.get(
|
||||
'MESSAGING_PROVIDER_MICROSOFT_ENABLED',
|
||||
),
|
||||
isMicrosoftCalendarEnabled: this.environmentService.get(
|
||||
'CALENDAR_PROVIDER_MICROSOFT_ENABLED',
|
||||
),
|
||||
isGoogleMessagingEnabled: this.environmentService.get(
|
||||
'MESSAGING_PROVIDER_GMAIL_ENABLED',
|
||||
),
|
||||
isGoogleCalendarEnabled: this.environmentService.get(
|
||||
'CALENDAR_PROVIDER_GOOGLE_ENABLED',
|
||||
),
|
||||
};
|
||||
|
||||
return Promise.resolve(clientConfig);
|
||||
|
||||
@ -199,6 +199,22 @@ export class EnvironmentVariables {
|
||||
@ValidateIf((env) => env.AUTH_MICROSOFT_ENABLED)
|
||||
AUTH_MICROSOFT_APIS_CALLBACK_URL: string;
|
||||
|
||||
@EnvironmentVariablesMetadata({
|
||||
group: EnvironmentVariablesGroup.Authentication,
|
||||
subGroup: EnvironmentVariablesSubGroup.MicrosoftAuth,
|
||||
description: 'Is Microsoft messaging provider enabled',
|
||||
})
|
||||
@CastToBoolean()
|
||||
MESSAGING_PROVIDER_MICROSOFT_ENABLED = false;
|
||||
|
||||
@EnvironmentVariablesMetadata({
|
||||
group: EnvironmentVariablesGroup.Authentication,
|
||||
subGroup: EnvironmentVariablesSubGroup.MicrosoftAuth,
|
||||
description: 'Is Microsoft Calendar provider enabled',
|
||||
})
|
||||
@CastToBoolean()
|
||||
CALENDAR_PROVIDER_MICROSOFT_ENABLED = false;
|
||||
|
||||
@EnvironmentVariablesMetadata({
|
||||
group: EnvironmentVariablesGroup.Authentication,
|
||||
subGroup: EnvironmentVariablesSubGroup.Tokens,
|
||||
|
||||
Reference in New Issue
Block a user