feat: conditional role

Resolve #9539
This commit is contained in:
syuilo 2023-01-13 11:03:54 +09:00
parent 74910f8d70
commit c5c40a73b7
9 changed files with 296 additions and 4 deletions

View file

@ -1,6 +1,48 @@
import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne } from 'typeorm';
import { id } from '../id.js';
type CondFormulaValueAnd = {
type: 'and';
values: RoleCondFormulaValue[];
};
type CondFormulaValueOr = {
type: 'or';
values: RoleCondFormulaValue[];
};
type CondFormulaValueNot = {
type: 'not';
value: RoleCondFormulaValue;
};
type CondFormulaValueIsLocal = {
type: 'isLocal';
};
type CondFormulaValueIsRemote = {
type: 'isRemote';
};
type CondFormulaValueCreatedLessThan = {
type: 'createdLessThan';
sec: number;
};
type CondFormulaValueCreatedMoreThan = {
type: 'createdMoreThan';
sec: number;
};
export type RoleCondFormulaValue =
CondFormulaValueAnd |
CondFormulaValueOr |
CondFormulaValueNot |
CondFormulaValueIsLocal |
CondFormulaValueIsRemote |
CondFormulaValueCreatedLessThan |
CondFormulaValueCreatedMoreThan;
@Entity()
export class Role {
@PrimaryColumn(id())
@ -36,6 +78,17 @@ export class Role {
})
public color: string | null;
@Column('enum', {
enum: ['manual', 'conditional'],
default: 'manual',
})
public target: 'manual' | 'conditional';
@Column('jsonb', {
default: { },
})
public condFormula: RoleCondFormulaValue;
@Column('boolean', {
default: false,
})