feat: Add scopes to /login endpoint (no-changelog) (#7718)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
@@ -20,11 +20,18 @@ import { objectRetriever, lowerCaser } from '../utils/transformers';
|
||||
import { WithTimestamps, jsonColumnType } from './AbstractEntity';
|
||||
import type { IPersonalizationSurveyAnswers } from '@/Interfaces';
|
||||
import type { AuthIdentity } from './AuthIdentity';
|
||||
import { ownerPermissions, memberPermissions } from '@/permissions/roles';
|
||||
import { hasScope, type HasScopeOptions, type Scope } from '@n8n/permissions';
|
||||
|
||||
export const MIN_PASSWORD_LENGTH = 8;
|
||||
|
||||
export const MAX_PASSWORD_LENGTH = 64;
|
||||
|
||||
const STATIC_SCOPE_MAP: Record<string, Scope[]> = {
|
||||
owner: ownerPermissions,
|
||||
member: memberPermissions,
|
||||
};
|
||||
|
||||
@Entity()
|
||||
export class User extends WithTimestamps implements IUser {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
@@ -125,4 +132,21 @@ export class User extends WithTimestamps implements IUser {
|
||||
computeIsOwner(): void {
|
||||
this.isOwner = this.globalRole?.name === 'owner';
|
||||
}
|
||||
|
||||
get globalScopes() {
|
||||
return STATIC_SCOPE_MAP[this.globalRole?.name] ?? [];
|
||||
}
|
||||
|
||||
async hasGlobalScope(
|
||||
scope: Scope | Scope[],
|
||||
hasScopeOptions?: HasScopeOptions,
|
||||
): Promise<boolean> {
|
||||
return hasScope(
|
||||
scope,
|
||||
{
|
||||
global: this.globalScopes,
|
||||
},
|
||||
hasScopeOptions,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user