enhance(server): Improve user block (#7640)

* enhance(server): Improve user block

* Update CHANGELOG.md

* ユーザーリスト対応

* 相手から見れなくなるように

* Update 1629004542760-chart-reindex.ts

2365761ba5 (commitcomment-54919821)

* update test

* add test

* add todos

* Update 1629004542760-chart-reindex.ts
This commit is contained in:
syuilo 2021-08-17 21:48:59 +09:00 committed by GitHub
parent 7ebdd4739a
commit 7015df37e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 394 additions and 30 deletions

View file

@ -4,7 +4,7 @@ import define from '../../../define';
import { ApiError } from '../../../error';
import { getUser } from '../../../common/getters';
import { pushUserToUserList } from '../../../../../services/user-list/push';
import { UserLists, UserListJoinings } from '../../../../../models';
import { UserLists, UserListJoinings, Blockings } from '../../../../../models';
export const meta = {
tags: ['lists', 'users'],
@ -40,7 +40,13 @@ export const meta = {
message: 'That user has already been added to that list.',
code: 'ALREADY_ADDED',
id: '1de7c884-1595-49e9-857e-61f12f4d4fc5'
}
},
youHaveBeenBlocked: {
message: 'You cannot push this user because you have been blocked by this user.',
code: 'YOU_HAVE_BEEN_BLOCKED',
id: '990232c5-3f9d-4d83-9f3f-ef27b6332a4b'
},
}
};
@ -61,6 +67,17 @@ export default define(meta, async (ps, me) => {
throw e;
});
// Check blocking
if (user.id !== me.id) {
const block = await Blockings.findOne({
blockerId: user.id,
blockeeId: me.id,
});
if (block) {
throw new ApiError(meta.errors.youHaveBeenBlocked);
}
}
const exist = await UserListJoinings.findOne({
userListId: userList.id,
userId: user.id