feat: workflow agent node permissions tab (#16092)
This commit is contained in:
+36
@@ -1,6 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { In, IsNull, Not, Repository } from 'typeorm';
|
||||
|
||||
import {
|
||||
@@ -174,4 +175,39 @@ export class AiAgentRoleService {
|
||||
roleToAssignIsSameAsCurrentRole: Boolean(existingRoleTarget),
|
||||
};
|
||||
}
|
||||
|
||||
public async deleteAgentOnlyRoleIfUnused({
|
||||
roleId,
|
||||
roleTargetId,
|
||||
workspaceId,
|
||||
}: {
|
||||
roleId: string;
|
||||
roleTargetId: string;
|
||||
workspaceId: string;
|
||||
}): Promise<void> {
|
||||
const role = await this.roleRepository.findOne({
|
||||
where: { id: roleId, workspaceId },
|
||||
});
|
||||
|
||||
if (
|
||||
!isDefined(role) ||
|
||||
!role.canBeAssignedToAgents ||
|
||||
role.canBeAssignedToUsers ||
|
||||
role.canBeAssignedToApiKeys
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const remainingAssignments = await this.roleTargetsRepository.count({
|
||||
where: {
|
||||
roleId,
|
||||
workspaceId,
|
||||
id: Not(roleTargetId),
|
||||
},
|
||||
});
|
||||
|
||||
if (remainingAssignments === 0) {
|
||||
await this.roleRepository.delete({ id: roleId, workspaceId });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user