add isFromInstance role condition

This commit is contained in:
Hazelnoot 2025-05-09 21:03:05 -04:00
parent b8558fd8db
commit 56a8ff4f50
5 changed files with 54 additions and 1 deletions

14
locales/index.d.ts vendored
View file

@ -7677,6 +7677,18 @@ export interface Locale extends ILocale {
* *
*/ */
"not": string; "not": string;
/**
* Is from a specific instance
*/
"isFromInstance": string;
/**
* Hostname (case-insensitive)
*/
"isFromInstanceHost": string;
/**
* Match subdomains
*/
"isFromInstanceSubdomains": string;
}; };
}; };
"_sensitiveMediaDetection": { "_sensitiveMediaDetection": {
@ -12949,7 +12961,7 @@ export interface Locale extends ILocale {
"enableProxyAccountDescription": string; "enableProxyAccountDescription": string;
"_confirmPollEdit": { "_confirmPollEdit": {
/** /**
* Are you sure you want to edit this poll? * Are you sure you want to edit this poll
*/ */
"title": string; "title": string;
/** /**

View file

@ -248,6 +248,19 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
case 'isRemote': { case 'isRemote': {
return this.userEntityService.isRemoteUser(user); return this.userEntityService.isRemoteUser(user);
} }
// User is from a specific instance
case 'isFromInstance': {
if (user.host == null) {
return false;
}
if (value.subdomains) {
const userHost = '.' + user.host.toLowerCase();
const targetHost = '.' + value.host.toLowerCase();
return userHost.endsWith(targetHost);
} else {
return user.host.toLowerCase() === value.host.toLowerCase();
}
}
// サスペンド済みユーザである // サスペンド済みユーザである
case 'isSuspended': { case 'isSuspended': {
return user.isSuspended; return user.isSuspended;

View file

@ -47,6 +47,15 @@ type CondFormulaValueIsRemote = {
type: 'isRemote'; type: 'isRemote';
}; };
/**
* User is from a specific instance
*/
type CondFormulaValueIsFromInstance = {
type: 'isFromInstance';
host: string;
subdomains: boolean;
};
/** /**
* *
*/ */
@ -160,6 +169,7 @@ export type RoleCondFormulaValue = { id: string } & (
CondFormulaValueNot | CondFormulaValueNot |
CondFormulaValueIsLocal | CondFormulaValueIsLocal |
CondFormulaValueIsRemote | CondFormulaValueIsRemote |
CondFormulaValueIsFromInstance |
CondFormulaValueIsSuspended | CondFormulaValueIsSuspended |
CondFormulaValueIsLocked | CondFormulaValueIsLocked |
CondFormulaValueIsBot | CondFormulaValueIsBot |

View file

@ -9,6 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSelect v-model="type" :class="$style.typeSelect"> <MkSelect v-model="type" :class="$style.typeSelect">
<option value="isLocal">{{ i18n.ts._role._condition.isLocal }}</option> <option value="isLocal">{{ i18n.ts._role._condition.isLocal }}</option>
<option value="isRemote">{{ i18n.ts._role._condition.isRemote }}</option> <option value="isRemote">{{ i18n.ts._role._condition.isRemote }}</option>
<option value="isFromInstance">{{ i18n.ts._role._condition.isFromInstance }}</option>
<option value="isSuspended">{{ i18n.ts._role._condition.isSuspended }}</option> <option value="isSuspended">{{ i18n.ts._role._condition.isSuspended }}</option>
<option value="isLocked">{{ i18n.ts._role._condition.isLocked }}</option> <option value="isLocked">{{ i18n.ts._role._condition.isLocked }}</option>
<option value="isBot">{{ i18n.ts._role._condition.isBot }}</option> <option value="isBot">{{ i18n.ts._role._condition.isBot }}</option>
@ -61,6 +62,14 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSelect v-else-if="type === 'roleAssignedTo'" v-model="v.roleId"> <MkSelect v-else-if="type === 'roleAssignedTo'" v-model="v.roleId">
<option v-for="role in roles.filter(r => r.target === 'manual')" :key="role.id" :value="role.id">{{ role.name }}</option> <option v-for="role in roles.filter(r => r.target === 'manual')" :key="role.id" :value="role.id">{{ role.name }}</option>
</MkSelect> </MkSelect>
<MkInput v-else-if="type === 'isFromInstance'" v-model="v.host" type="text">
<template #label>{{ i18n.ts._role._condition.isFromInstanceHost }}</template>
</MkInput>
<MkSwitch v-if="type === 'isFromInstance'" v-model="v.subdomains">
<template #label>{{ i18n.ts._role._condition.isFromInstanceSubdomains }}</template>
</MkSwitch>
</div> </div>
</template> </template>
@ -73,6 +82,7 @@ import MkButton from '@/components/MkButton.vue';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { deepClone } from '@/utility/clone.js'; import { deepClone } from '@/utility/clone.js';
import { rolesCache } from '@/cache.js'; import { rolesCache } from '@/cache.js';
import MkSwitch from '@/components/MkSwitch.vue';
const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default)); const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default));
@ -102,6 +112,7 @@ watch(v, () => {
const type = computed({ const type = computed({
get: () => v.value.type, get: () => v.value.type,
set: (t) => { set: (t) => {
// TODO there's a bug here: switching types leaves extra properties in the JSON
if (t === 'and') v.value.values = []; if (t === 'and') v.value.values = [];
if (t === 'or') v.value.values = []; if (t === 'or') v.value.values = [];
if (t === 'not') v.value.value = { id: uuid(), type: 'isRemote' }; if (t === 'not') v.value.value = { id: uuid(), type: 'isRemote' };
@ -114,6 +125,10 @@ const type = computed({
if (t === 'followingMoreThanOrEq') v.value.value = 10; if (t === 'followingMoreThanOrEq') v.value.value = 10;
if (t === 'notesLessThanOrEq') v.value.value = 10; if (t === 'notesLessThanOrEq') v.value.value = 10;
if (t === 'notesMoreThanOrEq') v.value.value = 10; if (t === 'notesMoreThanOrEq') v.value.value = 10;
if (t === 'isFromInstance') {
v.value.host = '';
v.value.subdomains = true;
}
v.value.type = t; v.value.type = t;
}, },
}); });

View file

@ -242,6 +242,9 @@ _role:
_condition: _condition:
isLocked: "Private account" isLocked: "Private account"
isExplorable: "Account is discoverable" isExplorable: "Account is discoverable"
isFromInstance: "Is from a specific instance"
isFromInstanceHost: "Hostname (case-insensitive)"
isFromInstanceSubdomains: "Match subdomains"
_emailUnavailable: _emailUnavailable:
banned: "This email address is banned" banned: "This email address is banned"
_signup: _signup: