From 5cb8ec6dba58827e2ce630196045dec5df244b10 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 16 Mar 2022 19:15:02 +0100 Subject: [PATCH] Add report causes --- config.yaml | 10 +++-- src/api_data/server_config.rs | 21 ++++++++++ src/data/comment.rs | 4 +- src/data/config.rs | 3 ++ src/data/mod.rs | 3 +- src/data/report_cause.rs | 72 +++++++++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 src/data/report_cause.rs diff --git a/config.yaml b/config.yaml index e64350b..d21b995 100644 --- a/config.yaml +++ b/config.yaml @@ -14,7 +14,7 @@ server-port: 3000 proxy: "127.0.0.1" # User data storage -storage-url: http://devweb.local/comunic/current/user_data/ +storage-url: http://devweb.internal/comunic/current/user_data/ storage-path: /home/pierre/Documents/projets_web/comunic/current/user_data/ # Specify whether user data files should be made available under the user_data directory @@ -23,14 +23,14 @@ storage-path: /home/pierre/Documents/projets_web/comunic/current/user_data/ serve-storage-files: true # URL where Comunic Terms of use are available -terms-url: http://devweb.local/comunic/current/about.php?cgu -privacy-policy-url: http://devweb.local/comunic/current/about.php?cgu&privacy +terms-url: http://devweb.internal/comunic/current/about.php?cgu +privacy-policy-url: http://devweb.internal/comunic/current/about.php?cgu&privacy # Email where the Comunic staff can be contacted contact-email: contact@communiquons.org # Password reset URL pattern -password-reset-url: https://devweb.local/comunic/v2/reset_password?token=#{TOKEN} +password-reset-url: https://devweb.internal/comunic/v2/reset_password?token=#{TOKEN} # Android application download URL play-store-url: https://play.google.com/store/apps/details?id=org.communiquons.comunic @@ -95,6 +95,8 @@ banner: # Optional URL to "learn more" about the message. Leave an empty value to disable link: https://about.communiquons.org/ +# Allow bad content to be reported by users +allow_reporting: false # List of #Forez groups # diff --git a/src/api_data/server_config.rs b/src/api_data/server_config.rs index c701161..870bafb 100644 --- a/src/api_data/server_config.rs +++ b/src/api_data/server_config.rs @@ -1,6 +1,8 @@ //! # Server configuration //! //! @author Pierre Hubert +use std::collections::HashMap; + use serde::Serialize; use crate::constants::{conservation_policy, MIN_SUPPORTED_MOBILE_VERSION, password_policy}; @@ -8,6 +10,7 @@ use crate::constants::accounts_info_policy::{MAX_FIRST_NAME_LENGTH, MAX_LAST_NAM use crate::constants::conversations::{ALLOWED_CONVERSATION_FILES_TYPES, CONVERSATION_FILES_MAX_SIZE, CONVERSATION_WRITING_EVENT_INTERVAL, CONVERSATION_WRITING_EVENT_LIFETIME, MAX_CONV_IMAGE_MESSAGE_WIDTH, MAX_CONV_LOGO_HEIGHT, MAX_CONV_LOGO_WIDTH, MAX_CONV_MESSAGE_THUMBNAIL_HEIGHT, MAX_CONV_MESSAGE_THUMBNAIL_WIDTH, MAX_CONVERSATION_MESSAGE_LENGTH, MAX_CONVERSATION_NAME_LENGTH, MIN_CONVERSATION_MESSAGE_LENGTH}; use crate::data::api_client::APIClient; use crate::data::config::{Banner, conf}; +use crate::data::report_cause::REPORT_CAUSES; #[derive(Serialize)] struct NotificationsConfig { @@ -63,6 +66,12 @@ struct AccountInformationPolicy { max_location_length: usize, } +#[derive(Serialize)] +struct ReportCause { + id: &'static str, + label: HashMap<&'static str, &'static str>, +} + #[derive(Serialize)] pub struct ServerConfig { min_supported_mobile_version: &'static str, @@ -78,6 +87,7 @@ pub struct ServerConfig { data_conservation_policy: DataConservationPolicy, conversations_policy: ConversationsPolicy, account_info_policy: AccountInformationPolicy, + report_causes: Option>, } impl ServerConfig { @@ -143,6 +153,17 @@ impl ServerConfig { max_last_name_length: MAX_LAST_NAME_LENGTH, max_location_length: MAX_LOCATION_LENGTH, }, + + report_causes: match conf().allow_reporting { + true => Some(REPORT_CAUSES.iter().map(|r| ReportCause { + id: r.id().id(), + label: HashMap::from([ + ("fr", r.label_fr), + ("en", r.label_en) + ]), + }).collect()), + false => None + }, } } } diff --git a/src/data/comment.rs b/src/data/comment.rs index 6445d9b..ce7c99b 100644 --- a/src/data/comment.rs +++ b/src/data/comment.rs @@ -4,9 +4,11 @@ use crate::data::user::UserID; +pub type CommentID = u64; + #[derive(Debug, Clone)] pub struct Comment { - pub id: u64, + pub id: CommentID, pub time_sent: u64, pub user_id: UserID, pub post_id: u64, diff --git a/src/data/config.rs b/src/data/config.rs index 40832db..411ec6d 100644 --- a/src/data/config.rs +++ b/src/data/config.rs @@ -82,6 +82,7 @@ pub struct Config { pub rtc_relay: Option, pub admin_url: String, pub banner: Option, + pub allow_reporting: bool, pub forez_groups: Vec, } @@ -249,6 +250,8 @@ impl Config { banner, + allow_reporting: Self::yaml_bool(parsed, "allow_reporting"), + forez_groups, }; diff --git a/src/data/mod.rs b/src/data/mod.rs index 30f8d03..e9cb537 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -44,4 +44,5 @@ pub mod presence; pub mod admin; pub mod webauthn_config; pub mod admin_action_log; -pub mod u64_visitor; \ No newline at end of file +pub mod u64_visitor; +pub mod report_cause; \ No newline at end of file diff --git a/src/data/report_cause.rs b/src/data/report_cause.rs new file mode 100644 index 0000000..8828c50 --- /dev/null +++ b/src/data/report_cause.rs @@ -0,0 +1,72 @@ +use crate::data::comment::CommentID; +use crate::data::conversation::ConvID; +use crate::data::conversation_message::ConvMessageID; +use crate::data::group_id::GroupID; +use crate::data::post::PostID; +use crate::data::user::UserID; + + +pub enum ReportTarget { + Post(PostID), + Comment(CommentID), + Conversation(ConvID), + ConversationMessage(ConvMessageID), + User(UserID), + Group(GroupID), +} + +#[derive(Eq, PartialEq, Copy, Clone)] +pub struct ReportCauseId(&'static str); + +impl ReportCauseId { + pub fn id(&self) -> &'static str { + self.0 + } +} + +pub struct ReportCause { + _id: &'static str, + pub label_fr: &'static str, + pub label_en: &'static str, +} + +pub const REPORT_CAUSES: [ReportCause; 5] = [ + ReportCause { + _id: "spam", + label_fr: "C'est du spam", + label_en: "It is spam", + }, + ReportCause { + _id: "nudity", + label_fr: "Scènes de nudité / de pornographie", + label_en: "Nudity / Sexual activity", + }, + ReportCause { + _id: "violence", + label_fr: "Scènes de violence", + label_en: "Violence scenes", + }, + ReportCause { + _id: "harassment", + label_fr: "Harcèlement", + label_en: "Harassment", + }, + ReportCause { + _id: "other", + label_fr: "Autre", + label_en: "Other", + } +]; + +impl ReportCause { + pub fn id(&self) -> ReportCauseId { + ReportCauseId(self._id) + } +} + +pub struct Report { + pub user_id: UserID, + pub target: ReportTarget, + pub time: u64, + pub comment: Option, +} \ No newline at end of file