refactor(core): Delete unused GET /me endpoint (no-changelog) (#5498)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-02-17 10:58:48 +01:00 committed by GitHub
parent d143f3f2ec
commit 12104bc4a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 124 deletions

View file

@ -49,14 +49,6 @@ export class MeController {
this.userRepository = repositories.User;
}
/**
* Return the logged-in user.
*/
@Get('/')
async getCurrentUser(req: AuthenticatedRequest): Promise<PublicUser> {
return sanitizeUser(req.user);
}
/**
* Update the logged-in user's settings, except password.
*/

View file

@ -40,39 +40,6 @@ afterAll(async () => {
});
describe('Owner shell', () => {
test('GET /me should return sanitized owner shell', async () => {
const ownerShell = await testDb.createUserShell(globalOwnerRole);
const response = await authAgent(ownerShell).get('/me');
expect(response.statusCode).toBe(200);
const {
id,
email,
firstName,
lastName,
personalizationAnswers,
globalRole,
password,
resetPasswordToken,
isPending,
apiKey,
} = response.body.data;
expect(validator.isUUID(id)).toBe(true);
expect(email).toBeNull();
expect(firstName).toBeNull();
expect(lastName).toBeNull();
expect(personalizationAnswers).toBeNull();
expect(password).toBeUndefined();
expect(resetPasswordToken).toBeUndefined();
expect(isPending).toBe(true);
expect(globalRole.name).toBe('owner');
expect(globalRole.scope).toBe('global');
expect(apiKey).toBeUndefined();
});
test('PATCH /me should succeed with valid inputs', async () => {
const ownerShell = await testDb.createUserShell(globalOwnerRole);
const authOwnerShellAgent = authAgent(ownerShell);
@ -234,39 +201,6 @@ describe('Member', () => {
);
});
test('GET /me should return sanitized member', async () => {
const member = await testDb.createUser({ globalRole: globalMemberRole });
const response = await authAgent(member).get('/me');
expect(response.statusCode).toBe(200);
const {
id,
email,
firstName,
lastName,
personalizationAnswers,
globalRole,
password,
resetPasswordToken,
isPending,
apiKey,
} = response.body.data;
expect(validator.isUUID(id)).toBe(true);
expect(email).toBe(member.email);
expect(firstName).toBe(member.firstName);
expect(lastName).toBe(member.lastName);
expect(personalizationAnswers).toBeNull();
expect(password).toBeUndefined();
expect(resetPasswordToken).toBeUndefined();
expect(isPending).toBe(false);
expect(globalRole.name).toBe('member');
expect(globalRole.scope).toBe('global');
expect(apiKey).toBeUndefined();
});
test('PATCH /me should succeed with valid inputs', async () => {
const member = await testDb.createUser({ globalRole: globalMemberRole });
const authMemberAgent = authAgent(member);
@ -433,39 +367,6 @@ describe('Owner', () => {
config.set('userManagement.isInstanceOwnerSetUp', true);
});
test('GET /me should return sanitized owner', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
const response = await authAgent(owner).get('/me');
expect(response.statusCode).toBe(200);
const {
id,
email,
firstName,
lastName,
personalizationAnswers,
globalRole,
password,
resetPasswordToken,
isPending,
apiKey,
} = response.body.data;
expect(validator.isUUID(id)).toBe(true);
expect(email).toBe(owner.email);
expect(firstName).toBe(owner.firstName);
expect(lastName).toBe(owner.lastName);
expect(personalizationAnswers).toBeNull();
expect(password).toBeUndefined();
expect(resetPasswordToken).toBeUndefined();
expect(isPending).toBe(false);
expect(globalRole.name).toBe('owner');
expect(globalRole.scope).toBe('global');
expect(apiKey).toBeUndefined();
});
test('PATCH /me should succeed with valid inputs', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
const authOwnerAgent = authAgent(owner);

View file

@ -28,7 +28,6 @@ export const LOGGED_OUT_RESPONSE_BODY = {
* Routes requiring a valid `n8n-auth` cookie for a user, either owner or member.
*/
export const ROUTES_REQUIRING_AUTHENTICATION: Readonly<string[]> = [
'GET /me',
'PATCH /me',
'PATCH /me/password',
'POST /me/survey',

View file

@ -5,16 +5,12 @@ import {
IUserResponse,
} from '@/Interface';
import { IDataObject } from 'n8n-workflow';
import { makeRestApiRequest } from '@/utils';
import { makeRestApiRequest } from '@/utils/apiUtils';
export function loginCurrentUser(context: IRestApiContext): Promise<IUserResponse | null> {
return makeRestApiRequest(context, 'GET', '/login');
}
export function getCurrentUser(context: IRestApiContext): Promise<IUserResponse | null> {
return makeRestApiRequest(context, 'GET', '/me');
}
export function login(
context: IRestApiContext,
params: { email: string; password: string },

View file

@ -1,7 +1,6 @@
import {
changePassword,
deleteUser,
getCurrentUser,
getInviteLink,
getUsers,
inviteUsers,
@ -138,16 +137,6 @@ export const useUsersStore = defineStore(STORES.USERS, {
}
Vue.set(this.currentUser, 'personalizationAnswers', answers);
},
async getCurrentUser(): Promise<IUserResponse | null> {
const rootStore = useRootStore();
const user = await getCurrentUser(rootStore.getRestApiContext);
if (user) {
this.addUsers([user]);
this.currentUserId = user.id;
}
return user;
},
async loginWithCookie(): Promise<void> {
const rootStore = useRootStore();
const user = await loginCurrentUser(rootStore.getRestApiContext);