feat(admin): shadowban owners (Gitea #10 Phase 3, part 2/4)

Adds a Shadowban model (mirrors UserBan: reason, issuedBy, expiresAt =
null for permanent) plus MODERATOR+ shadowbanOwner/removeShadowban
mutations logging SHADOWBAN_USER/UNSHADOWBAN_USER to ModerationLog.

Unlike a ban, a shadowbanned owner is never told and keeps using the
app normally — their posts just quietly stop reaching anyone else.
Every reader-facing post query now excludes a shadowbanned owner's
pets for other viewers while still showing that owner their own
content, via a `pet: { OR: [{ ownerId: ctx.userId }, { owner: {
shadowban: null } }] }` filter: feed (both Redis-postId lookup and the
Postgres fallback), profile grid, hashtag search, and the milestones
tab. Explore trending has no reliable per-viewer identity (public
procedure) so it excludes shadowbanned owners unconditionally — a
low-stakes gap since a single post rarely lands there anyway.

Admin dashboard (Gitea #10's "Konten sperren ... Shadowban" spec item):
Users page now shows a violet SHADOWBANNED badge + reason next to the
existing ban badge, and a Ghost-icon shadowban/un-shadowban button
mirroring the ban/unban flow (reason required, unlike ban's optional
one, since the deceptive nature of the action warrants a mandatory
audit trail).

Gitea #10
This commit is contained in:
admin committed 2026-08-12 15:49:45 +02:00
1 parent a29c57e37a
commit eb26cb5fbe
8 files changed
+212 -5

No files matched your search

+49
View File
@@ -425,6 +425,7 @@ export const adminRouter = router({
include: {
pets: { select: { id: true, name: true, avatarKey: true, isVerified: true }, take: 3 },
ban: true,
shadowban: true,
adminRole: true,
_count: { select: { pets: true, warnings: true } },
},
@@ -526,6 +527,54 @@ export const adminRouter = router({
return { success: true };
}),
shadowbanOwner: protectedProcedure
.input(z.object({ ownerId: z.string().min(1), reason: z.string().min(1).max(500) }))
.mutation(async ({ ctx, input }) => {
const callerRole = await assertAdmin(ctx.prisma, ctx.userId, AdminRoleType.MODERATOR);
if (input.ownerId === ctx.userId)
throw new TRPCError({ code: "BAD_REQUEST", message: "Cannot shadowban yourself." });
await ctx.prisma.$transaction([
ctx.prisma.shadowban.upsert({
where: { ownerId: input.ownerId },
create: { ownerId: input.ownerId, reason: input.reason, shadowbannedBy: ctx.userId },
update: { reason: input.reason, shadowbannedBy: ctx.userId, shadowbannedAt: new Date() },
}),
ctx.prisma.moderationLog.create({
data: {
action: "SHADOWBAN_USER",
targetType: "USER",
targetId: input.ownerId,
reason: input.reason,
moderatorId: ctx.userId,
moderatorRole: callerRole,
ipAddress: ctx.ip,
},
}),
]);
return { success: true };
}),
removeShadowban: protectedProcedure
.input(z.object({ ownerId: z.string().min(1) }))
.mutation(async ({ ctx, input }) => {
const callerRole = await assertAdmin(ctx.prisma, ctx.userId, AdminRoleType.MODERATOR);
await ctx.prisma.$transaction([
ctx.prisma.shadowban.delete({ where: { ownerId: input.ownerId } }),
ctx.prisma.moderationLog.create({
data: {
action: "UNSHADOWBAN_USER",
targetType: "USER",
targetId: input.ownerId,
reason: null,
moderatorId: ctx.userId,
moderatorRole: callerRole,
ipAddress: ctx.ip,
},
}),
]);
return { success: true };
}),
// ─── Warnings (append-only, no delete/edit — Gitea #10 permission matrix) ────
listWarnings: protectedProcedure
.input(z.object({ ownerId: z.string().min(1) }))
+6 -1
View File
@@ -60,7 +60,12 @@ export const exploreRouter = router({
const [posts, hashtags] = await Promise.all([
ctx.prisma.post.findMany({
where: { createdAt: { gte: since48h }, type: "PHOTO", hiddenAt: null },
where: {
createdAt: { gte: since48h },
type: "PHOTO",
hiddenAt: null,
pet: { owner: { shadowban: null } },
},
include: {
images: { orderBy: { position: "asc" } },
pet: { select: { id: true, name: true, avatarKey: true } },
+6 -1
View File
@@ -67,6 +67,7 @@ async function getDiscoveryPosts(
pet: {
speciesId: viewerPet.speciesId,
id: { notIn: [viewerPet.id, ...blockedPetIds] },
owner: { shadowban: null },
},
},
orderBy: { createdAt: "desc" },
@@ -125,6 +126,7 @@ export const feedRouter = router({
where: {
hiddenAt: null,
petId: { in: petIds, notIn: blockedPetIds },
pet: { OR: [{ ownerId: ctx.userId }, { owner: { shadowban: null } }] },
...(cursorDate ? { createdAt: { lt: cursorDate } } : {}),
},
orderBy: { createdAt: "desc" },
@@ -168,7 +170,10 @@ export const feedRouter = router({
where: {
id: { in: postIds },
hiddenAt: null,
pet: { id: { notIn: blockedPetIds } },
pet: {
id: { notIn: blockedPetIds },
OR: [{ ownerId: ctx.userId }, { owner: { shadowban: null } }],
},
},
include: postInclude,
});
+6 -1
View File
@@ -86,7 +86,12 @@ export const milestonesRouter = router({
)
.query(async ({ ctx, input }) => {
return ctx.prisma.post.findMany({
where: { petId: input.petId, type: "MILESTONE", hiddenAt: null },
where: {
petId: input.petId,
type: "MILESTONE",
hiddenAt: null,
pet: { OR: [{ ownerId: ctx.userId }, { owner: { shadowban: null } }] },
},
include: {
milestone: true,
images: { orderBy: { position: "asc" } },
+1
View File
@@ -208,6 +208,7 @@ export const postsRouter = router({
where: {
petId: input.petId,
hiddenAt: null,
pet: { OR: [{ ownerId: ctx.userId }, { owner: { shadowban: null } }] },
...(input.cursor
? { createdAt: { lt: new Date(input.cursor) } }
: {}),
+4 -1
View File
@@ -66,7 +66,10 @@ export const searchRouter = router({
const rows = await ctx.prisma.postHashtag.findMany({
where: {
hashtagId: hashtag.id,
post: { hiddenAt: null },
post: {
hiddenAt: null,
pet: { OR: [{ ownerId: ctx.userId }, { owner: { shadowban: null } }] },
},
...(input.cursor ? { postId: { lt: input.cursor } } : {}),
},
take: input.limit + 1,