From 517963174b607283bba1890575ee87c647b73b4e Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Thu, 5 Dec 2019 19:52:05 +0100 Subject: [PATCH] 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