5899 display a banner to alert users which need to reconnect their account (#6301)

Closes #5899

<img width="1280" alt="Index - banner"
src="https://github.com/twentyhq/twenty/assets/71827178/313cf20d-eb34-496a-8c7c-7589fbd55954">

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
bosiraphael
2024-07-27 18:34:52 +02:00
committed by GitHub
parent d0db3b765f
commit 6728e40256
48 changed files with 910 additions and 147 deletions

View File

@ -3,6 +3,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { BillingModule } from 'src/engine/core-modules/billing/billing.module';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { UserVarsModule } from 'src/engine/core-modules/user/user-vars/user-vars.module';
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity';
import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module';
import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module';
@ -51,6 +52,7 @@ import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/sta
BillingModule,
RefreshAccessTokenManagerModule,
CalendarEventParticipantManagerModule,
UserVarsModule,
],
providers: [
CalendarChannelSyncStatusService,

View File

@ -1,5 +1,6 @@
import { Injectable } from '@nestjs/common';
import { UserVarsService } from 'src/engine/core-modules/user/user-vars/services/user-vars.service';
import { CacheStorageService } from 'src/engine/integrations/cache-storage/cache-storage.service';
import { InjectCacheStorage } from 'src/engine/integrations/cache-storage/decorators/cache-storage.decorator';
import { CacheStorageNamespace } from 'src/engine/integrations/cache-storage/types/cache-storage-namespace.enum';
@ -9,6 +10,10 @@ import {
CalendarChannelSyncStatus,
CalendarChannelWorkspaceEntity,
} from 'src/modules/calendar/common/standard-objects/calendar-channel.workspace-entity';
import {
ConnectedAccountKeyValueType,
ConnectedAccountKeys,
} from 'src/modules/connected-account/types/connected-account-key-value.type';
@Injectable()
export class CalendarChannelSyncStatusService {
@ -16,6 +21,7 @@ export class CalendarChannelSyncStatusService {
private readonly twentyORMManager: TwentyORMManager,
@InjectCacheStorage(CacheStorageNamespace.Calendar)
private readonly cacheStorage: CacheStorageService,
private readonly userVarsService: UserVarsService<ConnectedAccountKeyValueType>,
) {}
public async scheduleFullCalendarEventListFetch(calendarChannelId: string) {
@ -157,5 +163,55 @@ export class CalendarChannelSyncStatusService {
syncStatus: CalendarChannelSyncStatus.FAILED_INSUFFICIENT_PERMISSIONS,
syncStage: CalendarChannelSyncStage.FAILED,
});
await this.addToAccountsToReconnect(calendarChannelId, workspaceId);
}
private async addToAccountsToReconnect(
calendarChannelId: string,
workspaceId: string,
) {
const calendarChannelRepository =
await this.twentyORMManager.getRepository<CalendarChannelWorkspaceEntity>(
'calendarChannel',
);
const calendarChannel = await calendarChannelRepository.findOne({
where: {
id: calendarChannelId,
},
relations: {
connectedAccount: {
accountOwner: true,
},
},
});
if (!calendarChannel) {
return;
}
const userId = calendarChannel.connectedAccount.accountOwner.userId;
const connectedAccountId = calendarChannel.connectedAccount.id;
const accountsToReconnect =
(await this.userVarsService.get({
userId,
workspaceId,
key: ConnectedAccountKeys.ACCOUNTS_TO_RECONNECT,
})) ?? [];
if (accountsToReconnect.includes(connectedAccountId)) {
return;
}
accountsToReconnect.push(connectedAccountId);
await this.userVarsService.set({
userId,
workspaceId,
key: ConnectedAccountKeys.ACCOUNTS_TO_RECONNECT,
value: accountsToReconnect,
});
}
}