From dac47d2abbac9f22ec39f29ea9bbb6a31425b764 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 9 Jun 2020 14:07:49 +0200 Subject: [PATCH] Add config option to allow anonymous reporting Signed-off-by: Thomas Citharel --- CHANGELOG.md | 1 + config/config.exs | 3 + config/dev.exs | 5 + js/src/graphql/comment.ts | 2 +- js/src/graphql/config.ts | 3 + js/src/types/config.model.ts | 3 + js/src/views/Event/Event.vue | 21 +++- js/src/views/Home.vue | 2 +- lib/graphql/resolvers/config.ex | 3 + lib/graphql/resolvers/event.ex | 5 +- lib/graphql/resolvers/report.ex | 28 ++++- lib/graphql/schema/config.ex | 5 + lib/mobilizon/config.ex | 4 + test/graphql/resolvers/report_test.exs | 139 ++++++++++++++++++------- 14 files changed, 177 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c162f3f3..3431a8e8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Also make sure to remove the `EnvironmentFile=` line from the systemd service an - Duplicate an event - Ability to handle basic administration settings in the admin panel - Added physical address change to the list of important changes that trigger event notifications +- Config option to allow anonymous reporting ### Changed - Configuration handling (see above) diff --git a/config/config.exs b/config/config.exs index 5ee17d3fa..012953b09 100644 --- a/config/config.exs +++ b/config/config.exs @@ -202,6 +202,9 @@ config :mobilizon, :anonymous, ], captcha: [enabled: false] } + ], + reports: [ + allowed: false ] config :mobilizon, Oban, diff --git a/config/dev.exs b/config/dev.exs index bfddae9ca..a58b0c969 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -92,6 +92,11 @@ config :mobilizon, :instance, # config :mobilizon, :activitypub, sign_object_fetches: false +config :mobilizon, :anonymous, + reports: [ + allowed: true + ] + require Logger cond do diff --git a/js/src/graphql/comment.ts b/js/src/graphql/comment.ts index 329b66057..8447c2f1f 100644 --- a/js/src/graphql/comment.ts +++ b/js/src/graphql/comment.ts @@ -62,7 +62,7 @@ export const COMMENTS_THREADS = gql` } } } - ${COMMENT_RECURSIVE_FRAGMENT} + ${COMMENT_FIELDS_FRAGMENT} `; export const CREATE_COMMENT_FROM_EVENT = gql` diff --git a/js/src/graphql/config.ts b/js/src/graphql/config.ts index f7d07cbf3..d3a29b436 100644 --- a/js/src/graphql/config.ts +++ b/js/src/graphql/config.ts @@ -34,6 +34,9 @@ export const CONFIG = gql` } } } + reports { + allowed + } actorId } location { diff --git a/js/src/types/config.model.ts b/js/src/types/config.model.ts index 07f83f5c2..9c40936c4 100644 --- a/js/src/types/config.model.ts +++ b/js/src/types/config.model.ts @@ -39,6 +39,9 @@ export interface IConfig { }; }; }; + reports: { + allowed: boolean; + }; actorId: string; }; maps: { diff --git a/js/src/views/Event/Event.vue b/js/src/views/Event/Event.vue index fcd64296d..348ead9c1 100644 --- a/js/src/views/Event/Event.vue +++ b/js/src/views/Event/Event.vue @@ -272,7 +272,7 @@ - + {{ $t("Report") }} @@ -750,14 +750,25 @@ export default class Event extends EventMixin { async reportEvent(content: string, forward: boolean) { this.isReportModalActive = false; + // @ts-ignore + this.$refs.reportModal.close(); if (!this.event.organizerActor) return; const eventTitle = this.event.title; + let reporterId = null; + if (this.currentActor.id) { + reporterId = this.currentActor.id; + } else { + if (this.config.anonymous.reports.allowed) { + reporterId = this.config.anonymous.actorId; + } + } + if (!reporterId) return; try { await this.$apollo.mutate({ mutation: CREATE_REPORT, variables: { eventId: this.event.id, - reporterId: this.currentActor.id, + reporterId, reportedId: this.event.organizerActor.id, content, forward, @@ -996,6 +1007,12 @@ export default class Event extends EventMixin { await removeAnonymousParticipation(this.uuid); this.anonymousParticipation = null; } + + get ableToReport(): boolean { + return ( + this.config && (this.currentActor.id != undefined || this.config.anonymous.reports.allowed) + ); + } }