diff --git a/config.yaml b/config.yaml index d21b995..583b50b 100644 --- a/config.yaml +++ b/config.yaml @@ -96,7 +96,7 @@ banner: link: https://about.communiquons.org/ # Allow bad content to be reported by users -allow_reporting: false +allow_reporting: true # List of #Forez groups # diff --git a/docs/db_struct.sql b/docs/db_struct.sql index ad3d075..096a1cc 100644 --- a/docs/db_struct.sql +++ b/docs/db_struct.sql @@ -305,3 +305,12 @@ CREATE TABLE `comunic_admin_log` ( `time` INT NULL, `action` VARCHAR(255) NULL, PRIMARY KEY (`id`)); + +CREATE TABLE `comunic_reports` ( + `id` INT NOT NULL, + `user_id` INT NOT NULL, + `target` VARCHAR(25) NOT NULL, + `target_id` INT NOT NULL, + `time` INT NOT NULL, + `comment` TEXT NULL, + PRIMARY KEY (`id`)); diff --git a/docs/migration.sql b/docs/migration.sql index 105f2e9..cd2b693 100644 --- a/docs/migration.sql +++ b/docs/migration.sql @@ -1 +1,9 @@ --- Nothing yet \ No newline at end of file +-- Create report table +CREATE TABLE `comunic_reports` ( + `id` INT NOT NULL, + `user_id` INT NOT NULL, + `target` VARCHAR(25) NOT NULL, + `target_id` INT NOT NULL, + `time` INT NOT NULL, + `comment` TEXT NULL, + PRIMARY KEY (`id`)); diff --git a/src/api_data/server_config.rs b/src/api_data/server_config.rs index 870bafb..7dc783b 100644 --- a/src/api_data/server_config.rs +++ b/src/api_data/server_config.rs @@ -5,12 +5,12 @@ use std::collections::HashMap; use serde::Serialize; -use crate::constants::{conservation_policy, MIN_SUPPORTED_MOBILE_VERSION, password_policy}; +use crate::constants::{conservation_policy, MIN_SUPPORTED_MOBILE_VERSION, password_policy, reports}; use crate::constants::accounts_info_policy::{MAX_FIRST_NAME_LENGTH, MAX_LAST_NAME_LENGTH, MAX_LOCATION_LENGTH, MIN_FIRST_NAME_LENGTH, MIN_LAST_NAME_LENGTH}; 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; +use crate::data::report::REPORT_CAUSES; #[derive(Serialize)] struct NotificationsConfig { @@ -72,6 +72,12 @@ struct ReportCause { label: HashMap<&'static str, &'static str>, } +#[derive(Serialize)] +struct ReportPolicy { + causes: Vec, + max_comment_length: u32, +} + #[derive(Serialize)] pub struct ServerConfig { min_supported_mobile_version: &'static str, @@ -87,7 +93,7 @@ pub struct ServerConfig { data_conservation_policy: DataConservationPolicy, conversations_policy: ConversationsPolicy, account_info_policy: AccountInformationPolicy, - report_causes: Option>, + report_policy: Option, } impl ServerConfig { @@ -154,14 +160,17 @@ impl ServerConfig { 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()), + report_policy: match conf().allow_reporting { + true => Some(ReportPolicy { + causes: REPORT_CAUSES.iter().map(|r| ReportCause { + id: r.id().id(), + label: HashMap::from([ + ("fr", r.label_fr), + ("en", r.label_en) + ]), + }).collect(), + max_comment_length: reports::MAX_COMMENT_LENGTH, + }), false => None }, } diff --git a/src/constants.rs b/src/constants.rs index b8b6209..c5dd0db 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -266,6 +266,12 @@ pub mod accounts_info_policy { /// Url where Firebase push notifications can be sent pub const FIREBASE_PUSH_MESSAGE_URL: &str = "https://fcm.googleapis.com/v1/projects/{PROJECT_ID}/messages:send"; +/// Reports constants +pub mod reports { + /// Maximum report comment length + pub const MAX_COMMENT_LENGTH: u32 = 500; +} + /// Admin-specific constants pub mod admin { #[derive(Copy, Clone, Eq, PartialEq)] diff --git a/src/data/mod.rs b/src/data/mod.rs index e9cb537..283ffe6 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -45,4 +45,4 @@ pub mod admin; pub mod webauthn_config; pub mod admin_action_log; pub mod u64_visitor; -pub mod report_cause; \ No newline at end of file +pub mod report; \ No newline at end of file diff --git a/src/data/report_cause.rs b/src/data/report.rs similarity index 93% rename from src/data/report_cause.rs rename to src/data/report.rs index 8828c50..8239fd8 100644 --- a/src/data/report_cause.rs +++ b/src/data/report.rs @@ -5,7 +5,6 @@ use crate::data::group_id::GroupID; use crate::data::post::PostID; use crate::data::user::UserID; - pub enum ReportTarget { Post(PostID), Comment(CommentID), @@ -64,7 +63,11 @@ impl ReportCause { } } +#[derive(Ord, PartialOrd, Eq, PartialEq, Hash, Copy, Clone)] +pub struct ReportID(pub u64); + pub struct Report { + pub id: ReportID, pub user_id: UserID, pub target: ReportTarget, pub time: u64,