summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-05-09 21:03:05 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-05-09 21:03:05 -0400
commit56a8ff4f50f9a7c66218c8590da056c149e1187e (patch)
tree9209d198cdd089c53fde84143df95cc757d652c2 /packages
parentmerge: Properly announce Accept-Ranges on Drive files (!1007) (diff)
downloadsharkey-56a8ff4f50f9a7c66218c8590da056c149e1187e.tar.gz
sharkey-56a8ff4f50f9a7c66218c8590da056c149e1187e.tar.bz2
sharkey-56a8ff4f50f9a7c66218c8590da056c149e1187e.zip
add isFromInstance role condition
Diffstat (limited to 'packages')
-rw-r--r--packages/backend/src/core/RoleService.ts13
-rw-r--r--packages/backend/src/models/Role.ts10
-rw-r--r--packages/frontend/src/pages/admin/RolesEditorFormula.vue15
3 files changed, 38 insertions, 0 deletions
diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts
index 229781c079..d948325503 100644
--- a/packages/backend/src/core/RoleService.ts
+++ b/packages/backend/src/core/RoleService.ts
@@ -248,6 +248,19 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
case 'isRemote': {
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': {
return user.isSuspended;
diff --git a/packages/backend/src/models/Role.ts b/packages/backend/src/models/Role.ts
index 4c7da252bd..d7ae8ed38c 100644
--- a/packages/backend/src/models/Role.ts
+++ b/packages/backend/src/models/Role.ts
@@ -48,6 +48,15 @@ type CondFormulaValueIsRemote = {
};
/**
+ * User is from a specific instance
+ */
+type CondFormulaValueIsFromInstance = {
+ type: 'isFromInstance';
+ host: string;
+ subdomains: boolean;
+};
+
+/**
* 既に指定のマニュアルロールにアサインされている場合のみ成立とする
*/
type CondFormulaValueRoleAssignedTo = {
@@ -160,6 +169,7 @@ export type RoleCondFormulaValue = { id: string } & (
CondFormulaValueNot |
CondFormulaValueIsLocal |
CondFormulaValueIsRemote |
+ CondFormulaValueIsFromInstance |
CondFormulaValueIsSuspended |
CondFormulaValueIsLocked |
CondFormulaValueIsBot |
diff --git a/packages/frontend/src/pages/admin/RolesEditorFormula.vue b/packages/frontend/src/pages/admin/RolesEditorFormula.vue
index 6c47e6397f..53a4836caa 100644
--- a/packages/frontend/src/pages/admin/RolesEditorFormula.vue
+++ b/packages/frontend/src/pages/admin/RolesEditorFormula.vue
@@ -9,6 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSelect v-model="type" :class="$style.typeSelect">
<option value="isLocal">{{ i18n.ts._role._condition.isLocal }}</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="isLocked">{{ i18n.ts._role._condition.isLocked }}</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">
<option v-for="role in roles.filter(r => r.target === 'manual')" :key="role.id" :value="role.id">{{ role.name }}</option>
</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>
</template>
@@ -73,6 +82,7 @@ import MkButton from '@/components/MkButton.vue';
import { i18n } from '@/i18n.js';
import { deepClone } from '@/utility/clone.js';
import { rolesCache } from '@/cache.js';
+import MkSwitch from '@/components/MkSwitch.vue';
const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default));
@@ -102,6 +112,7 @@ watch(v, () => {
const type = computed({
get: () => v.value.type,
set: (t) => {
+ // TODO there's a bug here: switching types leaves extra properties in the JSON
if (t === 'and') v.value.values = [];
if (t === 'or') v.value.values = [];
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 === 'notesLessThanOrEq') 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;
},
});