paricafe/packages/backend/src/models/Role.ts

271 lines
5.3 KiB
TypeScript
Raw Normal View History

/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Entity, Column, PrimaryColumn } from 'typeorm';
import { id } from './util/id.js';
/**
*
*
*/
2023-01-12 20:03:54 -06:00
type CondFormulaValueAnd = {
type: 'and';
values: RoleCondFormulaValue[];
};
/**
*
*
*/
2023-01-12 20:03:54 -06:00
type CondFormulaValueOr = {
type: 'or';
values: RoleCondFormulaValue[];
};
/**
*
*
*/
2023-01-12 20:03:54 -06:00
type CondFormulaValueNot = {
type: 'not';
value: RoleCondFormulaValue;
};
/**
*
*/
2023-01-12 20:03:54 -06:00
type CondFormulaValueIsLocal = {
type: 'isLocal';
};
/**
*
*/
2023-01-12 20:03:54 -06:00
type CondFormulaValueIsRemote = {
type: 'isRemote';
};
/**
*
*/
type CondFormulaValueRoleAssignedTo = {
type: 'roleAssignedTo';
roleId: string;
};
/**
*
*/
type CondFormulaValueIsSuspended = {
type: 'isSuspended';
};
/**
*
*/
type CondFormulaValueIsLocked = {
type: 'isLocked';
};
/**
* botアカウントの場合のみ成立とする
*/
type CondFormulaValueIsBot = {
type: 'isBot';
};
/**
*
*/
type CondFormulaValueIsCat = {
type: 'isCat';
};
/**
*
*/
type CondFormulaValueIsExplorable = {
type: 'isExplorable';
};
/**
*
*/
2023-01-12 20:03:54 -06:00
type CondFormulaValueCreatedLessThan = {
type: 'createdLessThan';
sec: number;
};
/**
*
*/
2023-01-12 20:03:54 -06:00
type CondFormulaValueCreatedMoreThan = {
type: 'createdMoreThan';
sec: number;
};
/**
*
*/
type CondFormulaValueFollowersLessThanOrEq = {
type: 'followersLessThanOrEq';
value: number;
};
/**
*
*/
type CondFormulaValueFollowersMoreThanOrEq = {
type: 'followersMoreThanOrEq';
value: number;
};
/**
*
*/
type CondFormulaValueFollowingLessThanOrEq = {
type: 'followingLessThanOrEq';
value: number;
};
/**
*
*/
type CondFormulaValueFollowingMoreThanOrEq = {
type: 'followingMoreThanOrEq';
value: number;
};
/**
* 稿
*/
type CondFormulaValueNotesLessThanOrEq = {
type: 'notesLessThanOrEq';
value: number;
};
/**
* 稿
*/
type CondFormulaValueNotesMoreThanOrEq = {
type: 'notesMoreThanOrEq';
value: number;
};
export type RoleCondFormulaValue = { id: string } & (
2023-01-12 20:03:54 -06:00
CondFormulaValueAnd |
CondFormulaValueOr |
CondFormulaValueNot |
CondFormulaValueIsLocal |
CondFormulaValueIsRemote |
CondFormulaValueIsSuspended |
CondFormulaValueIsLocked |
CondFormulaValueIsBot |
CondFormulaValueIsCat |
CondFormulaValueIsExplorable |
CondFormulaValueRoleAssignedTo |
2023-01-12 20:03:54 -06:00
CondFormulaValueCreatedLessThan |
CondFormulaValueCreatedMoreThan |
CondFormulaValueFollowersLessThanOrEq |
CondFormulaValueFollowersMoreThanOrEq |
CondFormulaValueFollowingLessThanOrEq |
CondFormulaValueFollowingMoreThanOrEq |
CondFormulaValueNotesLessThanOrEq |
CondFormulaValueNotesMoreThanOrEq
);
2023-01-12 20:03:54 -06:00
@Entity('role')
export class MiRole {
@PrimaryColumn(id())
public id: string;
@Column('timestamp with time zone', {
comment: 'The updated date of the Role.',
})
public updatedAt: Date;
@Column('timestamp with time zone', {
comment: 'The last used date of the Role.',
})
public lastUsedAt: Date;
@Column('varchar', {
length: 256,
})
public name: string;
@Column('varchar', {
length: 1024,
})
public description: string;
@Column('varchar', {
length: 256, nullable: true,
})
public color: string | null;
@Column('varchar', {
length: 512, nullable: true,
})
public iconUrl: string | null;
2023-01-12 20:03:54 -06:00
@Column('enum', {
enum: ['manual', 'conditional'],
default: 'manual',
})
public target: 'manual' | 'conditional';
@Column('jsonb', {
default: { },
})
public condFormula: RoleCondFormulaValue;
@Column('boolean', {
default: false,
})
public isPublic: boolean;
// trueの場合ユーザー名の横にバッジとして表示
@Column('boolean', {
default: false,
})
public asBadge: boolean;
@Column('boolean', {
default: false,
})
public isModerator: boolean;
@Column('boolean', {
default: false,
})
public isAdministrator: boolean;
@Column('boolean', {
default: false,
})
public isExplorable: boolean;
@Column('boolean', {
default: false,
})
public canEditMembersByModerator: boolean;
// UIに表示する際の並び順用(大きいほど先頭)
@Column('integer', {
default: 0,
})
public displayOrder: number;
@Column('jsonb', {
default: { },
})
public policies: Record<string, {
useDefault: boolean;
priority: number;
value: any;
}>;
}