diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2020-01-02 02:47:20 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2020-01-02 02:47:20 +0900 |
| commit | 541f5f13149022dc637a4afb5ff91d103e2ed7d6 (patch) | |
| tree | 82c2ff166507e48726b7bf923c494e81a18569bf /src/server/api | |
| parent | Fix: リモートプロキシ時にサムネイルのContent-Typeがおかし... (diff) | |
| download | sharkey-541f5f13149022dc637a4afb5ff91d103e2ed7d6.tar.gz sharkey-541f5f13149022dc637a4afb5ff91d103e2ed7d6.tar.bz2 sharkey-541f5f13149022dc637a4afb5ff91d103e2ed7d6.zip | |
Hide suspended user profile (#5452)
Diffstat (limited to 'src/server/api')
| -rw-r--r-- | src/server/api/endpoints/admin/suspend-user.ts | 12 | ||||
| -rw-r--r-- | src/server/api/endpoints/i/notifications.ts | 8 | ||||
| -rw-r--r-- | src/server/api/endpoints/users/show.ts | 9 |
3 files changed, 25 insertions, 4 deletions
diff --git a/src/server/api/endpoints/admin/suspend-user.ts b/src/server/api/endpoints/admin/suspend-user.ts index 6ba0d91505..1202315541 100644 --- a/src/server/api/endpoints/admin/suspend-user.ts +++ b/src/server/api/endpoints/admin/suspend-user.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import { ID } from '../../../../misc/cafy-id'; import define from '../../define'; import deleteFollowing from '../../../../services/following/delete'; -import { Users, Followings } from '../../../../models'; +import { Users, Followings, Notifications } from '../../../../models'; import { User } from '../../../../models/entities/user'; import { insertModerationLog } from '../../../../services/insert-moderation-log'; import { doPostSuspend } from '../../../../services/suspend-user'; @@ -55,6 +55,7 @@ export default define(meta, async (ps, me) => { (async () => { await doPostSuspend(user).catch(e => {}); await unFollowAll(user).catch(e => {}); + await readAllNotify(user).catch(e => {}); })(); }); @@ -75,3 +76,12 @@ async function unFollowAll(follower: User) { await deleteFollowing(follower, followee, true); } } + +async function readAllNotify(notifier: User) { + await Notifications.update({ + notifierId: notifier.id, + isRead: false, + }, { + isRead: true + }); +} diff --git a/src/server/api/endpoints/i/notifications.ts b/src/server/api/endpoints/i/notifications.ts index aa72e9a176..cd00501a2e 100644 --- a/src/server/api/endpoints/i/notifications.ts +++ b/src/server/api/endpoints/i/notifications.ts @@ -3,7 +3,7 @@ import { ID } from '../../../../misc/cafy-id'; import { readNotification } from '../../common/read-notification'; import define from '../../define'; import { makePaginationQuery } from '../../common/make-pagination-query'; -import { Notifications, Followings, Mutings } from '../../../../models'; +import { Notifications, Followings, Mutings, Users } from '../../../../models'; export const meta = { desc: { @@ -72,6 +72,10 @@ export default define(meta, async (ps, user) => { .select('muting.muteeId') .where('muting.muterId = :muterId', { muterId: user.id }); + const suspendedQuery = Users.createQueryBuilder('users') + .select('id') + .where('users.isSuspended = TRUE'); + const query = makePaginationQuery(Notifications.createQueryBuilder('notification'), ps.sinceId, ps.untilId) .andWhere(`notification.notifieeId = :meId`, { meId: user.id }) .leftJoinAndSelect('notification.notifier', 'notifier'); @@ -79,6 +83,8 @@ export default define(meta, async (ps, user) => { query.andWhere(`notification.notifierId NOT IN (${ mutingQuery.getQuery() })`); query.setParameters(mutingQuery.getParameters()); + query.andWhere(`notification.notifierId NOT IN (${ suspendedQuery.getQuery() })`); + if (ps.following) { query.andWhere(`((notification.notifierId IN (${ followingQuery.getQuery() })) OR (notification.notifierId = :meId))`, { meId: user.id }); query.setParameters(followingQuery.getParameters()); diff --git a/src/server/api/endpoints/users/show.ts b/src/server/api/endpoints/users/show.ts index d17dd51c0a..f49017a8c3 100644 --- a/src/server/api/endpoints/users/show.ts +++ b/src/server/api/endpoints/users/show.ts @@ -66,13 +66,18 @@ export const meta = { export default define(meta, async (ps, me) => { let user; + const isAdminOrModerator = me && (me.isAdmin || me.isModerator); + if (ps.userIds) { if (ps.userIds.length === 0) { return []; } - const users = await Users.find({ + const users = await Users.find(isAdminOrModerator ? { id: In(ps.userIds) + } : { + id: In(ps.userIds), + isSuspended: false }); return await Promise.all(users.map(u => Users.pack(u, me, { @@ -93,7 +98,7 @@ export default define(meta, async (ps, me) => { user = await Users.findOne(q); } - if (user == null) { + if (user == null || (!isAdminOrModerator && user.isSuspended)) { throw new ApiError(meta.errors.noSuchUser); } |