summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints
diff options
context:
space:
mode:
authornenohi <kimutipartylove@gmail.com>2023-05-05 14:18:06 +0900
committerGitHub <noreply@github.com>2023-05-05 14:18:06 +0900
commit2d84e042405322fc7f9dd5955f9d72f59cdb3a81 (patch)
tree4fc0725045c36b6937c49e363f17be7758c36b64 /packages/backend/src/server/api/endpoints
parentMerge branch 'develop' of https://github.com/misskey-dev/misskey into develop (diff)
downloadsharkey-2d84e042405322fc7f9dd5955f9d72f59cdb3a81.tar.gz
sharkey-2d84e042405322fc7f9dd5955f9d72f59cdb3a81.tar.bz2
sharkey-2d84e042405322fc7f9dd5955f9d72f59cdb3a81.zip
ロールにNSFWを強制的につけるオプションを追加 (#10731)
* ロールにNSFWを強制的につけるオプションを追加 * すでにあるファイルにNSFWが付与できない * NSFWを付与しようとするとエラーに * add test * Update packages/backend/src/core/RoleService.ts Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * spacingで怒られたので * ロール作成時のプロパティ削除 --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Diffstat (limited to 'packages/backend/src/server/api/endpoints')
-rw-r--r--packages/backend/src/server/api/endpoints/drive/files/update.ts13
-rw-r--r--packages/backend/src/server/api/endpoints/i/update.ts11
2 files changed, 21 insertions, 3 deletions
diff --git a/packages/backend/src/server/api/endpoints/drive/files/update.ts b/packages/backend/src/server/api/endpoints/drive/files/update.ts
index 3141e0fc01..3ecbba22b5 100644
--- a/packages/backend/src/server/api/endpoints/drive/files/update.ts
+++ b/packages/backend/src/server/api/endpoints/drive/files/update.ts
@@ -40,8 +40,13 @@ export const meta = {
code: 'NO_SUCH_FOLDER',
id: 'ea8fb7a5-af77-4a08-b608-c0218176cd73',
},
+
+ restrictedByRole: {
+ message: 'This feature is restricted by your role.',
+ code: 'RESTRICTED_BY_ROLE',
+ id: '7f59dccb-f465-75ab-5cf4-3ce44e3282f7',
+ },
},
-
res: {
type: 'object',
optional: false, nullable: false,
@@ -77,7 +82,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
) {
super(meta, paramDef, async (ps, me) => {
const file = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
-
+ const alwaysMarkNsfw = (await this.roleService.getUserPolicies(me.id)).alwaysMarkNsfw;
if (file == null) {
throw new ApiError(meta.errors.noSuchFile);
}
@@ -93,6 +98,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
if (ps.comment !== undefined) file.comment = ps.comment;
+ if (ps.isSensitive !== undefined && ps.isSensitive !== file.isSensitive && alwaysMarkNsfw && !ps.isSensitive) {
+ throw new ApiError(meta.errors.restrictedByRole);
+ }
+
if (ps.isSensitive !== undefined) file.isSensitive = ps.isSensitive;
if (ps.folderId !== undefined) {
diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts
index 738edf3978..6c66300bb7 100644
--- a/packages/backend/src/server/api/endpoints/i/update.ts
+++ b/packages/backend/src/server/api/endpoints/i/update.ts
@@ -93,6 +93,12 @@ export const meta = {
code: 'FORBIDDEN_TO_SET_YOURSELF',
id: '25c90186-4ab0-49c8-9bba-a1fa6c202ba4',
},
+
+ restrictedByRole: {
+ message: 'This feature is restricted by your role.',
+ code: 'RESTRICTED_BY_ROLE',
+ id: '8feff0ba-5ab5-585b-31f4-4df816663fad',
+ }
},
res: {
@@ -239,7 +245,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
if (typeof ps.isCat === 'boolean') updates.isCat = ps.isCat;
if (typeof ps.injectFeaturedNote === 'boolean') profileUpdates.injectFeaturedNote = ps.injectFeaturedNote;
if (typeof ps.receiveAnnouncementEmail === 'boolean') profileUpdates.receiveAnnouncementEmail = ps.receiveAnnouncementEmail;
- if (typeof ps.alwaysMarkNsfw === 'boolean') profileUpdates.alwaysMarkNsfw = ps.alwaysMarkNsfw;
+ if (typeof ps.alwaysMarkNsfw === 'boolean') {
+ if ((await roleService.getUserPolicies(user.id)).alwaysMarkNsfw) throw new ApiError(meta.errors.restrictedByRole);
+ profileUpdates.alwaysMarkNsfw = ps.alwaysMarkNsfw;
+ }
if (typeof ps.autoSensitive === 'boolean') profileUpdates.autoSensitive = ps.autoSensitive;
if (ps.emailNotificationTypes !== undefined) profileUpdates.emailNotificationTypes = ps.emailNotificationTypes;