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

@ -9,7 +9,7 @@ import { deliver } from '../../../../../queue';
import { renderActivity } from '../../../../../remote/activitypub/renderer';
import renderVote from '../../../../../remote/activitypub/renderer/vote';
import { deliverQuestionUpdate } from '../../../../../services/note/polls/update';
import { PollVotes, NoteWatchings, Users, Polls } from '../../../../../models';
import { PollVotes, NoteWatchings, Users, Polls, Blockings } from '../../../../../models';
import { Not } from 'typeorm';
import { IRemoteUser } from '../../../../../models/entities/user';
import { genId } from '@/misc/gen-id';
@ -61,6 +61,12 @@ export const meta = {
code: 'ALREADY_EXPIRED',
id: '1022a357-b085-4054-9083-8f8de358337e'
},
youHaveBeenBlocked: {
message: 'You cannot vote this poll because you have been blocked by this user.',
code: 'YOU_HAVE_BEEN_BLOCKED',
id: '85a5377e-b1e9-4617-b0b9-5bea73331e49'
},
}
};
@ -77,6 +83,17 @@ export default define(meta, async (ps, user) => {
throw new ApiError(meta.errors.noPoll);
}
// Check blocking
if (note.userId !== user.id) {
const block = await Blockings.findOne({
blockerId: note.userId,
blockeeId: user.id,
});
if (block) {
throw new ApiError(meta.errors.youHaveBeenBlocked);
}
}
const poll = await Polls.findOneOrFail({ noteId: note.id });
if (poll.expiresAt && poll.expiresAt < createdAt) {
@ -103,13 +120,13 @@ export default define(meta, async (ps, user) => {
}
// Create vote
const vote = await PollVotes.save({
const vote = await PollVotes.insert({
id: genId(),
createdAt,
noteId: note.id,
userId: user.id,
choice: ps.choice
});
}).then(x => PollVotes.findOneOrFail(x.identifiers[0]));
// Increment votes count
const index = ps.choice + 1; // In SQL, array index is 1 based