-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(core): Update tag endpoints to use DTOs and injectable config #12380
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
if (this.config.getEnv('workflowTagsDisabled')) | ||
throw new BadRequestError('Workflow tags are disabled'); | ||
workflowsEnabledMiddleware(_req: Request, res: Response, next: NextFunction) { | ||
if (this.config.getEnv('workflowTagsDisabled')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an exception from a middleware returns 500 with an empty response instead of the BadRequest. Probably a bug, due to the error not handled correctly, so for now use the response object to return.
*/ | ||
|
||
@Env('N8N_WORKFLOW_TAGS_DISABLED') | ||
workflowTagsDisabled: boolean = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we call the property disabled
so we can do tags.disabled
. Or move this to the workflow configuration instead? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. let's do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of minor comments, but looks good so far. 🙇🏽
@@ -1,54 +1,72 @@ | |||
import { UpdateTagRequestDto, CreateTagRequestDto } from '@n8n/api-types'; | |||
import { RetrieveTagQueryDto } from '@n8n/api-types/src/dto/tag/retrieve-tag-query.dto'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no /src/
in released code. This will break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh wondering why the import added the source 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
*/ | ||
|
||
@Env('N8N_WORKFLOW_TAGS_DISABLED') | ||
workflowTagsDisabled: boolean = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. let's do that.
import { z } from 'zod'; | ||
import { Z } from 'zod-class'; | ||
|
||
export class BaseTagRequestDto extends Z.class({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we really need to create two separate DTOs here. Can we instead have a CreateOrDeleteTagRequestDto
or UpsertTagRequestDto
?
if (this.config.getEnv('workflowTagsDisabled')) | ||
throw new BadRequestError('Workflow tags are disabled'); | ||
workflowsEnabledMiddleware(_req: Request, res: Response, next: NextFunction) { | ||
if (this.globalConfig.tags.workflowTagsDisabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been wondering about this code. The logic to return 400 comes from a long time ago, and I don't know if we ever even discussed this.
Perhaps a better solution here would be delete this middleware, and load this controller conditionally, like we do for MFAController
.
next(); | ||
} | ||
|
||
@Get('/') | ||
@GlobalScope('tag:list') | ||
async getAll(req: TagsRequest.GetAll) { | ||
return await this.tagService.getAll({ withUsageCount: req.query.withUsageCount === 'true' }); | ||
async getAll(_req: AuthenticatedRequest, _res: Response, @Query query: RetrieveTagQueryDto) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once we have migrated all controllers, we can remove these implicit parameters 🤞🏽
@@ -132,7 +131,7 @@ export class WorkflowRepository extends Repository<WorkflowEntity> { | |||
|
|||
const relations: string[] = []; | |||
|
|||
const areTagsEnabled = !config.getEnv('workflowTagsDisabled'); | |||
const areTagsEnabled = !Container.get(GlobalConfig).tags.workflowTagsDisabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const areTagsEnabled = !Container.get(GlobalConfig).tags.workflowTagsDisabled; | |
const areTagsEnabled = !this.GlobalConfig.tags.workflowTagsDisabled; |
@@ -10,9 +10,8 @@ import { | |||
type FindManyOptions, | |||
type FindOptionsRelations, | |||
} from '@n8n/typeorm'; | |||
import { Service } from 'typedi'; | |||
import Container, { Service } from 'typedi'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import Container, { Service } from 'typedi'; | |
import { Service } from 'typedi'; |
@@ -202,15 +203,17 @@ export class WorkflowService { | |||
]), | |||
); | |||
|
|||
if (tagIds && !config.getEnv('workflowTagsDisabled')) { | |||
const tagsDisabled = Container.get(GlobalConfig).tags.workflowTagsDisabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add GlobalConfig
to the constructor, and replace this with
const tagsDisabled = Container.get(GlobalConfig).tags.workflowTagsDisabled; | |
const tagsDisabled = this.globalConfig.tags.workflowTagsDisabled; |
@@ -240,6 +240,8 @@ test('should not report outdated instance when up to date', async () => { | |||
|
|||
test('should report security settings', async () => { | |||
Container.get(GlobalConfig).diagnostics.enabled = true; | |||
Container.get(GlobalConfig).publicApi.disabled = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems like an unrelated change. what's the context here?
const StringBooleanEnum = z.enum(['true', 'false']).optional(); | ||
|
||
export class RetrieveTagQueryDto extends Z.class({ | ||
withUsageCount: StringBooleanEnum, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should update this to use booleanFromString
after #12220 is merged.
Summary
Title self explanatory
I have no clue why we have the
N8N_WORKFLOW_TAGS_DISABLED
env variable at all. Not sure in which scenario we want to disable tags 🤔. Removing this env variable will simplify things as we need to constantly check this value. @netroy any idea why?Review / Merge checklist
release/backport
(if the PR is an urgent fix that needs to be backported)