[permissions] Add permissions check layer in entityManager (#11818)
First and main step of https://github.com/twentyhq/core-team-issues/issues/747 We are implementing a permission check layer in our custom WorkspaceEntityManager by overriding all the db-executing methods (this PR only overrides some as a POC, the rest will be done in the next PR). Our custom repositories call entity managers under the hood to interact with the db so this solves the repositories case too. This is still behind the feature flag IsPermissionsV2Enabled. In the next PR - finish overriding all the methods required in WorkspaceEntityManager - add tests
This commit is contained in:
@ -4,7 +4,7 @@ import axios, { AxiosInstance } from 'axios';
|
||||
import uniqBy from 'lodash.uniqby';
|
||||
import { TWENTY_COMPANIES_BASE_URL } from 'twenty-shared/constants';
|
||||
import { ConnectedAccountProvider } from 'twenty-shared/types';
|
||||
import { DeepPartial, EntityManager, ILike } from 'typeorm';
|
||||
import { DeepPartial, ILike } from 'typeorm';
|
||||
|
||||
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
@ -37,7 +37,6 @@ export class CreateCompanyService {
|
||||
async createCompanies(
|
||||
companies: CompanyToCreate[],
|
||||
workspaceId: string,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<{
|
||||
[domainName: string]: string;
|
||||
}> {
|
||||
@ -63,12 +62,9 @@ export class CreateCompanyService {
|
||||
}));
|
||||
|
||||
// Find existing companies
|
||||
const existingCompanies = await companyRepository.find(
|
||||
{
|
||||
where: conditions,
|
||||
},
|
||||
transactionManager,
|
||||
);
|
||||
const existingCompanies = await companyRepository.find({
|
||||
where: conditions,
|
||||
});
|
||||
const existingCompanyIdsMap = this.createCompanyMap(existingCompanies);
|
||||
|
||||
// Filter out companies that already exist
|
||||
@ -87,10 +83,8 @@ export class CreateCompanyService {
|
||||
}
|
||||
|
||||
// Retrieve the last company position
|
||||
let lastCompanyPosition = await this.getLastCompanyPosition(
|
||||
companyRepository,
|
||||
transactionManager,
|
||||
);
|
||||
let lastCompanyPosition =
|
||||
await this.getLastCompanyPosition(companyRepository);
|
||||
const newCompaniesData = await Promise.all(
|
||||
newCompaniesToCreate.map((company) =>
|
||||
this.prepareCompanyData(company, ++lastCompanyPosition),
|
||||
@ -156,12 +150,10 @@ export class CreateCompanyService {
|
||||
|
||||
private async getLastCompanyPosition(
|
||||
companyRepository: WorkspaceRepository<CompanyWorkspaceEntity>,
|
||||
transactionManager?: EntityManager,
|
||||
): Promise<number> {
|
||||
const lastCompanyPosition = await companyRepository.maximum(
|
||||
'position',
|
||||
undefined,
|
||||
transactionManager,
|
||||
);
|
||||
|
||||
return lastCompanyPosition ?? 0;
|
||||
|
||||
Reference in New Issue
Block a user