about summary refs log tree commit diff
path: root/app/policies/account_warning_policy.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-02-17 10:58:25 +0100
committerClaire <claire.github-309c@sitedethib.com>2022-02-17 10:58:44 +0100
commitf224237862b009ad4b008a8730c58111f103145b (patch)
tree097c08663c6348914fdf95d2ac9ce57ee2a3307c /app/policies/account_warning_policy.rb
parentec4f9066189fbab4368a275e9cd654dc7ad48217 (diff)
parentac99f586bb4138e083676579097d951434e90515 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `db/schema.rb`:
  Conflict due to glitch-soc adding the `content_type` column on status edits
  and thus having a different schema version number.
  Solved by taking upstream's schema version number, as it is higher than
  glitch-soc's.
Diffstat (limited to 'app/policies/account_warning_policy.rb')
-rw-r--r--app/policies/account_warning_policy.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/policies/account_warning_policy.rb b/app/policies/account_warning_policy.rb
new file mode 100644
index 000000000..65707dfa7
--- /dev/null
+++ b/app/policies/account_warning_policy.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AccountWarningPolicy < ApplicationPolicy
+  def show?
+    target? || staff?
+  end
+
+  def appeal?
+    target? && record.created_at >= Appeal::MAX_STRIKE_AGE.ago
+  end
+
+  private
+
+  def target?
+    record.target_account_id == current_account&.id
+  end
+end