about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-09-27 03:08:19 +0200
committerGitHub <noreply@github.com>2022-09-27 03:08:19 +0200
commit5c9abdeff1d0cf3e14d84c5ae298e6a5beccaf18 (patch)
treeb4bad153eec9f2a39d96a9da342e1618ac43740b /app/models
parent3e0999cd1139d638332d62129dbf0b37263802fd (diff)
Add retention policy for cached content and media (#19232)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/content_retention_policy.rb25
-rw-r--r--app/models/form/admin_settings.rb4
2 files changed, 29 insertions, 0 deletions
diff --git a/app/models/content_retention_policy.rb b/app/models/content_retention_policy.rb
new file mode 100644
index 000000000..b5e922c8c
--- /dev/null
+++ b/app/models/content_retention_policy.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class ContentRetentionPolicy
+  def self.current
+    new
+  end
+
+  def media_cache_retention_period
+    retention_period Setting.media_cache_retention_period
+  end
+
+  def content_cache_retention_period
+    retention_period Setting.content_cache_retention_period
+  end
+
+  def backups_retention_period
+    retention_period Setting.backups_retention_period
+  end
+
+  private
+
+  def retention_period(value)
+    value.days if value.is_a?(Integer) && value.positive?
+  end
+end
diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb
index 97fabc6ac..3a7150916 100644
--- a/app/models/form/admin_settings.rb
+++ b/app/models/form/admin_settings.rb
@@ -32,6 +32,9 @@ class Form::AdminSettings
     show_domain_blocks_rationale
     noindex
     require_invite_text
+    media_cache_retention_period
+    content_cache_retention_period
+    backups_retention_period
   ).freeze
 
   BOOLEAN_KEYS = %i(
@@ -64,6 +67,7 @@ class Form::AdminSettings
   validates :bootstrap_timeline_accounts, existing_username: { multiple: true }
   validates :show_domain_blocks, inclusion: { in: %w(disabled users all) }
   validates :show_domain_blocks_rationale, inclusion: { in: %w(disabled users all) }
+  validates :media_cache_retention_period, :content_cache_retention_period, :backups_retention_period, numericality: { only_integer: true }
 
   def initialize(_attributes = {})
     super