mirror of
https://github.com/lingble/twenty.git
synced 2025-11-03 22:27:57 +00:00
@@ -1,12 +1,12 @@
|
|||||||
import { ForbiddenException } from '@nestjs/common';
|
import { ForbiddenException } from '@nestjs/common';
|
||||||
|
|
||||||
import groupBy from 'lodash.groupby';
|
import { In } from 'typeorm';
|
||||||
import { Any } from 'typeorm';
|
|
||||||
|
|
||||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||||
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
import { MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity';
|
||||||
|
import { MessageChannelVisibility } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||||
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository';
|
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository';
|
||||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||||
|
|
||||||
@@ -20,32 +20,12 @@ export class CanAccessMessageThreadService {
|
|||||||
public async canAccessMessageThread(
|
public async canAccessMessageThread(
|
||||||
userId: string,
|
userId: string,
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
messageChannelMessageAssociations: any[],
|
messageChannelMessageAssociations: MessageChannelMessageAssociationWorkspaceEntity[],
|
||||||
) {
|
) {
|
||||||
const messageChannelRepository =
|
const messageChannelIds = messageChannelMessageAssociations.map(
|
||||||
await this.twentyORMManager.getRepository<MessageChannelWorkspaceEntity>(
|
(association) => association.messageChannelId,
|
||||||
'messageChannel',
|
|
||||||
);
|
|
||||||
const messageChannels = await messageChannelRepository.find({
|
|
||||||
select: ['id', 'visibility'],
|
|
||||||
where: {
|
|
||||||
id: Any(
|
|
||||||
messageChannelMessageAssociations.map(
|
|
||||||
(association) => association.messageChannelId,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const messageChannelsGroupByVisibility = groupBy(
|
|
||||||
messageChannels,
|
|
||||||
(channel) => channel.visibility,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (messageChannelsGroupByVisibility.SHARE_EVERYTHING) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentWorkspaceMember =
|
const currentWorkspaceMember =
|
||||||
await this.workspaceMemberRepository.getByIdOrFail(userId, workspaceId);
|
await this.workspaceMemberRepository.getByIdOrFail(userId, workspaceId);
|
||||||
|
|
||||||
@@ -55,17 +35,28 @@ export class CanAccessMessageThreadService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const connectedAccounts = await connectedAccountRepository.find({
|
const connectedAccounts = await connectedAccountRepository.find({
|
||||||
select: ['id'],
|
select: {
|
||||||
where: {
|
id: true,
|
||||||
messageChannels: Any(messageChannels.map((channel) => channel.id)),
|
|
||||||
accountOwnerId: currentWorkspaceMember.id,
|
|
||||||
},
|
},
|
||||||
|
where: [
|
||||||
|
{
|
||||||
|
messageChannels: {
|
||||||
|
id: In(messageChannelIds),
|
||||||
|
visibility: MessageChannelVisibility.SHARE_EVERYTHING,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
messageChannels: {
|
||||||
|
id: In(messageChannelIds),
|
||||||
|
},
|
||||||
|
accountOwnerId: currentWorkspaceMember.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
take: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (connectedAccounts.length > 0) {
|
if (connectedAccounts.length === 0) {
|
||||||
return;
|
throw new ForbiddenException();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ForbiddenException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user