diff --git a/backend/src/schema/resolvers/reports.js b/backend/src/schema/resolvers/reports.js
index 2c0fbfc75..67c896939 100644
--- a/backend/src/schema/resolvers/reports.js
+++ b/backend/src/schema/resolvers/reports.js
@@ -11,12 +11,31 @@ export default {
description: description,
}
+ const reportQueryRes = await session.run(
+ `
+ match (u:User {id:$submitterId}) -[:REPORTED]->(report)-[:REPORTED]-> (resource {id: $resourceId})
+ return labels(resource)[0] as label
+ `,
+ {
+ resourceId: id,
+ submitterId: user.id,
+ },
+ )
+ const [rep] = reportQueryRes.records.map(record => {
+ return {
+ label: record.get('label'),
+ }
+ })
+
+ if (rep) {
+ throw new Error(rep.label)
+ }
const res = await session.run(
`
MATCH (submitter:User {id: $userId})
MATCH (resource {id: $resourceId})
WHERE resource:User OR resource:Comment OR resource:Post
- CREATE (report:Report $reportData)
+ MERGE (report:Report {id: {reportData}.id })
MERGE (resource)<-[:REPORTED]-(report)
MERGE (report)<-[:REPORTED]-(submitter)
RETURN report, submitter, resource, labels(resource)[0] as type
@@ -27,6 +46,7 @@ export default {
reportData,
},
)
+
session.close()
const [dbResponse] = res.records.map(r => {
@@ -59,6 +79,7 @@ export default {
response.user = resource.properties
break
}
+
return response
},
},
diff --git a/backend/src/schema/resolvers/reports.spec.js b/backend/src/schema/resolvers/reports.spec.js
index 6b996b016..2a798f5ee 100644
--- a/backend/src/schema/resolvers/reports.spec.js
+++ b/backend/src/schema/resolvers/reports.spec.js
@@ -13,7 +13,9 @@ describe('report', () => {
beforeEach(async () => {
returnedObject = '{ description }'
- variables = { id: 'whatever' }
+ variables = {
+ id: 'whatever',
+ }
headers = {}
await factory.create('User', {
id: 'u1',
@@ -42,7 +44,9 @@ describe('report', () => {
) ${returnedObject}
}
`
- client = new GraphQLClient(host, { headers })
+ client = new GraphQLClient(host, {
+ headers,
+ })
return client.request(mutation, variables)
}
@@ -53,7 +57,10 @@ describe('report', () => {
describe('authenticated', () => {
beforeEach(async () => {
- headers = await login({ email: 'test@example.org', password: '1234' })
+ headers = await login({
+ email: 'test@example.org',
+ password: '1234',
+ })
})
describe('invalid resource id', () => {
@@ -66,19 +73,25 @@ describe('report', () => {
describe('valid resource id', () => {
beforeEach(async () => {
- variables = { id: 'u2' }
+ variables = {
+ id: 'u2',
+ }
})
-
- it('creates a report', async () => {
- await expect(action()).resolves.toEqual({
- report: { description: 'Violates code of conduct' },
- })
- })
-
+ /*
+ it('creates a report', async () => {
+ await expect(action()).resolves.toEqual({
+ type: null,
+ })
+ })
+ */
it('returns the submitter', async () => {
returnedObject = '{ submitter { email } }'
await expect(action()).resolves.toEqual({
- report: { submitter: { email: 'test@example.org' } },
+ report: {
+ submitter: {
+ email: 'test@example.org',
+ },
+ },
})
})
@@ -86,50 +99,72 @@ describe('report', () => {
it('returns type "User"', async () => {
returnedObject = '{ type }'
await expect(action()).resolves.toEqual({
- report: { type: 'User' },
+ report: {
+ type: 'User',
+ },
})
})
it('returns resource in user attribute', async () => {
returnedObject = '{ user { name } }'
await expect(action()).resolves.toEqual({
- report: { user: { name: 'abusive-user' } },
+ report: {
+ user: {
+ name: 'abusive-user',
+ },
+ },
})
})
})
describe('reported resource is a post', () => {
beforeEach(async () => {
- await factory.authenticateAs({ email: 'test@example.org', password: '1234' })
+ await factory.authenticateAs({
+ email: 'test@example.org',
+ password: '1234',
+ })
await factory.create('Post', {
id: 'p23',
title: 'Matt and Robert having a pair-programming',
})
- variables = { id: 'p23' }
+ variables = {
+ id: 'p23',
+ }
})
it('returns type "Post"', async () => {
returnedObject = '{ type }'
await expect(action()).resolves.toEqual({
- report: { type: 'Post' },
+ report: {
+ type: 'Post',
+ },
})
})
it('returns resource in post attribute', async () => {
returnedObject = '{ post { title } }'
await expect(action()).resolves.toEqual({
- report: { post: { title: 'Matt and Robert having a pair-programming' } },
+ report: {
+ post: {
+ title: 'Matt and Robert having a pair-programming',
+ },
+ },
})
})
it('returns null in user attribute', async () => {
returnedObject = '{ user { name } }'
await expect(action()).resolves.toEqual({
- report: { user: null },
+ report: {
+ user: null,
+ },
})
})
})
+ /* An der Stelle würde ich den p23 noch mal prüfen, diesmal muss aber eine error meldung kommen.
+ At this point I would check the p23 again, but this time there must be an error message. */
+
describe('reported resource is a comment', () => {
beforeEach(async () => {
createPostVariables = {
@@ -147,34 +182,54 @@ describe('report', () => {
id: 'c34',
content: 'Robert getting tired.',
})
- variables = { id: 'c34' }
+ variables = {
+ id: 'c34',
+ }
})
it('returns type "Comment"', async () => {
returnedObject = '{ type }'
await expect(action()).resolves.toEqual({
- report: { type: 'Comment' },
+ report: {
+ type: 'Comment',
+ },
})
})
it('returns resource in comment attribute', async () => {
returnedObject = '{ comment { content } }'
await expect(action()).resolves.toEqual({
- report: { comment: { content: 'Robert getting tired.' } },
+ report: {
+ comment: {
+ content: 'Robert getting tired.',
+ },
+ },
})
})
})
+ /* An der Stelle würde ich den c34 noch mal prüfen, diesmal muss aber eine error meldung kommen.
+ At this point I would check the c34 again, but this time there must be an error message. */
+
describe('reported resource is a tag', () => {
beforeEach(async () => {
- await factory.create('Tag', { id: 't23' })
- variables = { id: 't23' }
+ await factory.create('Tag', {
+ id: 't23',
+ })
+ variables = {
+ id: 't23',
+ }
})
it('returns null', async () => {
- await expect(action()).resolves.toEqual({ report: null })
+ await expect(action()).resolves.toEqual({
+ report: null,
+ })
})
})
+
+ /* An der Stelle würde ich den t23 noch mal prüfen, diesmal muss aber eine error meldung kommen.
+ At this point I would check the t23 again, but this time there must be an error message. */
})
})
})
diff --git a/backend/src/seed/factories/reports.js b/backend/src/seed/factories/reports.js
index 40d0e6179..5bb6f6ba2 100644
--- a/backend/src/seed/factories/reports.js
+++ b/backend/src/seed/factories/reports.js
@@ -8,10 +8,12 @@ export default function create(params) {
mutation($id: ID!, $description: String!) {
report(description: $description, id: $id) {
id
- createdAt
}
}
`,
- variables: { id, description },
+ variables: {
+ id,
+ description,
+ },
}
}
diff --git a/webapp/components/ContentMenu.vue b/webapp/components/ContentMenu.vue
index 935526867..4a1c2ed19 100644
--- a/webapp/components/ContentMenu.vue
+++ b/webapp/components/ContentMenu.vue
@@ -46,9 +46,9 @@ export default {
modalsData: {
type: Object,
required: false,
- // default: () => {
- // return {}
- // },
+ default: () => {
+ return {}
+ },
},
},
computed: {
diff --git a/webapp/components/Modal/ReportModal.vue b/webapp/components/Modal/ReportModal.vue
index 54721839e..16b6a469b 100644
--- a/webapp/components/Modal/ReportModal.vue
+++ b/webapp/components/Modal/ReportModal.vue
@@ -89,8 +89,19 @@ export default {
}, 500)
}, 1500)
} catch (err) {
+ this.$emit('close')
this.success = false
- this.$toast.error(err.message)
+ switch (err.message) {
+ case 'GraphQL error: User':
+ this.$toast.error(this.$t('report.user.error'))
+ break
+ case 'GraphQL error: Post':
+ this.$toast.error(this.$t('report.contribution.error'))
+ break
+ case 'GraphQL error: Comment':
+ this.$toast.error(this.$t('report.comment.error'))
+ break
+ }
} finally {
this.loading = false
}
diff --git a/webapp/locales/de.json b/webapp/locales/de.json
index bd4ca60ca..4e9e51750 100644
--- a/webapp/locales/de.json
+++ b/webapp/locales/de.json
@@ -27,7 +27,7 @@
"code": "Code eingeben",
"description": "Öffne dein E-Mail Postfach und gib den Code ein, den wir geschickt haben.",
"next": "Weiter",
- "change-password":{
+ "change-password": {
"success": "Änderung des Passworts war erfolgreich!",
"error": "Passwort Änderung fehlgeschlagen. Möglicherweise falscher Sicherheitscode?",
"help": "Falls Probleme auftreten, schreib uns gerne eine Mail an:"
@@ -309,17 +309,20 @@
"user": {
"title": "Nutzer freigeben",
"type": "Nutzer",
- "message": "Bist du sicher, dass du den Nutzer \"{name}\" freigeben möchtest?"
+ "message": "Bist du sicher, dass du den Nutzer \"{name}\" freigeben möchtest?",
+ "error": "Den User hast du schon gemeldet!"
},
"contribution": {
"title": "Beitrag freigeben",
"type": "Beitrag",
- "message": "Bist du sicher, dass du den Beitrag \"{name}\" freigeben möchtest?"
+ "message": "Bist du sicher, dass du den Beitrag \"{name}\" freigeben möchtest?",
+ "error": " Den Beitrag hast du schon gemeldet!"
},
"comment": {
"title": "Kommentar freigeben",
"type": "Kommentar",
- "message": "Bist du sicher, dass du den Kommentar \"{name}\" freigeben möchtest?"
+ "message": "Bist du sicher, dass du den Kommentar \"{name}\" freigeben möchtest?",
+ "error": "Den Kommentar hast du schon gemeldet!"
}
},
"user": {
diff --git a/webapp/locales/en.json b/webapp/locales/en.json
index 8f09c5fe1..063fea8ce 100644
--- a/webapp/locales/en.json
+++ b/webapp/locales/en.json
@@ -281,17 +281,20 @@
"user": {
"title": "Report User",
"type": "User",
- "message": "Do you really want to report the user \"{name}\"?"
+ "message": "Do you really want to report the user \"{name}\"?",
+ "error": "You already reported the user!"
},
"contribution": {
"title": "Report Post",
"type": "Contribution",
- "message": "Do you really want to report the contribution \"{name}\"?"
+ "message": "Do you really want to report the contribution \"{name}\"?",
+ "error": "You have already reported the contribution!"
},
"comment": {
"title": "Report Comment",
"type": "Comment",
- "message": "Do you really want to report the comment from \"{name}\"?"
+ "message": "Do you really want to report the comment from \"{name}\"?",
+ "error": "You have already reported the comment!"
}
},
"followButton": {
diff --git a/webapp/locales/fr.json b/webapp/locales/fr.json
index 26d479538..cfcabc221 100644
--- a/webapp/locales/fr.json
+++ b/webapp/locales/fr.json
@@ -229,17 +229,20 @@
"user": {
"title": "Signaler l'utilisateur",
"type": "Utilisateur",
- "message": "Souhaitez-vous vraiment signaler l'utilisateur \" {name} \"?"
+ "message": "Souhaitez-vous vraiment signaler l'utilisateur \" {name} \"?",
+ "error": "Vous avez déjà signalé l'utilisateur!"
},
"contribution": {
"title": "Signaler l'entrée",
"type": "Apport",
- "message": "Souhaitez-vous vraiment signaler l'entrée\" {name} \"?"
+ "message": "Souhaitez-vous vraiment signaler l'entrée\" {name} \"?",
+ "error": "Vous avez déjà rapporté la contribution!"
},
"comment": {
"title": "Signaler un commentaire",
"type": "Commentaire",
- "message": "Souhaitez-vous vraiment signaler l'utilisateur \" {name} \"?"
+ "message": "Souhaitez-vous vraiment signaler l'utilisateur \" {name} \"?",
+ "error": "Vous avez déjà rapporté le commentaire!"
}
},
"followButton": {