2023-07-27 00:31:52 -05:00
|
|
|
|
/*
|
2024-02-13 09:59:27 -06:00
|
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 00:31:52 -05:00
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2023-02-16 08:09:41 -06:00
|
|
|
|
import { Entity, Column, PrimaryColumn } from 'typeorm';
|
2023-09-19 21:33:36 -05:00
|
|
|
|
import { id } from './util/id.js';
|
2023-01-12 06:02:26 -06:00
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* ~かつ~
|
|
|
|
|
* 複数の条件を同時に満たす場合のみ成立とする
|
|
|
|
|
*/
|
2023-01-12 20:03:54 -06:00
|
|
|
|
type CondFormulaValueAnd = {
|
|
|
|
|
type: 'and';
|
|
|
|
|
values: RoleCondFormulaValue[];
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* ~または~
|
|
|
|
|
* 複数の条件のうち、いずれかを満たす場合のみ成立とする
|
|
|
|
|
*/
|
2023-01-12 20:03:54 -06:00
|
|
|
|
type CondFormulaValueOr = {
|
|
|
|
|
type: 'or';
|
|
|
|
|
values: RoleCondFormulaValue[];
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* ~ではない
|
|
|
|
|
* 条件を満たさない場合のみ成立とする
|
|
|
|
|
*/
|
2023-01-12 20:03:54 -06:00
|
|
|
|
type CondFormulaValueNot = {
|
|
|
|
|
type: 'not';
|
|
|
|
|
value: RoleCondFormulaValue;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* ローカルユーザーのみ成立とする
|
|
|
|
|
*/
|
2023-01-12 20:03:54 -06:00
|
|
|
|
type CondFormulaValueIsLocal = {
|
|
|
|
|
type: 'isLocal';
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* リモートユーザーのみ成立とする
|
|
|
|
|
*/
|
2023-01-12 20:03:54 -06:00
|
|
|
|
type CondFormulaValueIsRemote = {
|
|
|
|
|
type: 'isRemote';
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* 既に指定のマニュアルロールにアサインされている場合のみ成立とする
|
|
|
|
|
*/
|
2024-02-27 03:45:46 -06:00
|
|
|
|
type CondFormulaValueRoleAssignedTo = {
|
|
|
|
|
type: 'roleAssignedTo';
|
|
|
|
|
roleId: string;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* サスペンド済みアカウントの場合のみ成立とする
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* ユーザが作成されてから指定期間経っていない場合のみ成立とする
|
|
|
|
|
*/
|
2023-01-12 20:03:54 -06:00
|
|
|
|
type CondFormulaValueCreatedMoreThan = {
|
|
|
|
|
type: 'createdMoreThan';
|
|
|
|
|
sec: number;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* フォロワー数が指定値以下の場合のみ成立とする
|
|
|
|
|
*/
|
2023-01-13 17:27:23 -06:00
|
|
|
|
type CondFormulaValueFollowersLessThanOrEq = {
|
|
|
|
|
type: 'followersLessThanOrEq';
|
|
|
|
|
value: number;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* フォロワー数が指定値以上の場合のみ成立とする
|
|
|
|
|
*/
|
2023-01-13 17:27:23 -06:00
|
|
|
|
type CondFormulaValueFollowersMoreThanOrEq = {
|
|
|
|
|
type: 'followersMoreThanOrEq';
|
|
|
|
|
value: number;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* フォロー数が指定値以下の場合のみ成立とする
|
|
|
|
|
*/
|
2023-01-13 17:27:23 -06:00
|
|
|
|
type CondFormulaValueFollowingLessThanOrEq = {
|
|
|
|
|
type: 'followingLessThanOrEq';
|
|
|
|
|
value: number;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* フォロー数が指定値以上の場合のみ成立とする
|
|
|
|
|
*/
|
2023-01-13 17:27:23 -06:00
|
|
|
|
type CondFormulaValueFollowingMoreThanOrEq = {
|
|
|
|
|
type: 'followingMoreThanOrEq';
|
|
|
|
|
value: number;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* 投稿数が指定値以下の場合のみ成立とする
|
|
|
|
|
*/
|
2023-03-23 03:18:38 -05:00
|
|
|
|
type CondFormulaValueNotesLessThanOrEq = {
|
|
|
|
|
type: 'notesLessThanOrEq';
|
|
|
|
|
value: number;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-19 01:22:23 -05:00
|
|
|
|
/**
|
|
|
|
|
* 投稿数が指定値以上の場合のみ成立とする
|
|
|
|
|
*/
|
2023-03-23 03:18:38 -05:00
|
|
|
|
type CondFormulaValueNotesMoreThanOrEq = {
|
|
|
|
|
type: 'notesMoreThanOrEq';
|
|
|
|
|
value: number;
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-15 23:27:33 -06:00
|
|
|
|
export type RoleCondFormulaValue = { id: string } & (
|
2023-01-12 20:03:54 -06:00
|
|
|
|
CondFormulaValueAnd |
|
|
|
|
|
CondFormulaValueOr |
|
|
|
|
|
CondFormulaValueNot |
|
|
|
|
|
CondFormulaValueIsLocal |
|
|
|
|
|
CondFormulaValueIsRemote |
|
2024-04-19 01:22:23 -05:00
|
|
|
|
CondFormulaValueIsSuspended |
|
|
|
|
|
CondFormulaValueIsLocked |
|
|
|
|
|
CondFormulaValueIsBot |
|
|
|
|
|
CondFormulaValueIsCat |
|
|
|
|
|
CondFormulaValueIsExplorable |
|
2024-02-27 03:45:46 -06:00
|
|
|
|
CondFormulaValueRoleAssignedTo |
|
2023-01-12 20:03:54 -06:00
|
|
|
|
CondFormulaValueCreatedLessThan |
|
2023-01-13 17:27:23 -06:00
|
|
|
|
CondFormulaValueCreatedMoreThan |
|
|
|
|
|
CondFormulaValueFollowersLessThanOrEq |
|
|
|
|
|
CondFormulaValueFollowersMoreThanOrEq |
|
|
|
|
|
CondFormulaValueFollowingLessThanOrEq |
|
2023-03-23 03:18:38 -05:00
|
|
|
|
CondFormulaValueFollowingMoreThanOrEq |
|
|
|
|
|
CondFormulaValueNotesLessThanOrEq |
|
2024-02-15 23:27:33 -06:00
|
|
|
|
CondFormulaValueNotesMoreThanOrEq
|
|
|
|
|
);
|
2023-01-12 20:03:54 -06:00
|
|
|
|
|
2023-08-16 03:51:28 -05:00
|
|
|
|
@Entity('role')
|
|
|
|
|
export class MiRole {
|
2023-01-12 06:02:26 -06:00
|
|
|
|
@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;
|
|
|
|
|
|
2023-02-04 19:37:03 -06:00
|
|
|
|
@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;
|
|
|
|
|
|
2023-01-12 06:02:26 -06:00
|
|
|
|
@Column('boolean', {
|
|
|
|
|
default: false,
|
|
|
|
|
})
|
|
|
|
|
public isPublic: boolean;
|
|
|
|
|
|
2023-02-04 19:37:03 -06:00
|
|
|
|
// trueの場合ユーザー名の横にバッジとして表示
|
|
|
|
|
@Column('boolean', {
|
|
|
|
|
default: false,
|
|
|
|
|
})
|
|
|
|
|
public asBadge: boolean;
|
|
|
|
|
|
2023-01-12 06:02:26 -06:00
|
|
|
|
@Column('boolean', {
|
|
|
|
|
default: false,
|
|
|
|
|
})
|
|
|
|
|
public isModerator: boolean;
|
|
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
|
default: false,
|
|
|
|
|
})
|
|
|
|
|
public isAdministrator: boolean;
|
|
|
|
|
|
2023-04-20 06:02:50 -05:00
|
|
|
|
@Column('boolean', {
|
|
|
|
|
default: false,
|
|
|
|
|
})
|
|
|
|
|
public isExplorable: boolean;
|
|
|
|
|
|
2023-01-12 06:02:26 -06:00
|
|
|
|
@Column('boolean', {
|
|
|
|
|
default: false,
|
|
|
|
|
})
|
|
|
|
|
public canEditMembersByModerator: boolean;
|
|
|
|
|
|
2023-03-12 01:38:08 -06:00
|
|
|
|
// UIに表示する際の並び順用(大きいほど先頭)
|
|
|
|
|
@Column('integer', {
|
|
|
|
|
default: 0,
|
|
|
|
|
})
|
|
|
|
|
public displayOrder: number;
|
|
|
|
|
|
2023-01-12 06:02:26 -06:00
|
|
|
|
@Column('jsonb', {
|
|
|
|
|
default: { },
|
|
|
|
|
})
|
2023-01-15 05:52:53 -06:00
|
|
|
|
public policies: Record<string, {
|
2023-01-12 06:02:26 -06:00
|
|
|
|
useDefault: boolean;
|
2023-01-15 04:10:39 -06:00
|
|
|
|
priority: number;
|
2023-01-12 06:02:26 -06:00
|
|
|
|
value: any;
|
|
|
|
|
}>;
|
|
|
|
|
}
|