about summary refs log tree commit diff
path: root/app/validators/status_pin_validator.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/validators/status_pin_validator.rb')
-rw-r--r--app/validators/status_pin_validator.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/validators/status_pin_validator.rb b/app/validators/status_pin_validator.rb
new file mode 100644
index 000000000..f557df6af
--- /dev/null
+++ b/app/validators/status_pin_validator.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class StatusPinValidator < ActiveModel::Validator
+  def validate(pin)
+    pin.errors.add(:status, I18n.t('statuses.pin_errors.reblog')) if pin.status.reblog?
+    pin.errors.add(:status, I18n.t('statuses.pin_errors.ownership')) if pin.account_id != pin.status.account_id
+    pin.errors.add(:status, I18n.t('statuses.pin_errors.private')) unless %w(public unlisted).include?(pin.status.visibility)
+  end
+end