From 9dbe12135d3c22597624ab549586c89a30555be8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 18 May 2019 22:54:02 +0900 Subject: [PATCH] Fix bug --- src/server/api/endpoints/users/groups/show.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/server/api/endpoints/users/groups/show.ts b/src/server/api/endpoints/users/groups/show.ts index 5f2c83988..4f8374a22 100644 --- a/src/server/api/endpoints/users/groups/show.ts +++ b/src/server/api/endpoints/users/groups/show.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import { ID } from '../../../../../misc/cafy-id'; import define from '../../../define'; import { ApiError } from '../../../error'; -import { UserGroups } from '../../../../../models'; +import { UserGroups, UserGroupJoinings } from '../../../../../models'; import { types, bool } from '../../../../../misc/schema'; export const meta = { @@ -42,12 +42,20 @@ export default define(meta, async (ps, me) => { // Fetch the group const userGroup = await UserGroups.findOne({ id: ps.groupId, - userId: me.id, }); if (userGroup == null) { throw new ApiError(meta.errors.noSuchGroup); } + const joining = await UserGroupJoinings.findOne({ + userId: me.id, + userGroupId: userGroup.id + }); + + if (joining == null && userGroup.userId !== me.id) { + throw new ApiError(meta.errors.noSuchGroup); + } + return await UserGroups.pack(userGroup); });