Skip to content

Commit

Permalink
Merge pull request #1280 from AletheiaFact/refactored-kanban-page
Browse files Browse the repository at this point in the history
Refactored Kanban Page to support different `reviewTask` types
  • Loading branch information
thesocialdev authored Jul 5, 2024
2 parents d7f65b1 + 8c87b90 commit 08edcb0
Show file tree
Hide file tree
Showing 61 changed files with 877 additions and 535 deletions.
51 changes: 51 additions & 0 deletions migrations/20240701184655-add-namespace-in-review-task-schemae.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Db } from "mongodb";
const ObjectId = require("mongodb").ObjectID;

export async function up(db: Db) {
const reviewTasksCursor = await db.collection("reviewtasks").find();

while (await reviewTasksCursor.hasNext()) {
const reviewTask = await reviewTasksCursor.next();
if (reviewTask.machine.context.claimReview.claim) {
const claim = await db.collection("claims").findOne({
_id: ObjectId(reviewTask.machine.context.claimReview.claim),
});

await db
.collection("reviewtasks")
.updateOne(
{ _id: reviewTask._id },
{
$set: {
nameSpace: claim?.nameSpace,
reviewTaskType: "Claim",
},
}
);
}

if (reviewTask.machine.context.claimReview.source) {
const source = await db.collection("sources").findOne({
_id: ObjectId(reviewTask.machine.context.claimReview.source),
});

await db
.collection("reviewtasks")
.updateOne(
{ _id: reviewTask._id },
{
$set: {
nameSpace: source?.nameSpace,
reviewTaskType: "Source",
},
}
);
}
}
}

export async function down(db: Db) {
await db
.collection("reviewtasks")
.updateMany({}, { $unset: { nameSpace: "", reviewTaskType: "" } });
}
36 changes: 36 additions & 0 deletions migrations/20240701191347-add-target-field-in-machine-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Db } from "mongodb";

export async function up(db: Db) {
const reviewTasksCursor = await db.collection("reviewtasks").find();

while (await reviewTasksCursor.hasNext()) {
const reviewTask = await reviewTasksCursor.next();
if (reviewTask.machine.context.claimReview.claim) {
await db.collection("reviewtasks").updateOne(
{ _id: reviewTask._id },
{
$set: {
target: reviewTask.machine.context.claimReview.claim,
},
$unset: {
"machine.context.claimReview.claim": undefined,
},
}
);
}

if (reviewTask.machine.context.claimReview.source) {
await db.collection("reviewtasks").updateOne(
{ _id: reviewTask._id },
{
$set: {
target: reviewTask.machine.context.claimReview.source,
},
$unset: {
"machine.context.claimReview.source": undefined,
},
}
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Db } from "mongodb";

export async function up(db: Db) {
const reviewTasksCursor = await db.collection("reviewtasks").find();

while (await reviewTasksCursor.hasNext()) {
const reviewTask = await reviewTasksCursor.next();

await db
.collection("reviewtasks")
.updateOne(
{ _id: reviewTask._id },
{
$rename: {
"machine.context.claimReview": "machine.context.review",
},
}
);
}
}

export async function down(db: Db) {
const reviewTasksCursor = await db.collection("reviewtasks").find();

while (await reviewTasksCursor.hasNext()) {
const reviewTask = await reviewTasksCursor.next();

await db
.collection("reviewtasks")
.updateOne(
{ _id: reviewTask._id },
{
$rename: {
"machine.context.review": "machine.context.claimReview",
},
}
);
}
}
9 changes: 6 additions & 3 deletions public/locales/en/kanban.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"claimBy": "Claim by",
"assignedTo": "Fact-checkers",
"myTasks": "My tasks only",
"myCrossChecks": "My cross-checks only",
"myReviews": "My reviews only"
"myAssigned": "My tasks only",
"myCrossChecked": "My cross-checks only",
"myReviewed": "My reviews only",
"tabClaimTitle": "Claims",
"tabSourceTitle": "Sources",
"tabVerificationRequestTitle": "Verification Requests"
}
2 changes: 2 additions & 0 deletions public/locales/en/reviewTask.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"submitted": "In review",
"published": "Published",
"draft": "Draft",
"assignedRequest": "User assigned",
"rejectedRequest": "Rejected",
"crossCheckingAlertTitle": "This report is beeing cross-checked",
"reviewingAlertTitle": "This report is beeing reviewed",
"rejectionAlertTitle": "This review was rejected with the following comment",
Expand Down
9 changes: 6 additions & 3 deletions public/locales/pt/kanban.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"claimBy": "Afirmação de",
"assignedTo": "Checadores",
"myTasks": "Apenas minhas tarefas",
"myCrossChecks": "Apenas meus cross-checkings",
"myReviews": "Minhas revisões"
"myAssigned": "Apenas minhas tarefas",
"myCrossChecked": "Apenas meus cross-checkings",
"myReviewed": "Minhas revisões",
"tabClaimTitle": "Afirmações",
"tabSourceTitle": "Fontes",
"tabVerificationRequestTitle": "Denúncias"
}
2 changes: 2 additions & 0 deletions public/locales/pt/reviewTask.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"submitted": "Em revisão",
"published": "Publicado",
"draft": "Rascunho",
"assignedRequest": "Usuário atribuído",
"rejectedRequest": "Rejeitado",
"crossCheckingAlertTitle": "Este relatório está em processo de cross-checking",
"reviewingAlertTitle": "Este relatório está em processo de revisão",
"rejectionAlertTitle": "A revisão foi rejeitada com o seguinte comentário",
Expand Down
28 changes: 18 additions & 10 deletions server/claim-review/claim-review.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { REQUEST } from "@nestjs/core";
import type { BaseRequest } from "../types";
import { ImageService } from "../claim/types/image/image.service";
import { ContentModelEnum } from "../types/enums";
import lookUpPersonalityties from "../mongo-pipelines/lookUpPersonalityties";
import lookupClaims from "../mongo-pipelines/lookupClaims";
import { NameSpaceEnum } from "../auth/name-space/schemas/name-space.schema";
import { EditorParseService } from "../editor-parse/editor-parse.service";
import { WikidataService } from "../wikidata/wikidata.service";
Expand Down Expand Up @@ -149,8 +147,22 @@ export class ClaimReviewService {

aggregation.push(
{ $match: query },
lookUpPersonalityties(TargetModel.ClaimReview),
lookupClaims(TargetModel.ClaimReview),
{
$lookup: {
from: "personalities",
localField: "personality",
foreignField: "_id",
as: "personality",
},
},
{
$lookup: {
from: "claims",
localField: "claim",
foreignField: "_id",
as: "claim",
},
},
{ $unwind: "$claim" },
{
$match: {
Expand Down Expand Up @@ -235,12 +247,8 @@ export class ClaimReviewService {
claimReview.personality = Types.ObjectId(claimReview.personality);
}

if (claimReview.claim) {
claimReview.claim = Types.ObjectId(claimReview.claim);
}

if (claimReview.source) {
claimReview.source = Types.ObjectId(claimReview.source);
if (claimReview.target) {
claimReview.target = Types.ObjectId(claimReview.target);
}

claimReview.usersId = claimReview.report.usersId.map((userId) => {
Expand Down
30 changes: 0 additions & 30 deletions server/mongo-pipelines/lookUpPersonalityties.ts

This file was deleted.

10 changes: 0 additions & 10 deletions server/mongo-pipelines/lookupClaimReviews.ts

This file was deleted.

23 changes: 0 additions & 23 deletions server/mongo-pipelines/lookupClaimRevisions.ts

This file was deleted.

28 changes: 0 additions & 28 deletions server/mongo-pipelines/lookupClaims.ts

This file was deleted.

13 changes: 0 additions & 13 deletions server/mongo-pipelines/lookupUsers.ts

This file was deleted.

17 changes: 12 additions & 5 deletions server/review-task/dto/create-review-task.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { IsEnum, IsNotEmpty, IsObject, IsString } from "class-validator";

import { ClassificationEnum } from "../../claim-review/dto/create-claim-review.dto";
import { Claim } from "../../claim/schemas/claim.schema";
import { Personality } from "../../personality/schemas/personality.schema";
import { User } from "../../users/schemas/user.schema";
import { ApiProperty } from "@nestjs/swagger";
import { ReportModelEnum } from "../../types/enums";
import { ReportModelEnum, ReviewTaskTypeEnum } from "../../types/enums";

export type ReviewTaskMachineContextReviewData = {
usersId?: any[];
Expand All @@ -29,11 +28,9 @@ export type ReviewTaskMachineContextReviewData = {

export type ReviewTaskMachineContext = {
reviewData: ReviewTaskMachineContextReviewData;
claimReview: {
review: {
usersId?: User[];
data_hash: string;
personality: Personality;
claim: Claim;
isPartialReview: boolean;
targetId: string;
};
Expand Down Expand Up @@ -74,4 +71,14 @@ export class CreateReviewTaskDTO {
@IsString()
@ApiProperty()
nameSpace: string;

@IsString()
@ApiProperty()
target: string;

@IsNotEmpty()
@IsEnum(ReviewTaskTypeEnum)
@IsString()
@ApiProperty()
reviewTaskType: string;
}
Loading

0 comments on commit 08edcb0

Please sign in to comment.