feat(core): Add includeData parameter to GET /credentials (#12220)

Co-authored-by: r00gm <raul00gm@gmail.com>
This commit is contained in:
Danny Martini
2024-12-31 13:04:37 +01:00
committed by GitHub
parent 096329db51
commit f56ad8cf49
15 changed files with 526 additions and 66 deletions

View File

@@ -1,3 +1,4 @@
import { CredentialsGetManyRequestQuery, CredentialsGetOneRequestQuery } from '@n8n/api-types';
import { GlobalConfig } from '@n8n/config';
// eslint-disable-next-line n8n-local-rules/misplaced-n8n-typeorm-import
import { In } from '@n8n/typeorm';
@@ -19,6 +20,7 @@ import {
RestController,
ProjectScope,
} from '@/decorators';
import { Param, Query } from '@/decorators/args';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { ForbiddenError } from '@/errors/response-errors/forbidden.error';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
@@ -49,10 +51,15 @@ export class CredentialsController {
) {}
@Get('/', { middlewares: listQueryMiddleware })
async getMany(req: CredentialRequest.GetMany) {
async getMany(
req: CredentialRequest.GetMany,
_res: unknown,
@Query query: CredentialsGetManyRequestQuery,
) {
const credentials = await this.credentialsService.getMany(req.user, {
listQueryOptions: req.listQueryOptions,
includeScopes: req.query.includeScopes,
includeScopes: query.includeScopes,
includeData: query.includeData,
});
credentials.forEach((c) => {
// @ts-expect-error: This is to emulate the old behavior of removing the shared
@@ -82,21 +89,22 @@ export class CredentialsController {
@Get('/:credentialId')
@ProjectScope('credential:read')
async getOne(req: CredentialRequest.Get) {
async getOne(
req: CredentialRequest.Get,
_res: unknown,
@Param('credentialId') credentialId: string,
@Query query: CredentialsGetOneRequestQuery,
) {
const { shared, ...credential } = this.license.isSharingEnabled()
? await this.enterpriseCredentialsService.getOne(
req.user,
req.params.credentialId,
credentialId,
// TODO: editor-ui is always sending this, maybe we can just rely on the
// the scopes and always decrypt the data if the user has the permissions
// to do so.
req.query.includeData === 'true',
query.includeData,
)
: await this.credentialsService.getOne(
req.user,
req.params.credentialId,
req.query.includeData === 'true',
);
: await this.credentialsService.getOne(req.user, credentialId, query.includeData);
const scopes = await this.credentialsService.getCredentialScopes(
req.user,