From 517963174b607283bba1890575ee87c647b73b4e Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Thu, 5 Dec 2019 19:52:05 +0100 Subject: [PATCH 1/2] We are not setting disable on Report node - we are adding the report rule which says that if a resource was disabled by a report with this rule, then the latest review was the one that disabled it. - fix db script/ add new directory for keeping record of db scripts --- ...ge_disabled_relationship_to_report_node.sh | 51 +++++++++++++++++++ webapp/graphql/Moderation.js | 1 - 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 neo4j/db_manipulation/change_disabled_relationship_to_report_node.sh diff --git a/neo4j/db_manipulation/change_disabled_relationship_to_report_node.sh b/neo4j/db_manipulation/change_disabled_relationship_to_report_node.sh new file mode 100755 index 000000000..e611382f0 --- /dev/null +++ b/neo4j/db_manipulation/change_disabled_relationship_to_report_node.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +ENV_FILE=$(dirname "$0")/.env +[[ -f "$ENV_FILE" ]] && source "$ENV_FILE" + +if [ -z "$NEO4J_USERNAME" ] || [ -z "$NEO4J_PASSWORD" ]; then + echo "Please set NEO4J_USERNAME and NEO4J_PASSWORD environment variables." + echo "Database manipulation is not possible without connecting to the database." + echo "E.g. you could \`cp .env.template .env\` unless you run the script in a docker container" +fi + +until echo 'RETURN "Connection successful" as info;' | cypher-shell +do + echo "Connecting to neo4j failed, trying again..." + sleep 1 +done + +echo " + :begin + MATCH(user)-[reported:REPORTED]->(resource) + WITH reported, resource, COLLECT(user) as users + MERGE(report:Report)-[:BELONGS_TO]->(resource) + SET report.id = randomUUID(), report.createdAt = toString(datetime()), report.updatedAt = report.createdAt, report.rule = 'latestReviewUpdatedAtRules', report.closed = false + WITH report, users, reported + UNWIND users as user + MERGE (user)-[filed:FILED]->(report) + SET filed = reported + DELETE reported; + + MATCH(moderator)-[disabled:DISABLED]->(resource) + MATCH(report:Report)-[:BELONGS_TO]->(resource) + WITH disabled, resource, COLLECT(moderator) as moderators, report + DELETE disabled + WITH report, moderators, disabled + UNWIND moderators as moderator + MERGE (moderator)-[review:REVIEWED {disable: true}]->(report) + SET review.createdAt = toString(datetime()), review.updatedAt = review.createdAt, review.disable = true; + + MATCH(moderator)-[disabled:DISABLED]->(resource) + WITH disabled, resource, COLLECT(moderator) as moderators + MERGE(report:Report)-[:BELONGS_TO]->(resource) + SET report.id = randomUUID(), report.createdAt = toString(datetime()), report.updatedAt = report.createdAt, report.rule = 'latestReviewUpdatedAtRules', report.closed = false + DELETE disabled + WITH report, moderators, disabled + UNWIND moderators as moderator + MERGE(moderator)-[filed:FILED]->(report) + SET filed.createdAt = toString(datetime()), filed.reasonCategory = 'other', filed.reasonDescription = 'Old DISABLED relations didn\'t enforce mandatory reporting !!! Created automatically to ensure database consistency! Creation date is when the database manipulation happened.' + MERGE (moderator)-[review:REVIEWED {disable: true}]->(report) + SET review.createdAt = toString(datetime()), review.updatedAt = review.createdAt, review.disable = true; + :commit +" | cypher-shell \ No newline at end of file diff --git a/webapp/graphql/Moderation.js b/webapp/graphql/Moderation.js index df9d17870..31dcb2088 100644 --- a/webapp/graphql/Moderation.js +++ b/webapp/graphql/Moderation.js @@ -8,7 +8,6 @@ export const reportsListQuery = () => { id createdAt updatedAt - disable closed reviewed { createdAt From 55f25b153c12c17f918cb573c37a2ee9741fd996 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Thu, 5 Dec 2019 20:31:19 +0100 Subject: [PATCH 2/2] Remove disable from models/Report.js - we are not setting this property, and it's inclusion in this model with a default false value meant that there were no errors with seeded data, but with the data returned from the db_manipulation there was. --- backend/src/models/Report.js | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/models/Report.js b/backend/src/models/Report.js index b66aa4076..2ace4ea73 100644 --- a/backend/src/models/Report.js +++ b/backend/src/models/Report.js @@ -5,7 +5,6 @@ module.exports = { createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, updatedAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, rule: { type: 'string', default: 'latestReviewUpdatedAtRules' }, - disable: { type: 'boolean', default: false }, closed: { type: 'boolean', default: false }, belongsTo: { type: 'relationship',