about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/disputes/appeals_controller.rb3
-rw-r--r--app/models/appeal.rb4
-rw-r--r--app/policies/account_warning_policy.rb2
3 files changed, 6 insertions, 3 deletions
diff --git a/app/controllers/disputes/appeals_controller.rb b/app/controllers/disputes/appeals_controller.rb
index 15367c879..eefd92b5a 100644
--- a/app/controllers/disputes/appeals_controller.rb
+++ b/app/controllers/disputes/appeals_controller.rb
@@ -9,7 +9,8 @@ class Disputes::AppealsController < Disputes::BaseController
     @appeal = AppealService.new.call(@strike, appeal_params[:text])
 
     redirect_to disputes_strike_path(@strike), notice: I18n.t('disputes.strikes.appealed_msg')
-  rescue ActiveRecord::RecordInvalid
+  rescue ActiveRecord::RecordInvalid => e
+    @appeal = e.record
     render template: 'disputes/strikes/show'
   end
 
diff --git a/app/models/appeal.rb b/app/models/appeal.rb
index 46f35ae37..1f32cfa8b 100644
--- a/app/models/appeal.rb
+++ b/app/models/appeal.rb
@@ -16,6 +16,8 @@
 #  updated_at             :datetime         not null
 #
 class Appeal < ApplicationRecord
+  MAX_STRIKE_AGE = 20.days
+
   belongs_to :account
   belongs_to :strike, class_name: 'AccountWarning', foreign_key: 'account_warning_id'
   belongs_to :approved_by_account, class_name: 'Account', optional: true
@@ -53,6 +55,6 @@ class Appeal < ApplicationRecord
   private
 
   def validate_time_frame
-    errors.add(:base, I18n.t('strikes.errors.too_late')) if Time.now.utc > (strike.created_at + 20.days)
+    errors.add(:base, I18n.t('strikes.errors.too_late')) if strike.created_at < MAX_STRIKE_AGE.ago
   end
 end
diff --git a/app/policies/account_warning_policy.rb b/app/policies/account_warning_policy.rb
index 6b92da475..65707dfa7 100644
--- a/app/policies/account_warning_policy.rb
+++ b/app/policies/account_warning_policy.rb
@@ -6,7 +6,7 @@ class AccountWarningPolicy < ApplicationPolicy
   end
 
   def appeal?
-    target?
+    target? && record.created_at >= Appeal::MAX_STRIKE_AGE.ago
   end
 
   private