From 35660ca073bddb15ec102ee79afce7ad59bb4615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Fri, 17 Jan 2020 15:22:02 +0100 Subject: [PATCH] Implemented the notifications for filling reports Notification.vue --- backend/src/models/Report.js | 2 +- backend/src/schema/resolvers/reports.js | 6 + backend/src/seed/seed-db.js | 101 ++++++++---- .../components/Notification/Notification.vue | 149 ++++++++++++------ .../NotificationList/NotificationList.vue | 1 + webapp/graphql/User.js | 4 + webapp/locales/de.json | 15 +- webapp/locales/en.json | 15 +- 8 files changed, 212 insertions(+), 81 deletions(-) diff --git a/backend/src/models/Report.js b/backend/src/models/Report.js index 523cfd0fd..d7172cf2e 100644 --- a/backend/src/models/Report.js +++ b/backend/src/models/Report.js @@ -34,7 +34,7 @@ module.exports = { ], invalid: [null], }, - reasonDescription: { type: 'string', allow: [null] }, + reasonDescription: { type: 'string', allow: [null, ''] }, }, }, reviewed: { diff --git a/backend/src/schema/resolvers/reports.js b/backend/src/schema/resolvers/reports.js index 0565c4d8a..1f10ee86d 100644 --- a/backend/src/schema/resolvers/reports.js +++ b/backend/src/schema/resolvers/reports.js @@ -183,4 +183,10 @@ export default { return reviewed }, }, + FILED: { + reasonDescription: async (parent, _params, _context, _resolveInfo) => { + if (typeof parent.reasonDescription !== 'undefined') return parent.reasonDescription + return null + }, + }, } diff --git a/backend/src/seed/seed-db.js b/backend/src/seed/seed-db.js index 2e9f9215d..1dbe3f0d0 100644 --- a/backend/src/seed/seed-db.js +++ b/backend/src/seed/seed-db.js @@ -606,7 +606,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] postId: 'p15', }), ]) - const trollingComment = comments[0] + const trollingCommentC1 = comments[0] + const trollingCommentC2 = comments[1] await Promise.all([ democracy.relateTo(p3, 'post'), @@ -670,16 +671,23 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] louie.relateTo(p10, 'shouted'), ]) - const reports = await Promise.all([ - factory.create('Report'), - factory.create('Report'), - factory.create('Report'), - factory.create('Report'), + const [ + reportAgainstDagobert, + reportAgainstHuey, + reportAgainstTrollingPostP2, + reportAgainstTrollingPostP9, + reportAgainstTrollingCommentC1, + reportAgainstTrollingCommentC2, + reportAgainstDewey, + ] = await Promise.all([ + factory.create('Report', { id: 'reportAgainstDagobert' }), + factory.create('Report', { id: 'reportAgainstHuey' }), + factory.create('Report', { id: 'reportAgainstTrollingPostP2' }), + factory.create('Report', { id: 'reportAgainstTrollingPostP9' }), + factory.create('Report', { id: 'reportAgainstTrollingCommentC1' }), + factory.create('Report', { id: 'reportAgainstTrollingCommentC2' }), + factory.create('Report', { id: 'reportAgainstDewey' }), ]) - const reportAgainstDagobert = reports[0] - const reportAgainstTrollingPost = reports[1] - const reportAgainstTrollingComment = reports[2] - const reportAgainstDewey = reports[3] // report resource first time await Promise.all([ @@ -690,19 +698,40 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] }), reportAgainstDagobert.relateTo(dagobert, 'belongsTo'), - reportAgainstTrollingPost.relateTo(jennyRostock, 'filed', { + reportAgainstHuey.relateTo(jennyRostock, 'filed', { + resourceId: 'u4', + reasonCategory: 'doxing', + reasonDescription: '', + }), + reportAgainstHuey.relateTo(huey, 'belongsTo'), + + reportAgainstTrollingPostP2.relateTo(jennyRostock, 'filed', { resourceId: 'p2', reasonCategory: 'doxing', reasonDescription: "This shouldn't be shown to anybody else! It's my private thing!", }), - reportAgainstTrollingPost.relateTo(p2, 'belongsTo'), + reportAgainstTrollingPostP2.relateTo(p2, 'belongsTo'), - reportAgainstTrollingComment.relateTo(huey, 'filed', { + reportAgainstTrollingPostP9.relateTo(jennyRostock, 'filed', { + resourceId: 'p9', + reasonCategory: 'discrimination_etc', + reasonDescription: 'Discrimination !!!', + }), + reportAgainstTrollingPostP9.relateTo(p9, 'belongsTo'), + + reportAgainstTrollingCommentC1.relateTo(huey, 'filed', { resourceId: 'c1', reasonCategory: 'other', reasonDescription: 'This comment is bigoted', }), - reportAgainstTrollingComment.relateTo(trollingComment, 'belongsTo'), + reportAgainstTrollingCommentC1.relateTo(trollingCommentC1, 'belongsTo'), + + reportAgainstTrollingCommentC2.relateTo(jennyRostock, 'filed', { + resourceId: 'c2', + reasonCategory: 'other', + reasonDescription: 'This comment is bigoted', + }), + reportAgainstTrollingCommentC2.relateTo(trollingCommentC2, 'belongsTo'), reportAgainstDewey.relateTo(dagobert, 'filed', { resourceId: 'u5', @@ -717,11 +746,23 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] read: false, reason: 'filed_report_on_resource', }), - reportAgainstTrollingPost.relateTo(jennyRostock, 'notified', { + reportAgainstHuey.relateTo(jennyRostock, 'notified', { read: false, reason: 'filed_report_on_resource', }), - reportAgainstTrollingComment.relateTo(huey, 'notified', { + reportAgainstTrollingPostP2.relateTo(jennyRostock, 'notified', { + read: false, + reason: 'filed_report_on_resource', + }), + reportAgainstTrollingPostP9.relateTo(jennyRostock, 'notified', { + read: false, + reason: 'filed_report_on_resource', + }), + reportAgainstTrollingCommentC1.relateTo(huey, 'notified', { + read: false, + reason: 'filed_report_on_resource', + }), + reportAgainstTrollingCommentC2.relateTo(jennyRostock, 'notified', { read: false, reason: 'filed_report_on_resource', }), @@ -740,19 +781,19 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] }), reportAgainstDagobert.relateTo(dagobert, 'belongsTo'), - reportAgainstTrollingPost.relateTo(peterLustig, 'filed', { + reportAgainstTrollingPostP2.relateTo(peterLustig, 'filed', { resourceId: 'p2', reasonCategory: 'discrimination_etc', reasonDescription: 'This post is bigoted', }), - reportAgainstTrollingPost.relateTo(p2, 'belongsTo'), + reportAgainstTrollingPostP2.relateTo(p2, 'belongsTo'), - reportAgainstTrollingComment.relateTo(bobDerBaumeister, 'filed', { + reportAgainstTrollingCommentC1.relateTo(bobDerBaumeister, 'filed', { resourceId: 'c1', reasonCategory: 'pornographic_content_links', reasonDescription: 'This comment is porno!!!', }), - reportAgainstTrollingComment.relateTo(trollingComment, 'belongsTo'), + reportAgainstTrollingCommentC1.relateTo(trollingCommentC1, 'belongsTo'), ]) // notify second report filers await Promise.all([ @@ -760,11 +801,11 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] read: false, reason: 'filed_report_on_resource', }), - reportAgainstTrollingPost.relateTo(peterLustig, 'notified', { + reportAgainstTrollingPostP2.relateTo(peterLustig, 'notified', { read: false, reason: 'filed_report_on_resource', }), - reportAgainstTrollingComment.relateTo(bobDerBaumeister, 'notified', { + reportAgainstTrollingCommentC1.relateTo(bobDerBaumeister, 'notified', { read: false, reason: 'filed_report_on_resource', }), @@ -783,16 +824,16 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] resourceId: 'u7', }), dagobert.update({ disabled: true, updatedAt: new Date().toISOString() }), - reportAgainstTrollingPost.relateTo(peterLustig, 'reviewed', { + reportAgainstTrollingPostP2.relateTo(peterLustig, 'reviewed', { ...disableVariables, resourceId: 'p2', }), p2.update({ disabled: true, updatedAt: new Date().toISOString() }), - reportAgainstTrollingComment.relateTo(bobDerBaumeister, 'reviewed', { + reportAgainstTrollingCommentC1.relateTo(bobDerBaumeister, 'reviewed', { ...disableVariables, resourceId: 'c1', }), - trollingComment.update({ disabled: true, updatedAt: new Date().toISOString() }), + trollingCommentC1.update({ disabled: true, updatedAt: new Date().toISOString() }), ]) // second review of resource and close report @@ -803,19 +844,23 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] closed: true, }), dagobert.update({ disabled: false, updatedAt: new Date().toISOString(), closed: true }), - reportAgainstTrollingPost.relateTo(bobDerBaumeister, 'reviewed', { + reportAgainstTrollingPostP2.relateTo(bobDerBaumeister, 'reviewed', { resourceId: 'p2', disable: true, closed: true, }), p2.update({ disabled: true, updatedAt: new Date().toISOString(), closed: true }), - reportAgainstTrollingComment.relateTo(peterLustig, 'reviewed', { + reportAgainstTrollingCommentC1.relateTo(peterLustig, 'reviewed', { ...disableVariables, resourceId: 'c1', disable: true, closed: true, }), - trollingComment.update({ disabled: true, updatedAt: new Date().toISOString(), closed: true }), + trollingCommentC1.update({ + disabled: true, + updatedAt: new Date().toISOString(), + closed: true, + }), ]) await Promise.all( diff --git a/webapp/components/Notification/Notification.vue b/webapp/components/Notification/Notification.vue index dadee672e..6c9a2c6a2 100644 --- a/webapp/components/Notification/Notification.vue +++ b/webapp/components/Notification/Notification.vue @@ -2,31 +2,46 @@ - + - {{ $t(`notifications.reason.${notification.reason}`) }} + {{ $t(`notifications.reason.${notification.reason}` + sourceData.reasonExtention) }} - + - + -
- +
+ +
+
+ {{ $t(`notifications.comment`) }}: - {{ from.contentExcerpt | removeHtml }} + {{ sourceData.contentExcerpt | removeHtml }} +
+
+ + + {{ $t(`notifications.filedReport.category`) }}: + + {{ this.$t('report.reason.category.options.' + sourceData.report.reasonCategory) }} +
+ + {{ $t(`notifications.filedReport.description`) }}: + + + {{ sourceData.report.reasonDescription }} + + + — +
@@ -35,6 +50,7 @@