diff --git a/backend/src/schema/resolvers/moderation.js b/backend/src/schema/resolvers/moderation.js index 6f841f018..1b6cc4027 100644 --- a/backend/src/schema/resolvers/moderation.js +++ b/backend/src/schema/resolvers/moderation.js @@ -1,4 +1,5 @@ import uuid from 'uuid/v4' +import { undefinedToNullResolver } from './helpers/Resolver' export default { Mutation: { @@ -38,18 +39,15 @@ export default { if (disable === undefined) disable = false // default for creation if (closed === undefined) closed = false // default for creation cypherHeader = ` - MATCH (moderator:User {id: $moderatorId}) MATCH (resource {id: $resourceId}) - WHERE resource:User OR resource:Comment OR resource:Post + WHERE resource: User OR resource: Comment OR resource: Post + OPTIONAL MATCH (:User)-[lastDecision:DECIDED {last: true}]->(resource) + SET (CASE WHEN lastDecision IS NOT NULL THEN lastDecision END).last = false + WITH resource + MATCH (moderator:User {id: $moderatorId}) CREATE (resource)<-[decision:DECIDED]-(moderator) SET decision.last = true - WITH decision, resource, moderator - OPTIONAL MATCH (:User)-[lastDecision:DECIDED {last: true}]->(resource) - SET ( - CASE - WHEN lastDecision IS NOT NULL - THEN lastDecision END).last = false - ` + ` } else { // an open decision … if (disable === undefined) disable = existingDecisionTxResult.decision.properties.disable // default set to existing @@ -77,24 +75,20 @@ export default { } let decisionUUID = null let cypherClosed = '' - // if (closed) { - // decisionUUID = uuid() - // cypherClosed = ` - // OPTIONAL MATCH (:User)-[report:REPORTED {closed: false}]->(resource) - // SET report.closed = true, report.decisionUuid = $decisionUUID - // SET decision.uuid = $decisionUUID - // ` - // } + if (closed) { + decisionUUID = uuid() + cypherClosed = ` + WITH decision, resource, moderator + OPTIONAL MATCH (:User)-[report:REPORTED {closed: false}]->(resource) + SET (CASE WHEN report IS NOT NULL THEN report END).closed = true + SET (CASE WHEN report IS NOT NULL THEN report END).decisionUuid = $decisionUUID + SET decision.uuid = $decisionUUID + ` + } const cypher = cypherHeader + - `SET ( - CASE - WHEN decision.createdAt IS NOT NULL - THEN decision END).updatedAt = toString(datetime()) - SET ( - CASE - WHEN decision.createdAt IS NULL - THEN decision END).createdAt = toString(datetime()) + `SET (CASE WHEN decision.createdAt IS NOT NULL THEN decision END).updatedAt = toString(datetime()) + SET (CASE WHEN decision.createdAt IS NULL THEN decision END).createdAt = toString(datetime()) SET decision.disable = $disable, decision.closed = $closed SET resource.disabled = $disable ` + @@ -148,4 +142,7 @@ export default { return createdRelationshipWithNestedAttributes }, }, + DECIDED: { + ...undefinedToNullResolver(['updatedAt', 'uuid']), + }, } diff --git a/backend/src/schema/resolvers/reports.js b/backend/src/schema/resolvers/reports.js index 083c94362..8e7533a02 100644 --- a/backend/src/schema/resolvers/reports.js +++ b/backend/src/schema/resolvers/reports.js @@ -1,3 +1,5 @@ +import { undefinedToNullResolver } from './helpers/Resolver' + export default { Mutation: { report: async (_parent, params, context, _resolveInfo) => { @@ -11,7 +13,7 @@ export default { MATCH (submitter:User {id: $submitterId}) MATCH (resource {id: $resourceId}) WHERE resource:User OR resource:Comment OR resource:Post - CREATE (resource)<-[report:REPORTED {createdAt: $createdAt, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription}]-(submitter) + CREATE (resource)<-[report:REPORTED {createdAt: $createdAt, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription, closed: false}]-(submitter) RETURN report, submitter, resource, labels(resource)[0] as type `, { @@ -78,7 +80,9 @@ export default { const cypher = ` MATCH (submitter:User)-[report:REPORTED]->(resource) WHERE resource:User OR resource:Comment OR resource:Post - RETURN report, submitter, resource, labels(resource)[0] as type + OPTIONAL MATCH (:User)-[decision:DECIDED {uuid: report.decisionUuid}]->(resource) + OPTIONAL MATCH (:User)-[decisionPending:DECIDED {last: true}]->(resource) + RETURN report, submitter, resource, labels(resource)[0] as type, decision, decisionPending ${orderByClause} ` const result = await session.run(cypher, {}) @@ -88,16 +92,28 @@ export default { submitter: r.get('submitter'), resource: r.get('resource'), type: r.get('type'), + decision: r.get('decision'), + decisionPending: r.get('decisionPending'), } }) if (!dbResponse) return null response = [] dbResponse.forEach(ele => { - const { report, submitter, resource, type } = ele + const { report, submitter, resource, type, decision, decisionPending } = ele const responseEle = { ...report.properties, + decisionAt: decision + ? decision.properties.updatedAt + : decisionPending + ? decisionPending.properties.updatedAt + : null, + decisionDisable: decision + ? decision.properties.disable + : decisionPending + ? decisionPending.properties.disable + : null, post: null, comment: null, user: null, @@ -122,7 +138,19 @@ export default { session.close() } + // Wolle console.log('response: ') + // response.forEach((ele, index) => { + // // console.log('ele #', index, ': ', ele) + // // if (ele.decision === undefined) + // // console.log('ele #', index, ': ', ele) + // if (ele.decision) console.log('ele #', index, ': ', ele) + // }) + // // Wolle console.log('response: ', response) + return response }, }, + REPORTED: { + ...undefinedToNullResolver(['decisionUuid', 'decisionAt', 'decisionDisable']), + }, } diff --git a/backend/src/schema/resolvers/reports.spec.js b/backend/src/schema/resolvers/reports.spec.js index 21b1b4a7b..305ede92b 100644 --- a/backend/src/schema/resolvers/reports.spec.js +++ b/backend/src/schema/resolvers/reports.spec.js @@ -411,6 +411,7 @@ describe('report resources', () => { }) }) }) + describe('query for reported resource', () => { const reportsQuery = gql` query { diff --git a/backend/src/schema/types/type/DECIDED.gql b/backend/src/schema/types/type/DECIDED.gql index d76534256..8469a9d79 100644 --- a/backend/src/schema/types/type/DECIDED.gql +++ b/backend/src/schema/types/type/DECIDED.gql @@ -5,8 +5,7 @@ type DECIDED { # reasonDescription: String disable: Boolean! closed: Boolean! - - # internal + uuid: ID last: Boolean! moderator: User @@ -15,7 +14,7 @@ type DECIDED { # resource: ReportResource # @cypher(statement: "MATCH (resource)<-[:DECIDED]-(:User) RETURN resource") type: String - @cypher(statement: "MATCH (resource)<-[:DECIDED]-(:User) RETURN labels(resource)[0]") + @cypher(statement: "MATCH (resource)<-[:DECIDED]-(user:User) RETURN labels(resource)[0]") user: User post: Post comment: Comment diff --git a/backend/src/schema/types/type/NOTIFIED.gql b/backend/src/schema/types/type/NOTIFIED.gql index 5082b5f7f..6610aa4ca 100644 --- a/backend/src/schema/types/type/NOTIFIED.gql +++ b/backend/src/schema/types/type/NOTIFIED.gql @@ -25,7 +25,7 @@ enum NotificationReason { type Query { notifications(read: Boolean, orderBy: NotificationOrdering): [NOTIFIED] } - + type Mutation { markAsRead(id: ID!): NOTIFIED } diff --git a/backend/src/schema/types/type/REPORTED.gql b/backend/src/schema/types/type/REPORTED.gql index abbf2a7d4..8fce8011f 100644 --- a/backend/src/schema/types/type/REPORTED.gql +++ b/backend/src/schema/types/type/REPORTED.gql @@ -1,7 +1,16 @@ type REPORTED { - createdAt: String - reasonCategory: ReasonCategory - reasonDescription: String + createdAt: String! + reasonCategory: ReasonCategory! + reasonDescription: String! + closed: Boolean! + decisionUuid: ID + + decisionDisable: Boolean + decisionAt: String + + # Wolle decision: DECIDED + # @cypher(statement: "MATCH (resource)<-[decision:DECIDED {uuid: $decisionUuid}]-(user:User) RETURN decision") + submitter: User @cypher(statement: "MATCH (resource)<-[:REPORTED]-(user:User) RETURN user") # not yet supported @@ -12,8 +21,6 @@ type REPORTED { user: User post: Post comment: Comment - - # decided: DECIDED } # this list equals the strings of an array in file "webapp/constants/modals.js" diff --git a/backend/src/seed/seed-db.js b/backend/src/seed/seed-db.js index 9b5b400ab..a2b90b9e5 100644 --- a/backend/src/seed/seed-db.js +++ b/backend/src/seed/seed-db.js @@ -697,6 +697,14 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] // report content a second time authenticatedUser = await dewey.toJson() await Promise.all([ + mutate({ + mutation: reportMutation, + variables: { + resourceId: 'c5', + reasonCategory: 'doxing', + reasonDescription: "That's my friends privat data!", + }, + }), mutate({ mutation: reportMutation, variables: { diff --git a/neo4j/change_disabled_relationship_to_decided_relationship.sh b/neo4j/change_disabled_relationship_to_decided_relationship.sh index 8fb3ac4b2..18d10a8cf 100755 --- a/neo4j/change_disabled_relationship_to_decided_relationship.sh +++ b/neo4j/change_disabled_relationship_to_decided_relationship.sh @@ -20,5 +20,8 @@ MATCH (moderator:User)-[disabled:DISABLED]->(resource) DELETE disabled CREATE (moderator)-[decision:DECIDED]->(resource) SET decision.createdAt = toString(datetime()), decision.disable = true, decision.last = true, decision.closed = false -RETURN decision; +WITH decision +MATCH (:User)-[report:REPORTED]->(resource) +SET report.closed = false +RETURN decision, report; " | cypher-shell diff --git a/webapp/graphql/Moderation.js b/webapp/graphql/Moderation.js index 391c08062..be87be1de 100644 --- a/webapp/graphql/Moderation.js +++ b/webapp/graphql/Moderation.js @@ -8,6 +8,10 @@ export const reportListQuery = () => { createdAt reasonCategory reasonDescription + closed + decisionUuid + decisionAt + decisionDisable type submitter { id diff --git a/webapp/locales/de.json b/webapp/locales/de.json index 11e2053df..90902ee20 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -454,8 +454,9 @@ "type": "Typ", "content": "Inhalt", "author": "Autor", - "decision": "Entscheidung", + "decided": "Entschieden", "noDecision": "Keine Entscheidung!", + "enabledBy": "Aktiviert von", "disabledBy": "Deaktiviert von", "reasonCategory": "Kategorie", "reasonDescription": "Beschreibung", diff --git a/webapp/locales/en.json b/webapp/locales/en.json index e969013ab..3bc2ed7d4 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -455,8 +455,9 @@ "type": "Type", "content": "Content", "author": "Author", - "decision": "Decision", + "decided": "Decided", "noDecision": "No decision!", + "enabledBy": "Enabled by", "disabledBy": "Disabled by", "reasonCategory": "Category", "reasonDescription": "Description", diff --git a/webapp/pages/moderation/index.vue b/webapp/pages/moderation/index.vue index 35c8addfb..1451b8ded 100644 --- a/webapp/pages/moderation/index.vue +++ b/webapp/pages/moderation/index.vue @@ -87,17 +87,30 @@ —