]> cat aescling's git repositories - mastodon.git/commitdiff
Fix issues when attempting to appeal an old strike (#17554)
authorClaire <claire.github-309c@sitedethib.com>
Wed, 16 Feb 2022 21:29:48 +0000 (22:29 +0100)
committerGitHub <noreply@github.com>
Wed, 16 Feb 2022 21:29:48 +0000 (22:29 +0100)
* Display an error when an appeal could not be submitted

* Do not offer users to appeal old strikes

* Fix 500 error when trying to appeal a strike that is too old

* Avoid using an extra translatable string

app/controllers/disputes/appeals_controller.rb
app/models/appeal.rb
app/policies/account_warning_policy.rb

index 15367c879206172de8f25eb7c7e93d7f962db341..eefd92b5a83c708d5329bc4c08088ee9d48c3a86 100644 (file)
@@ -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
 
index 46f35ae375e357c73a05ed6775becab932b799d9..1f32cfa8b23f57b10c16ecf6cf1c475a0f4f2937 100644 (file)
@@ -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
index 6b92da475bd545daa358785683c7e4cba929888a..65707dfa7cbdb9fb9ff7d8e0c78a679c7394f2c3 100644 (file)
@@ -6,7 +6,7 @@ class AccountWarningPolicy < ApplicationPolicy
   end
 
   def appeal?
-    target?
+    target? && record.created_at >= Appeal::MAX_STRIKE_AGE.ago
   end
 
   private