From 8b8a498c547a2e3412f85eaa66c950c4483cb247 Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 11 Nov 2023 10:03:45 +0900 Subject: [PATCH] chore: rename default emoji mod permission from 'none' to 'unauthorized' considering name collision in Rust --- locales/en-US.yml | 2 +- locales/ja-JP.yml | 2 +- locales/zh-TW.yml | 2 +- .../1699658378432-emojimod-enum-relabel.js | 15 +++++++++++++++ .../src/model/entity/sea_orm_active_enums.rs | 2 +- packages/backend/src/models/entities/user.ts | 14 +++++++------- packages/backend/src/models/repositories/user.ts | 2 +- .../api/endpoints/admin/emoji/add-aliases-bulk.ts | 2 +- .../src/server/api/endpoints/admin/emoji/add.ts | 2 +- .../api/endpoints/admin/emoji/import-zip.ts | 4 +++- .../api/endpoints/admin/emoji/list-remote.ts | 2 +- .../src/server/api/endpoints/admin/emoji/list.ts | 2 +- .../api/endpoints/admin/emoji/set-aliases-bulk.ts | 2 +- .../endpoints/admin/emoji/set-category-bulk.ts | 2 +- .../api/endpoints/admin/emoji/set-license-bulk.ts | 2 +- .../server/api/endpoints/admin/emoji/update.ts | 2 +- .../api/endpoints/admin/set-emoji-moderator.ts | 9 ++++++--- packages/client/src/account.ts | 2 +- packages/client/src/pages/user-info.vue | 4 ++-- .../client/src/ui/_common_/navbar-for-mobile.vue | 2 +- packages/client/src/ui/_common_/navbar.vue | 2 +- 21 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 packages/backend/migration-neko/1699658378432-emojimod-enum-relabel.js diff --git a/locales/en-US.yml b/locales/en-US.yml index 6e1c3323..829d577c 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -2170,7 +2170,7 @@ _feeds: emojiModPerm: "Custom emoji management" emojiModPermDescription: "Add: Allow this user to add new custom emojis and to set tag/category/license to newly added custom emojis.\nAdd and Edit: \"Add\" Permission + Allow this user to edit the name/category/tag/license of the existing custom emojis.\nAllow All: \"Add and Edit\" Permission + Allow this user to delete existing custom emojis." _emojiModPerm: - none: "Deny All" + unauthorized: "Deny All" add: "Add" mod: "Add and Edit" full: "Allow All" diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index bbe07c23..f0970cd4 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -2004,7 +2004,7 @@ confirm: "確認" emojiModPerm: "カスタム絵文字の管理" emojiModPermDescription: "追加: カスタム絵文字の新規追加と新規追加されたカスタム絵文字(正確には、タグとカテゴリとライセンスが設定されていないカスタム絵文字)へのタグとカテゴリとライセンスの設定を許可します。\n追加と変更:「追加」の権限に加え、既存の絵文字の名前・カテゴリ・タグ・ライセンスの変更を許可します。\n全て許可:「追加と変更」の権限に加え、既存のカスタム絵文字の削除を許可します。\nこの設定にかかわらず、サーバーの管理者およびモデレーターには「全て許可」の権限が与えられます。" _emojiModPerm: - none: "不許可" + unauthorized: "不許可" add: "追加" mod: "追加と変更" full: "全て許可" diff --git a/locales/zh-TW.yml b/locales/zh-TW.yml index 911cbee3..2ecde276 100644 --- a/locales/zh-TW.yml +++ b/locales/zh-TW.yml @@ -2000,7 +2000,7 @@ disableToast: 不顯示「歡迎回來,◯◯」 emojiModPerm: 自訂表情符號的管理 emojiModPermDescription: "新增: 允許新增自訂表情符號,並允許設定尚未設定標籤/類別/授權條款的現有自訂表情符號。\n新增及編輯: 除了「新增」的權限之外,也允許編輯現有自訂表情符號的標籤/類別/授權條款\n全部允許: 除了「新增及編輯」的權限之外,也允許刪除現有的自訂表情符號。\n伺服器管理員及板主無論此設定為何皆有「全部允許」的權限。" _emojiModPerm: - none: 不允許 + unauthorized: 不允許 add: 新增 mod: 新增及編輯 full: 全部允許 diff --git a/packages/backend/migration-neko/1699658378432-emojimod-enum-relabel.js b/packages/backend/migration-neko/1699658378432-emojimod-enum-relabel.js new file mode 100644 index 00000000..1f681a10 --- /dev/null +++ b/packages/backend/migration-neko/1699658378432-emojimod-enum-relabel.js @@ -0,0 +1,15 @@ +export class EmojimodEnumRelabel1699658378432 { + name = "EmojimodEnumRelabel1699658378432"; + + async up(queryRunner) { + await queryRunner.query( + `ALTER TYPE "public"."user_emojimodperm_enum" RENAME VALUE 'none' TO 'unauthorized'`, + ); + } + + async down(queryRunner) { + await queryRunner.query( + `ALTER TYPE "public"."user_emojimodperm_enum" RENAME VALUE 'unauthorized' TO 'none'`, + ); + } +} diff --git a/packages/backend/native-utils/src/model/entity/sea_orm_active_enums.rs b/packages/backend/native-utils/src/model/entity/sea_orm_active_enums.rs index 7f38837f..4dfeff94 100644 --- a/packages/backend/native-utils/src/model/entity/sea_orm_active_enums.rs +++ b/packages/backend/native-utils/src/model/entity/sea_orm_active_enums.rs @@ -182,7 +182,7 @@ pub enum UserEmojimodpermEnum { Mod, #[default] #[sea_orm(string_value = "none")] - None, + Unauthorized, } #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Default)] #[sea_orm( diff --git a/packages/backend/src/models/entities/user.ts b/packages/backend/src/models/entities/user.ts index a316f512..6d730071 100644 --- a/packages/backend/src/models/entities/user.ts +++ b/packages/backend/src/models/entities/user.ts @@ -9,11 +9,11 @@ import { import { id } from "../id.js"; import { DriveFile } from "./drive-file.js"; -// none: no permission -// add: add custom emojis to the server -// mod: add permission + modify {category, tags, license} of existing custom emojis -// full: mod permission + {rename, delete} existing custom emojis -export type EmojiModPerm = "none" | "add" | "mod" | "full"; +// unauthorized: no permission +// add: add custom emojis to the server +// mod: add permission + modify {category, tags, license} of existing custom emojis +// full: mod permission + {rename, delete} existing custom emojis +export type EmojiModPerm = "unauthorized" | "add" | "mod" | "full"; @Entity() @Index(["usernameLower", "host"], { unique: true }) @@ -187,8 +187,8 @@ export class User { @Column({ type: "enum", - enum: ["none", "add", "mod", "full"], - default: "none", + enum: ["unauthorized", "add", "mod", "full"], + default: "unauthorized", }) public emojiModPerm: EmojiModPerm; diff --git a/packages/backend/src/models/repositories/user.ts b/packages/backend/src/models/repositories/user.ts index f30663e7..a667f775 100644 --- a/packages/backend/src/models/repositories/user.ts +++ b/packages/backend/src/models/repositories/user.ts @@ -450,7 +450,7 @@ export const UserRepository = db.getRepository(User).extend({ avatarUrl: this.getAvatarUrlSync(user), avatarBlurhash: user.avatar?.blurhash || null, avatarColor: null, // 後方互換性のため - emojiModPerm: user.emojiModPerm ?? "none", + emojiModPerm: user.emojiModPerm ?? "unauthorized", isAdmin: user.isAdmin || falsy, isModerator: user.isModerator || falsy, isBot: user.isBot || falsy, diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/add-aliases-bulk.ts b/packages/backend/src/server/api/endpoints/admin/emoji/add-aliases-bulk.ts index 2633c550..af4a3ebd 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/add-aliases-bulk.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/add-aliases-bulk.ts @@ -41,7 +41,7 @@ export const paramDef = { export default define(meta, paramDef, async (ps, me) => { // require emoji mod permission (or add permission if there is no alias) - if (!(me.isAdmin || me.isModerator || me.emojiModPerm === "none")) + if (!(me.isAdmin || me.isModerator || me.emojiModPerm === "unauthorized")) throw new ApiError(meta.errors.accessDenied); const emojis = await Emojis.findBy({ diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/add.ts b/packages/backend/src/server/api/endpoints/admin/emoji/add.ts index 7463e84a..eadc52e3 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/add.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/add.ts @@ -38,7 +38,7 @@ export const paramDef = { export default define(meta, paramDef, async (ps, me) => { // require emoji add permission - if (!(me.isAdmin || me.isModerator || me.emojiModPerm !== "none")) + if (!(me.isAdmin || me.isModerator || me.emojiModPerm !== "unauthorized")) throw new ApiError(meta.errors.accessDenied); const file = await DriveFiles.findOneBy({ id: ps.fileId }); diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/import-zip.ts b/packages/backend/src/server/api/endpoints/admin/emoji/import-zip.ts index f49f9461..ef1027df 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/import-zip.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/import-zip.ts @@ -28,7 +28,9 @@ export const paramDef = { export default define(meta, paramDef, async (ps, user) => { // require emoji add permission - if (!(user.isAdmin || user.isModerator || user.emojiModPerm !== "none")) + if ( + !(user.isAdmin || user.isModerator || user.emojiModPerm !== "unauthorized") + ) throw new ApiError(meta.errors.accessDenied); createImportCustomEmojisJob(user, ps.fileId); diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/list-remote.ts b/packages/backend/src/server/api/endpoints/admin/emoji/list-remote.ts index ab1eb937..53c234ad 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/list-remote.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/list-remote.ts @@ -104,7 +104,7 @@ export const paramDef = { export default define(meta, paramDef, async (ps, me) => { // require emoji add permission - if (!(me.isAdmin || me.isModerator || me.emojiModPerm !== "none")) + if (!(me.isAdmin || me.isModerator || me.emojiModPerm !== "unauthorized")) throw new ApiError(meta.errors.accessDenied); const q = makePaginationQuery( diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/list.ts b/packages/backend/src/server/api/endpoints/admin/emoji/list.ts index 1c36d78d..759b9eab 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/list.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/list.ts @@ -98,7 +98,7 @@ export const paramDef = { export default define(meta, paramDef, async (ps, me) => { // require emoji add permission - if (!(me.isAdmin || me.isModerator || me.emojiModPerm !== "none")) + if (!(me.isAdmin || me.isModerator || me.emojiModPerm !== "unauthorized")) throw new ApiError(meta.errors.accessDenied); const q = makePaginationQuery( diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/set-aliases-bulk.ts b/packages/backend/src/server/api/endpoints/admin/emoji/set-aliases-bulk.ts index f08e143b..ea7e70f6 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/set-aliases-bulk.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/set-aliases-bulk.ts @@ -41,7 +41,7 @@ export const paramDef = { export default define(meta, paramDef, async (ps, me) => { // require emoji mod permission (or add permission if there is no alias) - if (!(me.isAdmin || me.isModerator || me.emojiModPerm === "none")) + if (!(me.isAdmin || me.isModerator || me.emojiModPerm === "unauthorized")) throw new ApiError(meta.errors.accessDenied); const emojis = await Emojis.findBy({ diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/set-category-bulk.ts b/packages/backend/src/server/api/endpoints/admin/emoji/set-category-bulk.ts index 2831b7d8..eada64e3 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/set-category-bulk.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/set-category-bulk.ts @@ -40,7 +40,7 @@ export const paramDef = { export default define(meta, paramDef, async (ps, me) => { // require emoji mod permission (or add permission if there is no category) - if (!(me.isAdmin || me.isModerator || me.emojiModPerm === "none")) + if (!(me.isAdmin || me.isModerator || me.emojiModPerm === "unauthorized")) throw new ApiError(meta.errors.accessDenied); const emojis = await Emojis.findBy({ diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/set-license-bulk.ts b/packages/backend/src/server/api/endpoints/admin/emoji/set-license-bulk.ts index af5d02d2..0c498a19 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/set-license-bulk.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/set-license-bulk.ts @@ -40,7 +40,7 @@ export const paramDef = { export default define(meta, paramDef, async (ps, me) => { // require emoji mod permission (or add permission if there is no license) - if (!(me.isAdmin || me.isModerator || me.emojiModPerm === "none")) + if (!(me.isAdmin || me.isModerator || me.emojiModPerm === "unauthorized")) throw new ApiError(meta.errors.accessDenied); const emojis = await Emojis.findBy({ diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/update.ts b/packages/backend/src/server/api/endpoints/admin/emoji/update.ts index 6c5b06e0..039acb39 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/update.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/update.ts @@ -49,7 +49,7 @@ export const paramDef = { export default define(meta, paramDef, async (ps, me) => { // require emoji mod permission (or add permission if there is no category/alias/license) - if (!(me.isAdmin || me.isModerator || me.emojiModPerm !== "none")) + if (!(me.isAdmin || me.isModerator || me.emojiModPerm !== "unauthorized")) throw new ApiError(meta.errors.accessDenied); const emoji = await Emojis.findOneBy({ id: ps.id }); diff --git a/packages/backend/src/server/api/endpoints/admin/set-emoji-moderator.ts b/packages/backend/src/server/api/endpoints/admin/set-emoji-moderator.ts index e963b5c6..f821a54f 100644 --- a/packages/backend/src/server/api/endpoints/admin/set-emoji-moderator.ts +++ b/packages/backend/src/server/api/endpoints/admin/set-emoji-moderator.ts @@ -25,12 +25,15 @@ export default define(meta, paramDef, async (ps) => { throw new Error("user not found"); } - if (!["none", "add", "mod", "full"].includes(ps.emojiModPerm)) { - throw new Error("emojiModPerm must be 'none', 'add', 'mod', or 'full'"); + if (!["unauthorized", "add", "mod", "full"].includes(ps.emojiModPerm)) { + throw new Error( + "emojiModPerm must be 'unauthorized', 'add', 'mod', or 'full'", + ); } const _emojiModPerm = - (ps.emojiModPerm as "none" | "add" | "mod" | "full") ?? "none"; + (ps.emojiModPerm as "unauthorized" | "add" | "mod" | "full") ?? + "unauthorized"; await Users.update(user.id, { emojiModPerm: _emojiModPerm, diff --git a/packages/client/src/account.ts b/packages/client/src/account.ts index 9bfeb1cf..2f113f75 100644 --- a/packages/client/src/account.ts +++ b/packages/client/src/account.ts @@ -14,7 +14,7 @@ export type Account = firefish.entities.MeDetailed; export const iAmModerator = $i != null && ($i.isAdmin || $i.isModerator); export const iAmAdmin = $i?.isAdmin; -export const iAmEmojiMod = iAmModerator || $i?.emojiModPerm !== "none"; +export const iAmEmojiMod = iAmModerator || $i?.emojiModPerm !== "unauthorized"; export async function signout() { waiting(); diff --git a/packages/client/src/pages/user-info.vue b/packages/client/src/pages/user-info.vue index 57866926..8929c809 100644 --- a/packages/client/src/pages/user-info.vue +++ b/packages/client/src/pages/user-info.vue @@ -189,8 +189,8 @@ i18n.ts.originalFeature }} -