Skip to content

Commit

Permalink
update dsareports on gdpr delete only if dsa enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kabeaty committed Nov 6, 2023
1 parent 3f8acb1 commit bd2ac51
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion server/src/core/server/graph/mutators/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ export const Users = (ctx: GraphContext) => ({
ctx.config,
input.userID,
ctx.tenant.id,
ctx.now
ctx.now,
ctx.tenant.dsa.enabled
);
},
cancelAccountDeletion: async (
Expand Down
33 changes: 25 additions & 8 deletions server/src/core/server/services/users/delete.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { Collection, FilterQuery } from "mongodb";
import { v4 as uuid } from "uuid";

import { Config } from "coral-server/config";
import { MongoContext } from "coral-server/data/context";
import { ACTION_TYPE } from "coral-server/models/action/comment";
import { Comment, getLatestRevision } from "coral-server/models/comment";
import { DSAReport } from "coral-server/models/dsaReport";
import { Story } from "coral-server/models/story";
import { retrieveTenant } from "coral-server/models/tenant";

import {
GQLCOMMENT_STATUS,
GQLDSAReportHistoryType,
GQLDSAReportStatus,
} from "coral-server/graph/schema/__generated__/types";

import { moderate } from "../comments/moderation";
import { AugmentedRedis } from "../redis";
import { DSAReport } from "coral-server/models/dsaReport";

const BATCH_SIZE = 500;

Expand Down Expand Up @@ -213,6 +211,12 @@ async function updateUserDSAReports(
const match = mongo.dsaReports().find({
tenantID,
commentID: comment.id,
status: {
$in: [
GQLDSAReportStatus.AWAITING_REVIEW,
GQLDSAReportStatus.UNDER_REVIEW,
],
},
});

if (!match) {
Expand All @@ -221,7 +225,16 @@ async function updateUserDSAReports(

batch.dsaReports.push({
updateMany: {
filter: { tenantID, commentID: comment.id },
filter: {
tenantID,
commentID: comment.id,
status: {
$in: [
GQLDSAReportStatus.AWAITING_REVIEW,
GQLDSAReportStatus.UNDER_REVIEW,
],
},
},
update: {
$status: "VOID",
},
Expand Down Expand Up @@ -313,7 +326,8 @@ export async function deleteUser(
config: Config,
userID: string,
tenantID: string,
now: Date
now: Date,
dsaEnabled: boolean
) {
const user = await mongo.users().findOne({ id: userID, tenantID });
if (!user) {
Expand Down Expand Up @@ -342,10 +356,13 @@ export async function deleteUser(
await deleteUserComments(mongo, redis, config, userID, tenantID, now, true);
}

// If DSA is enabled,
// Update the user's comment's associated DSAReports; set their status to VOID
await updateUserDSAReports(mongo, tenantID, userID);
if (mongo.archive) {
await updateUserDSAReports(mongo, tenantID, userID, true);
if (dsaEnabled) {
await updateUserDSAReports(mongo, tenantID, userID);
if (mongo.archive) {
await updateUserDSAReports(mongo, tenantID, userID, true);
}
}

// Mark the user as deleted.
Expand Down

0 comments on commit bd2ac51

Please sign in to comment.