Merge pull request #908 from Human-Connection/785-reporting-a-user-post-or-comment

the one-time reporting of a user, post or comment
This commit is contained in:
Alexander Friedland 2019-07-03 08:44:19 +02:00 committed by GitHub
commit 76388d4c4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 140 additions and 42 deletions

View File

@ -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
},
},

View File

@ -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' },
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,35 +182,55 @@ 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. */
})
})
})
})

View File

@ -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,
},
}
}

View File

@ -46,9 +46,9 @@ export default {
modalsData: {
type: Object,
required: false,
// default: () => {
// return {}
// },
default: () => {
return {}
},
},
},
computed: {

View File

@ -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
}

View File

@ -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 \"<b>{name}</b>\" freigeben möchtest?"
"message": "Bist du sicher, dass du den Nutzer \"<b>{name}</b>\" freigeben möchtest?",
"error": "Den User hast du schon gemeldet!"
},
"contribution": {
"title": "Beitrag freigeben",
"type": "Beitrag",
"message": "Bist du sicher, dass du den Beitrag \"<b>{name}</b>\" freigeben möchtest?"
"message": "Bist du sicher, dass du den Beitrag \"<b>{name}</b>\" freigeben möchtest?",
"error": " Den Beitrag hast du schon gemeldet!"
},
"comment": {
"title": "Kommentar freigeben",
"type": "Kommentar",
"message": "Bist du sicher, dass du den Kommentar \"<b>{name}</b>\" freigeben möchtest?"
"message": "Bist du sicher, dass du den Kommentar \"<b>{name}</b>\" freigeben möchtest?",
"error": "Den Kommentar hast du schon gemeldet!"
}
},
"user": {

View File

@ -281,17 +281,20 @@
"user": {
"title": "Report User",
"type": "User",
"message": "Do you really want to report the user \"<b>{name}</b>\"?"
"message": "Do you really want to report the user \"<b>{name}</b>\"?",
"error": "You already reported the user!"
},
"contribution": {
"title": "Report Post",
"type": "Contribution",
"message": "Do you really want to report the contribution \"<b>{name}</b>\"?"
"message": "Do you really want to report the contribution \"<b>{name}</b>\"?",
"error": "You have already reported the contribution!"
},
"comment": {
"title": "Report Comment",
"type": "Comment",
"message": "Do you really want to report the comment from \"<b>{name}</b>\"?"
"message": "Do you really want to report the comment from \"<b>{name}</b>\"?",
"error": "You have already reported the comment!"
}
},
"followButton": {

View File

@ -229,17 +229,20 @@
"user": {
"title": "Signaler l'utilisateur",
"type": "Utilisateur",
"message": "Souhaitez-vous vraiment signaler l'utilisateur \" <b> {name} </b> \"?"
"message": "Souhaitez-vous vraiment signaler l'utilisateur \" <b> {name} </b> \"?",
"error": "Vous avez déjà signalé l'utilisateur!"
},
"contribution": {
"title": "Signaler l'entrée",
"type": "Apport",
"message": "Souhaitez-vous vraiment signaler l'entrée\" <b> {name} </b> \"?"
"message": "Souhaitez-vous vraiment signaler l'entrée\" <b> {name} </b> \"?",
"error": "Vous avez déjà rapporté la contribution!"
},
"comment": {
"title": "Signaler un commentaire",
"type": "Commentaire",
"message": "Souhaitez-vous vraiment signaler l'utilisateur \" <b> {name} </b> \"?"
"message": "Souhaitez-vous vraiment signaler l'utilisateur \" <b> {name} </b> \"?",
"error": "Vous avez déjà rapporté le commentaire!"
}
},
"followButton": {