yggdrasil/models/
settings.rs1pub const DEFAULT_RETENTION_DAYS: i32 = 30;
5pub const DEFAULT_AUTO_PURGE_ENABLED: bool = false;
7#[cfg(feature = "server")]
9pub const MIN_RETENTION_DAYS: i32 = 1;
10#[cfg(feature = "server")]
12pub const MAX_RETENTION_DAYS: i32 = 365;
13
14#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
16pub struct TrashSettings {
17 pub auto_purge_enabled: bool,
19 pub retention_days: i32,
21}
22
23impl Default for TrashSettings {
24 fn default() -> Self {
25 Self {
26 auto_purge_enabled: DEFAULT_AUTO_PURGE_ENABLED,
27 retention_days: DEFAULT_RETENTION_DAYS,
28 }
29 }
30}
31
32impl TrashSettings {
33 #[cfg(feature = "server")]
35 pub fn clamp_retention(days: i32) -> i32 {
36 days.clamp(MIN_RETENTION_DAYS, MAX_RETENTION_DAYS)
37 }
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn default_is_disabled_30_days() {
46 let s = TrashSettings::default();
47 assert!(!s.auto_purge_enabled);
48 assert_eq!(s.retention_days, 30);
49 }
50
51 #[test]
52 #[cfg(feature = "server")]
53 fn clamp_retention_keeps_valid() {
54 assert_eq!(TrashSettings::clamp_retention(7), 7);
55 assert_eq!(TrashSettings::clamp_retention(30), 30);
56 }
57
58 #[test]
59 #[cfg(feature = "server")]
60 fn clamp_retention_clamps_below_min() {
61 assert_eq!(TrashSettings::clamp_retention(0), MIN_RETENTION_DAYS);
62 assert_eq!(TrashSettings::clamp_retention(-5), MIN_RETENTION_DAYS);
63 }
64
65 #[test]
66 #[cfg(feature = "server")]
67 fn clamp_retention_clamps_above_max() {
68 assert_eq!(TrashSettings::clamp_retention(366), MAX_RETENTION_DAYS);
69 assert_eq!(TrashSettings::clamp_retention(i32::MAX), MAX_RETENTION_DAYS);
70 }
71
72 #[test]
73 #[cfg(feature = "server")]
74 fn clamp_retention_boundary() {
75 assert_eq!(
76 TrashSettings::clamp_retention(MIN_RETENTION_DAYS),
77 MIN_RETENTION_DAYS
78 );
79 assert_eq!(
80 TrashSettings::clamp_retention(MAX_RETENTION_DAYS),
81 MAX_RETENTION_DAYS
82 );
83 }
84}