diff --git a/messages/de.json b/messages/de.json index 58d2e65..58c991d 100644 --- a/messages/de.json +++ b/messages/de.json @@ -127,6 +127,14 @@ "Theme": { "toggleLabel": "Dark Mode" }, + "AiDisclosure": { + "question": "Enthält dieser Inhalt KI-generierte oder KI-bearbeitete Bilder/Texte?", + "none": "Nein", + "modified": "KI-bearbeitet", + "generated": "KI-generiert", + "modifiedBadgeAlt": "Mit KI bearbeitet", + "generatedBadgeAlt": "Mit KI generiert" + }, "Invite": { "title": "Freunde einladen", "subtitle": "Du hast {available} von {total} Einladungen verfügbar. Teile einen Link — jeder Code kann nur einmal verwendet werden.", diff --git a/messages/en.json b/messages/en.json index 12162a5..8a8691b 100644 --- a/messages/en.json +++ b/messages/en.json @@ -127,6 +127,14 @@ "Theme": { "toggleLabel": "Dark Mode" }, + "AiDisclosure": { + "question": "Does this content include AI-generated or AI-modified images/text?", + "none": "No", + "modified": "AI-modified", + "generated": "AI-generated", + "modifiedBadgeAlt": "AI-modified", + "generatedBadgeAlt": "AI-generated" + }, "Invite": { "title": "Invite friends", "subtitle": "You have {available} of {total} invites available. Share a link — each code can only be used once.", diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5ab07c0..856a81a 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -185,6 +185,11 @@ model Pet { verificationRequests VerificationRequest[] + // Gitea #18 — legal AI-content disclosure. Set once at avatar upload, + // owner-immutable afterward; only a moderator can correct it (see + // admin.setAiDisclosure). Overlay-badge only, never baked into pixels. + aiDisclosure AiDisclosure @default(NONE) + @@index([ownerId]) @@index([speciesId]) @@index([breedId]) @@ -198,6 +203,13 @@ enum DmPolicy { FOLLOWERS_ONLY // only pets that this pet follows can send a DM } +// Gitea #18 — legal AI-content disclosure, shared across Post/Story/Pet. +enum AiDisclosure { + NONE + AI_MODIFIED + AI_GENERATED +} + // ─── Phase 2 Enums ─────────────────────────────────────────────────────────── enum PostType { @@ -268,6 +280,10 @@ model Post { commentCount Int @default(0) repostCount Int @default(0) + // Gitea #18 — legal AI-content disclosure, set once at creation, owner- + // immutable afterward. See admin.setAiDisclosure for moderator correction. + aiDisclosure AiDisclosure @default(NONE) + // Phase 3 back-relations reactions Reaction[] @relation("PostReactions") comments Comment[] @relation("PostComments") @@ -316,6 +332,9 @@ model Story { views StoryView[] createdAt DateTime @default(now()) + // Gitea #18 — legal AI-content disclosure, set once at creation. + aiDisclosure AiDisclosure @default(NONE) + @@index([petId, expiresAt]) // supports lazy-delete filter query } @@ -742,7 +761,7 @@ model AdRepost { model ModerationLog { id String @id @default(cuid()) - action String @db.VarChar(50) // DELETE_POST | DELETE_COMMENT | BAN_USER | UNBAN_USER | DELETE_IMAGE | DISMISS_REPORT | CREATE_AD | UPDATE_AD | DELETE_AD | GRANT_ROLE | REVOKE_ROLE | WARN_USER | VERIFY_PET | UNVERIFY_PET | DELETE_ACCOUNT | APPROVE_VERIFICATION_REQUEST | REJECT_VERIFICATION_REQUEST | HIDE_POST | UNHIDE_POST | SHADOWBAN_USER | UNSHADOWBAN_USER + action String @db.VarChar(50) // DELETE_POST | DELETE_COMMENT | BAN_USER | UNBAN_USER | DELETE_IMAGE | DISMISS_REPORT | CREATE_AD | UPDATE_AD | DELETE_AD | GRANT_ROLE | REVOKE_ROLE | WARN_USER | VERIFY_PET | UNVERIFY_PET | DELETE_ACCOUNT | APPROVE_VERIFICATION_REQUEST | REJECT_VERIFICATION_REQUEST | HIDE_POST | UNHIDE_POST | SHADOWBAN_USER | UNSHADOWBAN_USER | SET_AI_DISCLOSURE targetType String @db.VarChar(20) // POST | COMMENT | USER | IMAGE | AD | REPORT | PET targetId String reason String? @db.VarChar(500) diff --git a/public/badges/ai-generated.png b/public/badges/ai-generated.png new file mode 100644 index 0000000..4c2f82f Binary files /dev/null and b/public/badges/ai-generated.png differ diff --git a/public/badges/ai-modified.png b/public/badges/ai-modified.png new file mode 100644 index 0000000..c667e0c Binary files /dev/null and b/public/badges/ai-modified.png differ diff --git a/src/__tests__/admin.test.ts b/src/__tests__/admin.test.ts index 0e27cbd..ea538b0 100644 --- a/src/__tests__/admin.test.ts +++ b/src/__tests__/admin.test.ts @@ -481,3 +481,67 @@ describe("admin.getActiveAds", () => { await expect(caller.admin.getActiveAds({ petId: "pet-dog-1" })).resolves.toEqual([adUnfiltered]); }); }); + +// Gitea #18 — legal AI-content disclosure moderator correction. +describe("admin.setAiDisclosure", () => { + it("wraps the post update + moderation log write in a transaction, requiring a reason", async () => { + vi.stubEnv("ADMIN_OWNER_ID", "admin-1"); + const { caller, mockPrisma } = await createAdminCaller(); + mockPrisma.post.findUnique.mockResolvedValue({ id: "post-1" }); + mockPrisma.post.update.mockResolvedValue({ id: "post-1", aiDisclosure: "AI_GENERATED" }); + mockPrisma.moderationLog.create.mockResolvedValue({ id: "log-1" }); + + const result = await caller.admin.setAiDisclosure({ + postId: "post-1", + aiDisclosure: "AI_GENERATED", + reason: "Owner forgot to disclose", + }); + + expect(mockPrisma.$transaction).toHaveBeenCalledWith(expect.any(Array)); + expect(mockPrisma.post.update).toHaveBeenCalledWith({ + where: { id: "post-1" }, + data: { aiDisclosure: "AI_GENERATED" }, + }); + expect(mockPrisma.moderationLog.create).toHaveBeenCalledWith( + expect.objectContaining({ + data: expect.objectContaining({ + action: "SET_AI_DISCLOSURE", + targetType: "POST", + targetId: "post-1", + reason: "Owner forgot to disclose", + }), + }) + ); + expect(result).toEqual({ success: true }); + }); + + it("rejects an empty reason", async () => { + vi.stubEnv("ADMIN_OWNER_ID", "admin-1"); + const { caller } = await createAdminCaller(); + + await expect( + caller.admin.setAiDisclosure({ postId: "post-1", aiDisclosure: "NONE", reason: "" }) + ).rejects.toThrow(); + }); + + it("throws FORBIDDEN for a non-admin caller", async () => { + vi.stubEnv("ADMIN_OWNER_ID", "someone-else"); + const { caller, mockPrisma } = await createAdminCaller(); + mockPrisma.adminRole.findUnique.mockResolvedValue(null); + + await expect( + caller.admin.setAiDisclosure({ postId: "post-1", aiDisclosure: "NONE", reason: "test" }) + ).rejects.toThrow(TRPCError); + expect(mockPrisma.post.update).not.toHaveBeenCalled(); + }); + + it("throws NOT_FOUND when the post doesn't exist", async () => { + vi.stubEnv("ADMIN_OWNER_ID", "admin-1"); + const { caller, mockPrisma } = await createAdminCaller(); + mockPrisma.post.findUnique.mockResolvedValue(null); + + await expect( + caller.admin.setAiDisclosure({ postId: "missing", aiDisclosure: "NONE", reason: "test" }) + ).rejects.toThrow(TRPCError); + }); +}); diff --git a/src/__tests__/media-upload.test.ts b/src/__tests__/media-upload.test.ts index 39dfe4b..2084c23 100644 --- a/src/__tests__/media-upload.test.ts +++ b/src/__tests__/media-upload.test.ts @@ -197,7 +197,7 @@ describe("media.confirmUpload", () => { // Assert DB update was called with the correct avatarKey expect(mockPrisma.pet.update).toHaveBeenCalledWith({ where: { id: PET_ID }, - data: { avatarKey: AVATAR_KEY }, + data: { avatarKey: AVATAR_KEY, aiDisclosure: "NONE" }, }); // Assert return value contains the avatarKey diff --git a/src/app/(app)/pets/[petId]/page.tsx b/src/app/(app)/pets/[petId]/page.tsx index 73a315d..14344af 100644 --- a/src/app/(app)/pets/[petId]/page.tsx +++ b/src/app/(app)/pets/[petId]/page.tsx @@ -66,6 +66,7 @@ export default async function PetProfilePage({ params }: PageProps) { avatarUrl={pet.avatarKey ? getAvatarUrl(pet.avatarKey) : null} petName={pet.name} initials={getInitials(pet.name)} + aiDisclosure={pet.aiDisclosure} />
{t("question")}
+{uploadError}
} + {previewUrl && uploadedKey && ( +