mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
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:
commit
76388d4c4b
@ -11,12 +11,31 @@ export default {
|
|||||||
description: description,
|
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(
|
const res = await session.run(
|
||||||
`
|
`
|
||||||
MATCH (submitter:User {id: $userId})
|
MATCH (submitter:User {id: $userId})
|
||||||
MATCH (resource {id: $resourceId})
|
MATCH (resource {id: $resourceId})
|
||||||
WHERE resource:User OR resource:Comment OR resource:Post
|
WHERE resource:User OR resource:Comment OR resource:Post
|
||||||
CREATE (report:Report $reportData)
|
MERGE (report:Report {id: {reportData}.id })
|
||||||
MERGE (resource)<-[:REPORTED]-(report)
|
MERGE (resource)<-[:REPORTED]-(report)
|
||||||
MERGE (report)<-[:REPORTED]-(submitter)
|
MERGE (report)<-[:REPORTED]-(submitter)
|
||||||
RETURN report, submitter, resource, labels(resource)[0] as type
|
RETURN report, submitter, resource, labels(resource)[0] as type
|
||||||
@ -27,6 +46,7 @@ export default {
|
|||||||
reportData,
|
reportData,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
const [dbResponse] = res.records.map(r => {
|
const [dbResponse] = res.records.map(r => {
|
||||||
@ -59,6 +79,7 @@ export default {
|
|||||||
response.user = resource.properties
|
response.user = resource.properties
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
return response
|
return response
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -13,7 +13,9 @@ describe('report', () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
returnedObject = '{ description }'
|
returnedObject = '{ description }'
|
||||||
variables = { id: 'whatever' }
|
variables = {
|
||||||
|
id: 'whatever',
|
||||||
|
}
|
||||||
headers = {}
|
headers = {}
|
||||||
await factory.create('User', {
|
await factory.create('User', {
|
||||||
id: 'u1',
|
id: 'u1',
|
||||||
@ -42,7 +44,9 @@ describe('report', () => {
|
|||||||
) ${returnedObject}
|
) ${returnedObject}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
client = new GraphQLClient(host, { headers })
|
client = new GraphQLClient(host, {
|
||||||
|
headers,
|
||||||
|
})
|
||||||
return client.request(mutation, variables)
|
return client.request(mutation, variables)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +57,10 @@ describe('report', () => {
|
|||||||
|
|
||||||
describe('authenticated', () => {
|
describe('authenticated', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
headers = await login({ email: 'test@example.org', password: '1234' })
|
headers = await login({
|
||||||
|
email: 'test@example.org',
|
||||||
|
password: '1234',
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('invalid resource id', () => {
|
describe('invalid resource id', () => {
|
||||||
@ -66,19 +73,25 @@ describe('report', () => {
|
|||||||
|
|
||||||
describe('valid resource id', () => {
|
describe('valid resource id', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
variables = { id: 'u2' }
|
variables = {
|
||||||
|
id: 'u2',
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
/*
|
||||||
it('creates a report', async () => {
|
it('creates a report', async () => {
|
||||||
await expect(action()).resolves.toEqual({
|
await expect(action()).resolves.toEqual({
|
||||||
report: { description: 'Violates code of conduct' },
|
type: null,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
it('returns the submitter', async () => {
|
it('returns the submitter', async () => {
|
||||||
returnedObject = '{ submitter { email } }'
|
returnedObject = '{ submitter { email } }'
|
||||||
await expect(action()).resolves.toEqual({
|
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 () => {
|
it('returns type "User"', async () => {
|
||||||
returnedObject = '{ type }'
|
returnedObject = '{ type }'
|
||||||
await expect(action()).resolves.toEqual({
|
await expect(action()).resolves.toEqual({
|
||||||
report: { type: 'User' },
|
report: {
|
||||||
|
type: 'User',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns resource in user attribute', async () => {
|
it('returns resource in user attribute', async () => {
|
||||||
returnedObject = '{ user { name } }'
|
returnedObject = '{ user { name } }'
|
||||||
await expect(action()).resolves.toEqual({
|
await expect(action()).resolves.toEqual({
|
||||||
report: { user: { name: 'abusive-user' } },
|
report: {
|
||||||
|
user: {
|
||||||
|
name: 'abusive-user',
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('reported resource is a post', () => {
|
describe('reported resource is a post', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await factory.authenticateAs({ email: 'test@example.org', password: '1234' })
|
await factory.authenticateAs({
|
||||||
|
email: 'test@example.org',
|
||||||
|
password: '1234',
|
||||||
|
})
|
||||||
await factory.create('Post', {
|
await factory.create('Post', {
|
||||||
id: 'p23',
|
id: 'p23',
|
||||||
title: 'Matt and Robert having a pair-programming',
|
title: 'Matt and Robert having a pair-programming',
|
||||||
})
|
})
|
||||||
variables = { id: 'p23' }
|
variables = {
|
||||||
|
id: 'p23',
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns type "Post"', async () => {
|
it('returns type "Post"', async () => {
|
||||||
returnedObject = '{ type }'
|
returnedObject = '{ type }'
|
||||||
await expect(action()).resolves.toEqual({
|
await expect(action()).resolves.toEqual({
|
||||||
report: { type: 'Post' },
|
report: {
|
||||||
|
type: 'Post',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns resource in post attribute', async () => {
|
it('returns resource in post attribute', async () => {
|
||||||
returnedObject = '{ post { title } }'
|
returnedObject = '{ post { title } }'
|
||||||
await expect(action()).resolves.toEqual({
|
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 () => {
|
it('returns null in user attribute', async () => {
|
||||||
returnedObject = '{ user { name } }'
|
returnedObject = '{ user { name } }'
|
||||||
await expect(action()).resolves.toEqual({
|
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', () => {
|
describe('reported resource is a comment', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
createPostVariables = {
|
createPostVariables = {
|
||||||
@ -147,34 +182,54 @@ describe('report', () => {
|
|||||||
id: 'c34',
|
id: 'c34',
|
||||||
content: 'Robert getting tired.',
|
content: 'Robert getting tired.',
|
||||||
})
|
})
|
||||||
variables = { id: 'c34' }
|
variables = {
|
||||||
|
id: 'c34',
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns type "Comment"', async () => {
|
it('returns type "Comment"', async () => {
|
||||||
returnedObject = '{ type }'
|
returnedObject = '{ type }'
|
||||||
await expect(action()).resolves.toEqual({
|
await expect(action()).resolves.toEqual({
|
||||||
report: { type: 'Comment' },
|
report: {
|
||||||
|
type: 'Comment',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns resource in comment attribute', async () => {
|
it('returns resource in comment attribute', async () => {
|
||||||
returnedObject = '{ comment { content } }'
|
returnedObject = '{ comment { content } }'
|
||||||
await expect(action()).resolves.toEqual({
|
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', () => {
|
describe('reported resource is a tag', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await factory.create('Tag', { id: 't23' })
|
await factory.create('Tag', {
|
||||||
variables = { id: 't23' }
|
id: 't23',
|
||||||
|
})
|
||||||
|
variables = {
|
||||||
|
id: 't23',
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null', async () => {
|
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. */
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -8,10 +8,12 @@ export default function create(params) {
|
|||||||
mutation($id: ID!, $description: String!) {
|
mutation($id: ID!, $description: String!) {
|
||||||
report(description: $description, id: $id) {
|
report(description: $description, id: $id) {
|
||||||
id
|
id
|
||||||
createdAt
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
variables: { id, description },
|
variables: {
|
||||||
|
id,
|
||||||
|
description,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,9 +46,9 @@ export default {
|
|||||||
modalsData: {
|
modalsData: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: false,
|
required: false,
|
||||||
// default: () => {
|
default: () => {
|
||||||
// return {}
|
return {}
|
||||||
// },
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|||||||
@ -89,8 +89,19 @@ export default {
|
|||||||
}, 500)
|
}, 500)
|
||||||
}, 1500)
|
}, 1500)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
this.$emit('close')
|
||||||
this.success = false
|
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 {
|
} finally {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
"code": "Code eingeben",
|
"code": "Code eingeben",
|
||||||
"description": "Öffne dein E-Mail Postfach und gib den Code ein, den wir geschickt haben.",
|
"description": "Öffne dein E-Mail Postfach und gib den Code ein, den wir geschickt haben.",
|
||||||
"next": "Weiter",
|
"next": "Weiter",
|
||||||
"change-password":{
|
"change-password": {
|
||||||
"success": "Änderung des Passworts war erfolgreich!",
|
"success": "Änderung des Passworts war erfolgreich!",
|
||||||
"error": "Passwort Änderung fehlgeschlagen. Möglicherweise falscher Sicherheitscode?",
|
"error": "Passwort Änderung fehlgeschlagen. Möglicherweise falscher Sicherheitscode?",
|
||||||
"help": "Falls Probleme auftreten, schreib uns gerne eine Mail an:"
|
"help": "Falls Probleme auftreten, schreib uns gerne eine Mail an:"
|
||||||
@ -309,17 +309,20 @@
|
|||||||
"user": {
|
"user": {
|
||||||
"title": "Nutzer freigeben",
|
"title": "Nutzer freigeben",
|
||||||
"type": "Nutzer",
|
"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": {
|
"contribution": {
|
||||||
"title": "Beitrag freigeben",
|
"title": "Beitrag freigeben",
|
||||||
"type": "Beitrag",
|
"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": {
|
"comment": {
|
||||||
"title": "Kommentar freigeben",
|
"title": "Kommentar freigeben",
|
||||||
"type": "Kommentar",
|
"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": {
|
"user": {
|
||||||
|
|||||||
@ -281,17 +281,20 @@
|
|||||||
"user": {
|
"user": {
|
||||||
"title": "Report User",
|
"title": "Report User",
|
||||||
"type": "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": {
|
"contribution": {
|
||||||
"title": "Report Post",
|
"title": "Report Post",
|
||||||
"type": "Contribution",
|
"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": {
|
"comment": {
|
||||||
"title": "Report Comment",
|
"title": "Report Comment",
|
||||||
"type": "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": {
|
"followButton": {
|
||||||
|
|||||||
@ -229,17 +229,20 @@
|
|||||||
"user": {
|
"user": {
|
||||||
"title": "Signaler l'utilisateur",
|
"title": "Signaler l'utilisateur",
|
||||||
"type": "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": {
|
"contribution": {
|
||||||
"title": "Signaler l'entrée",
|
"title": "Signaler l'entrée",
|
||||||
"type": "Apport",
|
"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": {
|
"comment": {
|
||||||
"title": "Signaler un commentaire",
|
"title": "Signaler un commentaire",
|
||||||
"type": "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": {
|
"followButton": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user