diff --git a/CHANGELOG.md b/CHANGELOG.md index 3149fae6e6d3..7d88aae7006c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,13 @@ --> ## 2023.9.3 +### General +- Enhance: ノートの翻訳機能の利用可否をロールで設定可能に + +### Client +- Enhance: モデレーションログ機能の強化 +- Enhance: ローカリゼーションの更新 + ### Server - Fix: Redisに古いバージョンのキャッシュが残っている場合、キャッシュが消えるまでの間通知が届かなくなる問題を修正 diff --git a/locales/index.d.ts b/locales/index.d.ts index 15736f6994af..a9de0ad9652f 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -1562,6 +1562,7 @@ export interface Locale { "descriptionOfRateLimitFactor": string; "canHideAds": string; "canSearchNotes": string; + "canUseTranslator": string; }; "_condition": { "isLocal": string; diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index dcdff1b317fd..c4594987296c 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1482,7 +1482,8 @@ _role: rateLimitFactor: "レートリミット" descriptionOfRateLimitFactor: "小さいほど制限が緩和され、大きいほど制限が強化されます。" canHideAds: "広告の非表示" - canSearchNotes: "ノート検索の利用可否" + canSearchNotes: "ノート検索の利用" + canUseTranslator: "翻訳機能の利用" _condition: isLocal: "ローカルユーザー" isRemote: "リモートユーザー" diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts index c3445abc5337..ad40fbaecd4a 100644 --- a/packages/backend/src/core/RoleService.ts +++ b/packages/backend/src/core/RoleService.ts @@ -33,6 +33,7 @@ export type RolePolicies = { inviteExpirationTime: number; canManageCustomEmojis: boolean; canSearchNotes: boolean; + canUseTranslator: boolean; canHideAds: boolean; driveCapacityMb: number; alwaysMarkNsfw: boolean; @@ -58,6 +59,7 @@ export const DEFAULT_POLICIES: RolePolicies = { inviteExpirationTime: 0, canManageCustomEmojis: false, canSearchNotes: false, + canUseTranslator: true, canHideAds: false, driveCapacityMb: 100, alwaysMarkNsfw: false, @@ -303,6 +305,7 @@ export class RoleService implements OnApplicationShutdown { inviteExpirationTime: calc('inviteExpirationTime', vs => Math.max(...vs)), canManageCustomEmojis: calc('canManageCustomEmojis', vs => vs.some(v => v === true)), canSearchNotes: calc('canSearchNotes', vs => vs.some(v => v === true)), + canUseTranslator: calc('canUseTranslator', vs => vs.some(v => v === true)), canHideAds: calc('canHideAds', vs => vs.some(v => v === true)), driveCapacityMb: calc('driveCapacityMb', vs => Math.max(...vs)), alwaysMarkNsfw: calc('alwaysMarkNsfw', vs => vs.some(v => v === true)), diff --git a/packages/backend/src/server/api/endpoints/notes/translate.ts b/packages/backend/src/server/api/endpoints/notes/translate.ts index 00cb9a0a2863..a1561c944cf8 100644 --- a/packages/backend/src/server/api/endpoints/notes/translate.ts +++ b/packages/backend/src/server/api/endpoints/notes/translate.ts @@ -10,12 +10,13 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { MetaService } from '@/core/MetaService.js'; import { HttpRequestService } from '@/core/HttpRequestService.js'; import { GetterService } from '@/server/api/GetterService.js'; +import { RoleService } from '@/core/RoleService.js'; import { ApiError } from '../../error.js'; export const meta = { tags: ['notes'], - requireCredential: false, + requireCredential: true, res: { type: 'object', @@ -23,6 +24,11 @@ export const meta = { }, errors: { + unavailable: { + message: 'Translate of notes unavailable.', + code: 'UNAVAILABLE', + id: '50a70314-2d8a-431b-b433-efa5cc56444c', + }, noSuchNote: { message: 'No such note.', code: 'NO_SUCH_NOTE', @@ -47,14 +53,20 @@ export default class extends Endpoint { // eslint- private getterService: GetterService, private metaService: MetaService, private httpRequestService: HttpRequestService, + private roleService: RoleService, ) { super(meta, paramDef, async (ps, me) => { + const policies = await this.roleService.getUserPolicies(me.id); + if (!policies.canUseTranslator) { + throw new ApiError(meta.errors.unavailable); + } + const note = await this.getterService.getNote(ps.noteId).catch(err => { if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); throw err; }); - if (!(await this.noteEntityService.isVisibleForMe(note, me ? me.id : null))) { + if (!(await this.noteEntityService.isVisibleForMe(note, me.id))) { return 204; // TODO: 良い感じのエラー返す } diff --git a/packages/frontend/src/const.ts b/packages/frontend/src/const.ts index 9fd6d40d7204..f4ce0a096dea 100644 --- a/packages/frontend/src/const.ts +++ b/packages/frontend/src/const.ts @@ -68,6 +68,7 @@ export const ROLE_POLICIES = [ 'inviteExpirationTime', 'canManageCustomEmojis', 'canSearchNotes', + 'canUseTranslator', 'canHideAds', 'driveCapacityMb', 'alwaysMarkNsfw', diff --git a/packages/frontend/src/pages/admin/roles.editor.vue b/packages/frontend/src/pages/admin/roles.editor.vue index 1b72e1d3326a..8015bb7a7f73 100644 --- a/packages/frontend/src/pages/admin/roles.editor.vue +++ b/packages/frontend/src/pages/admin/roles.editor.vue @@ -299,6 +299,26 @@ SPDX-License-Identifier: AGPL-3.0-only + + + +
+ + + + + + + + + +
+
+