fix(core): Better input validation for the changeRole endpoint (#8189)
also refactored the code to 1. stop passing around `scope === 'global'`, since this code can be used only for changing globalRole. 2. leak less details when input validation fails. ## Review / Merge checklist - [x] PR title and summary are descriptive - [x] Tests included
This commit is contained in:
committed by
GitHub
parent
11cda41214
commit
cfe9525dd4
@@ -7,7 +7,6 @@ import type {
|
||||
} from '@/Interface';
|
||||
import type { IDataObject } from 'n8n-workflow';
|
||||
import { makeRestApiRequest } from '@/utils/apiUtils';
|
||||
import type { ScopeLevel } from '@n8n/permissions';
|
||||
|
||||
export async function loginCurrentUser(
|
||||
context: IRestApiContext,
|
||||
@@ -146,9 +145,14 @@ export async function submitPersonalizationSurvey(
|
||||
await makeRestApiRequest(context, 'POST', '/me/survey', params as unknown as IDataObject);
|
||||
}
|
||||
|
||||
export async function updateRole(
|
||||
context: IRestApiContext,
|
||||
{ id, role }: { id: string; role: { scope: ScopeLevel; name: IRole } },
|
||||
): Promise<IUserResponse> {
|
||||
return makeRestApiRequest(context, 'PATCH', `/users/${id}/role`, { newRole: role });
|
||||
export interface UpdateGlobalRolePayload {
|
||||
id: string;
|
||||
newRoleName: Exclude<IRole, 'default' | 'owner'>;
|
||||
}
|
||||
|
||||
export async function updateGlobalRole(
|
||||
context: IRestApiContext,
|
||||
{ id, newRoleName }: UpdateGlobalRolePayload,
|
||||
): Promise<IUserResponse> {
|
||||
return makeRestApiRequest(context, 'PATCH', `/users/${id}/role`, { newRoleName });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user