feat: Add scopes to /login endpoint (no-changelog) (#7718)

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Val
2023-11-16 11:11:55 +00:00
committed by GitHub
parent ebee1a5908
commit d39bb2540f
9 changed files with 158 additions and 15 deletions

View File

@@ -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,
);
}
}