1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-21 12:59:22 +00:00

Update database structure

This commit is contained in:
Pierre HUBERT 2022-03-16 19:22:37 +01:00
parent 5cb8ec6dba
commit 0eebfbe98a
7 changed files with 50 additions and 15 deletions

View File

@ -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
#

View File

@ -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`));

View File

@ -1 +1,9 @@
-- Nothing yet
-- 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`));

View File

@ -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<ReportCause>,
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<Vec<ReportCause>>,
report_policy: Option<ReportPolicy>,
}
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
},
}

View File

@ -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)]

View File

@ -45,4 +45,4 @@ pub mod admin;
pub mod webauthn_config;
pub mod admin_action_log;
pub mod u64_visitor;
pub mod report_cause;
pub mod report;

View File

@ -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,