feat: make possible to configure following/followers visibility (#7959)

* feat: make possible to configure following/followers visibility

* add test

* ap

* add ap test

* set Cache-Control

* hide following/followers count
This commit is contained in:
syuilo 2021-11-07 18:04:32 +09:00 committed by GitHub
parent 07526ada45
commit a28c515ef6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 317 additions and 10 deletions

View file

@ -72,6 +72,10 @@ export const meta = {
validator: $.optional.bool,
},
ffVisibility: {
validator: $.optional.str,
},
carefulBot: {
validator: $.optional.bool,
},
@ -174,6 +178,7 @@ export default define(meta, async (ps, _user, token) => {
if (ps.lang !== undefined) profileUpdates.lang = ps.lang;
if (ps.location !== undefined) profileUpdates.location = ps.location;
if (ps.birthday !== undefined) profileUpdates.birthday = ps.birthday;
if (ps.ffVisibility !== undefined) profileUpdates.ffVisibility = ps.ffVisibility;
if (ps.avatarId !== undefined) updates.avatarId = ps.avatarId;
if (ps.bannerId !== undefined) updates.bannerId = ps.bannerId;
if (ps.mutedWords !== undefined) {

View file

@ -2,7 +2,7 @@ import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../define';
import { ApiError } from '../../error';
import { Users, Followings } from '@/models/index';
import { Users, Followings, UserProfiles } from '@/models/index';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { toPunyNullable } from '@/misc/convert-host';
@ -53,7 +53,13 @@ export const meta = {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '27fa5435-88ab-43de-9360-387de88727cd'
}
},
forbidden: {
message: 'Forbidden.',
code: 'FORBIDDEN',
id: '3c6a84db-d619-26af-ca14-06232a21df8a'
},
}
};
@ -66,6 +72,26 @@ export default define(meta, async (ps, me) => {
throw new ApiError(meta.errors.noSuchUser);
}
const profile = await UserProfiles.findOneOrFail(user.id);
if (profile.ffVisibility === 'private') {
if (me == null || (me.id !== user.id)) {
throw new ApiError(meta.errors.forbidden);
}
} else if (profile.ffVisibility === 'followers') {
if (me == null) {
throw new ApiError(meta.errors.forbidden);
} else if (me.id !== user.id) {
const following = await Followings.findOne({
followeeId: user.id,
followerId: me.id,
});
if (following == null) {
throw new ApiError(meta.errors.forbidden);
}
}
}
const query = makePaginationQuery(Followings.createQueryBuilder('following'), ps.sinceId, ps.untilId)
.andWhere(`following.followeeId = :userId`, { userId: user.id })
.innerJoinAndSelect('following.follower', 'follower');

View file

@ -2,7 +2,7 @@ import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../define';
import { ApiError } from '../../error';
import { Users, Followings } from '@/models/index';
import { Users, Followings, UserProfiles } from '@/models/index';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { toPunyNullable } from '@/misc/convert-host';
@ -53,7 +53,13 @@ export const meta = {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '63e4aba4-4156-4e53-be25-c9559e42d71b'
}
},
forbidden: {
message: 'Forbidden.',
code: 'FORBIDDEN',
id: 'f6cdb0df-c19f-ec5c-7dbb-0ba84a1f92ba'
},
}
};
@ -66,6 +72,26 @@ export default define(meta, async (ps, me) => {
throw new ApiError(meta.errors.noSuchUser);
}
const profile = await UserProfiles.findOneOrFail(user.id);
if (profile.ffVisibility === 'private') {
if (me == null || (me.id !== user.id)) {
throw new ApiError(meta.errors.forbidden);
}
} else if (profile.ffVisibility === 'followers') {
if (me == null) {
throw new ApiError(meta.errors.forbidden);
} else if (me.id !== user.id) {
const following = await Followings.findOne({
followeeId: user.id,
followerId: me.id,
});
if (following == null) {
throw new ApiError(meta.errors.forbidden);
}
}
}
const query = makePaginationQuery(Followings.createQueryBuilder('following'), ps.sinceId, ps.untilId)
.andWhere(`following.followerId = :userId`, { userId: user.id })
.innerJoinAndSelect('following.followee', 'followee');