mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-19 16:55:02 +02:00
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { DismissBannerRequestDto, OwnerSetupRequestDto } from '@n8n/api-types';
|
|
import { AuthenticatedRequest } from '@n8n/db';
|
|
import { Body, GlobalScope, Post, RestController } from '@n8n/decorators';
|
|
import { Response } from 'express';
|
|
|
|
import { AuthService } from '@/auth/auth.service';
|
|
import { PostHogClient } from '@/posthog';
|
|
import { BannerService } from '@/services/banner.service';
|
|
import { OwnershipService } from '@/services/ownership.service';
|
|
import { UserService } from '@/services/user.service';
|
|
|
|
@RestController('/owner')
|
|
export class OwnerController {
|
|
constructor(
|
|
private readonly authService: AuthService,
|
|
private readonly bannerService: BannerService,
|
|
private readonly userService: UserService,
|
|
private readonly postHog: PostHogClient,
|
|
private readonly ownershipService: OwnershipService,
|
|
) {}
|
|
|
|
/**
|
|
* Promote a shell into the owner of the n8n instance
|
|
*/
|
|
@Post('/setup', { skipAuth: true })
|
|
async setupOwner(req: AuthenticatedRequest, res: Response, @Body payload: OwnerSetupRequestDto) {
|
|
const owner = await this.ownershipService.setupOwner(payload);
|
|
this.authService.issueCookie(res, owner, req.authInfo?.usedMfa ?? false, req.browserId);
|
|
return await this.userService.toPublic(owner, { posthog: this.postHog, withScopes: true });
|
|
}
|
|
|
|
@Post('/dismiss-banner')
|
|
@GlobalScope('banner:dismiss')
|
|
async dismissBanner(
|
|
_req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Body payload: DismissBannerRequestDto,
|
|
) {
|
|
const bannerName = payload.banner;
|
|
if (!bannerName) return;
|
|
await this.bannerService.dismissBanner(bannerName);
|
|
}
|
|
}
|