refactor(core): Remove roleId indirection (no-changelog) (#8413)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-01-24 13:38:57 +01:00
committed by GitHub
parent 1affebd85e
commit d6deceacde
139 changed files with 922 additions and 1684 deletions

View File

@@ -10,8 +10,7 @@ import * as WorkflowHelpers from '@/WorkflowHelpers';
import type { IWorkflowResponse } from '@/Interfaces';
import config from '@/config';
import { Authorized, Delete, Get, Patch, Post, Put, RestController } from '@/decorators';
import type { RoleNames } from '@db/entities/Role';
import { SharedWorkflow } from '@db/entities/SharedWorkflow';
import { SharedWorkflow, type WorkflowSharingRole } from '@db/entities/SharedWorkflow';
import { WorkflowEntity } from '@db/entities/WorkflowEntity';
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
import { TagRepository } from '@db/repositories/tag.repository';
@@ -23,7 +22,6 @@ import { ListQuery } from '@/requests';
import { WorkflowService } from './workflow.service';
import { License } from '@/License';
import { InternalHooks } from '@/InternalHooks';
import { RoleService } from '@/services/role.service';
import * as utils from '@/utils';
import { listQueryMiddleware } from '@/middlewares';
import { TagService } from '@/services/tag.service';
@@ -53,7 +51,6 @@ export class WorkflowsController {
private readonly externalHooks: ExternalHooks,
private readonly tagRepository: TagRepository,
private readonly enterpriseWorkflowService: EnterpriseWorkflowService,
private readonly roleService: RoleService,
private readonly workflowHistoryService: WorkflowHistoryService,
private readonly tagService: TagService,
private readonly namingService: NamingService,
@@ -116,12 +113,10 @@ export class WorkflowsController {
await Db.transaction(async (transactionManager) => {
savedWorkflow = await transactionManager.save<WorkflowEntity>(newWorkflow);
const role = await this.roleService.findWorkflowOwnerRole();
const newSharedWorkflow = new SharedWorkflow();
Object.assign(newSharedWorkflow, {
role,
role: 'workflow:owner',
user: req.user,
workflow: savedWorkflow,
});
@@ -151,7 +146,9 @@ export class WorkflowsController {
@Get('/', { middlewares: listQueryMiddleware })
async getAll(req: ListQuery.Request, res: express.Response) {
try {
const roles: RoleNames[] = this.license.isSharingEnabled() ? [] : ['owner'];
const roles: WorkflowSharingRole[] = this.license.isSharingEnabled()
? []
: ['workflow:owner'];
const sharedWorkflowIds = await this.workflowSharingService.getSharedWorkflowIds(
req.user,
roles,
@@ -223,7 +220,7 @@ export class WorkflowsController {
const { id: workflowId } = req.params;
if (this.license.isSharingEnabled()) {
const relations = ['shared', 'shared.user', 'shared.role'];
const relations = ['shared', 'shared.user'];
if (!config.getEnv('workflowTagsDisabled')) {
relations.push('tags');
}
@@ -281,7 +278,8 @@ export class WorkflowsController {
const { tags, ...rest } = req.body;
Object.assign(updateData, rest);
if (this.license.isSharingEnabled()) {
const isSharingEnabled = this.license.isSharingEnabled();
if (isSharingEnabled) {
updateData = await this.enterpriseWorkflowService.preventTampering(
updateData,
workflowId,
@@ -294,8 +292,8 @@ export class WorkflowsController {
updateData,
workflowId,
tags,
this.license.isSharingEnabled() ? forceSave : true,
this.license.isSharingEnabled() ? undefined : ['owner'],
isSharingEnabled ? forceSave : true,
isSharingEnabled ? undefined : ['workflow:owner'],
);
return updatedWorkflow;
@@ -378,10 +376,10 @@ export class WorkflowsController {
await this.workflowRepository.getSharings(
Db.getConnection().createEntityManager(),
workflowId,
['shared', 'shared.role'],
['shared'],
)
)
.filter((e) => e.role.name === 'owner')
.filter((e) => e.role === 'workflow:owner')
.map((e) => e.userId);
let newShareeIds: string[] = [];
@@ -399,9 +397,7 @@ export class WorkflowsController {
if (newShareeIds.length) {
const users = await this.userRepository.getByIds(trx, newShareeIds);
const role = await this.roleService.findWorkflowEditorRole();
await this.sharedWorkflowRepository.share(trx, workflow!, users, role.id);
await this.sharedWorkflowRepository.share(trx, workflow!, users);
}
});