feat(core): Add filtering, selection and pagination to users (#6994)
https://linear.app/n8n/issue/PAY-646
This commit is contained in:
@@ -8,16 +8,15 @@ import {
|
||||
InternalServerError,
|
||||
UnauthorizedError,
|
||||
} from '@/ResponseHelper';
|
||||
import { sanitizeUser, withFeatureFlags } from '@/UserManagement/UserManagementHelper';
|
||||
import { issueCookie, resolveJwt } from '@/auth/jwt';
|
||||
import { AUTH_COOKIE_NAME, RESPONSE_ERROR_MESSAGES } from '@/constants';
|
||||
import { Request, Response } from 'express';
|
||||
import { ILogger } from 'n8n-workflow';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { LoginRequest, UserRequest } from '@/requests';
|
||||
import type { PublicUser } from '@/Interfaces';
|
||||
import { Config } from '@/config';
|
||||
import { IInternalHooksClass } from '@/Interfaces';
|
||||
import type { PublicUser, CurrentUser } from '@/Interfaces';
|
||||
import { handleEmailLogin, handleLdapLogin } from '@/auth';
|
||||
import { PostHogClient } from '@/posthog';
|
||||
import {
|
||||
@@ -98,7 +97,8 @@ export class AuthController {
|
||||
user,
|
||||
authenticationMethod: usedAuthenticationMethod,
|
||||
});
|
||||
return withFeatureFlags(this.postHog, sanitizeUser(user));
|
||||
|
||||
return this.userService.toPublic(user, { posthog: this.postHog });
|
||||
}
|
||||
void Container.get(InternalHooks).onUserLoginFailed({
|
||||
user: email,
|
||||
@@ -112,7 +112,7 @@ export class AuthController {
|
||||
* Manually check the `n8n-auth` cookie.
|
||||
*/
|
||||
@Get('/login')
|
||||
async currentUser(req: Request, res: Response): Promise<CurrentUser> {
|
||||
async currentUser(req: Request, res: Response): Promise<PublicUser> {
|
||||
// Manually check the existing cookie.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
const cookieContents = req.cookies?.[AUTH_COOKIE_NAME] as string | undefined;
|
||||
@@ -123,7 +123,7 @@ export class AuthController {
|
||||
try {
|
||||
user = await resolveJwt(cookieContents);
|
||||
|
||||
return await withFeatureFlags(this.postHog, sanitizeUser(user));
|
||||
return await this.userService.toPublic(user, { posthog: this.postHog });
|
||||
} catch (error) {
|
||||
res.clearCookie(AUTH_COOKIE_NAME);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ export class AuthController {
|
||||
}
|
||||
|
||||
await issueCookie(res, user);
|
||||
return withFeatureFlags(this.postHog, sanitizeUser(user));
|
||||
return this.userService.toPublic(user, { posthog: this.postHog });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +183,10 @@ export class AuthController {
|
||||
}
|
||||
}
|
||||
|
||||
const users = await this.userService.findMany({ where: { id: In([inviterId, inviteeId]) } });
|
||||
const users = await this.userService.findMany({
|
||||
where: { id: In([inviterId, inviteeId]) },
|
||||
relations: ['globalRole'],
|
||||
});
|
||||
if (users.length !== 2) {
|
||||
this.logger.debug(
|
||||
'Request to resolve signup token failed because the ID of the inviter and/or the ID of the invitee were not found in database',
|
||||
|
||||
Reference in New Issue
Block a user