summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2024-06-17 03:11:08 +0000
committerGo MAEDA <maeda@farend.jp>2024-06-17 03:11:08 +0000
commitddde0ff47dbbc8d270e4f3bd77fa3a898fc013a2 (patch)
treeb533d2b4b06d17aa787e2cf45adc830ab5b83aa2
parentb6fe86477033f8994e21f11ba4054908b2002fab (diff)
downloadredmine-ddde0ff47dbbc8d270e4f3bd77fa3a898fc013a2.tar.gz
redmine-ddde0ff47dbbc8d270e4f3bd77fa3a898fc013a2.zip
Fix RuboCop offense Rails/ActiveRecordCallbacksOrder (#39889).
git-svn-id: https://svn.redmine.org/redmine/trunk@22879 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--.rubocop_todo.yml19
-rw-r--r--app/models/attachment.rb2
-rw-r--r--app/models/change.rb2
-rw-r--r--app/models/changeset.rb2
-rw-r--r--app/models/enumeration.rb2
-rw-r--r--app/models/issue.rb6
-rw-r--r--app/models/issue_status.rb2
-rw-r--r--app/models/member_role.rb2
-rw-r--r--app/models/project.rb6
-rw-r--r--app/models/user.rb4
-rw-r--r--app/models/version.rb2
-rw-r--r--app/models/wiki_page.rb2
12 files changed, 17 insertions, 34 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 2f7eb1c78..05932e915 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 20 --no-offense-counts --no-auto-gen-timestamp`
-# using RuboCop version 1.64.0.
+# using RuboCop version 1.64.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -454,23 +454,6 @@ Naming/VariableNumber:
- 'test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb'
- 'test/unit/project_test.rb'
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: Include.
-# Include: app/models/**/*.rb
-Rails/ActiveRecordCallbacksOrder:
- Exclude:
- - 'app/models/attachment.rb'
- - 'app/models/change.rb'
- - 'app/models/changeset.rb'
- - 'app/models/enumeration.rb'
- - 'app/models/issue.rb'
- - 'app/models/issue_status.rb'
- - 'app/models/member_role.rb'
- - 'app/models/project.rb'
- - 'app/models/user.rb'
- - 'app/models/version.rb'
- - 'app/models/wiki_page.rb'
-
# Configuration parameters: Severity, Include.
# Include: app/models/**/*.rb
Rails/ActiveRecordOverride:
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 59addf528..7fc8a8ab0 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -84,9 +84,9 @@ class Attachment < ApplicationRecord
@@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails")
before_create :files_to_final_location
- after_rollback :delete_from_disk, :on => :create
after_commit :delete_from_disk, :on => :destroy
after_commit :reuse_existing_file_if_possible, :on => :create
+ after_rollback :delete_from_disk, :on => :create
safe_attributes 'filename', 'content_type', 'description'
diff --git a/app/models/change.rb b/app/models/change.rb
index f512ad036..c7edd1668 100644
--- a/app/models/change.rb
+++ b/app/models/change.rb
@@ -21,8 +21,8 @@ class Change < ApplicationRecord
belongs_to :changeset
validates_presence_of :changeset_id, :action, :path
- before_save :init_path
before_validation :replace_invalid_utf8_of_path
+ before_save :init_path
def replace_invalid_utf8_of_path
self.path = Redmine::CodesetUtil.replace_invalid_utf8(self.path)
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index d8ce4475b..40e6cf51c 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -60,8 +60,8 @@ class Changeset < ApplicationRecord
where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))
end)
- after_create :scan_for_issues
before_create :before_create_cs
+ after_create :scan_for_issues
def revision=(r)
write_attribute :revision, (r.nil? ? nil : r.to_s)
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index c96c18c98..b97e97e9d 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -28,8 +28,8 @@ class Enumeration < ApplicationRecord
acts_as_customizable
acts_as_tree
- before_destroy :check_integrity
before_save :check_default
+ before_destroy :check_integrity
after_save :update_children_name
validates_presence_of :name
diff --git a/app/models/issue.rb b/app/models/issue.rb
index fdca171c9..95e5a4f24 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -21,6 +21,8 @@ class Issue < ApplicationRecord
include Redmine::SafeAttributes
include Redmine::Utils::DateCalculation
include Redmine::I18n
+ before_validation :default_assign, on: :create
+ before_validation :clear_disabled_fields
before_save :set_parent_id
include Redmine::NestedSet::IssueNestedSet
@@ -107,8 +109,6 @@ class Issue < ApplicationRecord
end
end)
- before_validation :default_assign, on: :create
- before_validation :clear_disabled_fields
before_save :close_duplicates, :update_done_ratio_from_issue_status,
:force_updated_on_change, :update_closed_on
after_save do |issue|
@@ -116,11 +116,11 @@ class Issue < ApplicationRecord
issue.send :after_project_change
end
end
+ after_destroy :update_parent_attributes
after_save :reschedule_following_issues, :update_nested_set_attributes,
:update_parent_attributes, :delete_selected_attachments, :create_journal
# Should be after_create but would be called before previous after_save callbacks
after_save :after_create_from_copy
- after_destroy :update_parent_attributes
# add_auto_watcher needs to run before sending notifications, thus it needs
# to be added after send_notification (after_ callbacks are run in inverse order)
# https://api.rubyonrails.org/v5.2.3/classes/ActiveSupport/Callbacks/ClassMethods.html#method-i-set_callback
diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb
index 7fb0ce007..eb2e488f8 100644
--- a/app/models/issue_status.rb
+++ b/app/models/issue_status.rb
@@ -20,12 +20,12 @@
class IssueStatus < ApplicationRecord
include Redmine::SafeAttributes
+ after_update :handle_is_closed_change
before_destroy :check_integrity
has_many :workflows, :class_name => 'WorkflowTransition', :foreign_key => "old_status_id"
has_many :workflow_transitions_as_new_status, :class_name => 'WorkflowTransition', :foreign_key => "new_status_id"
acts_as_positioned
- after_update :handle_is_closed_change
before_destroy :delete_workflow_rules
validates_presence_of :name
diff --git a/app/models/member_role.rb b/app/models/member_role.rb
index 11f1a04e7..975c6f2b0 100644
--- a/app/models/member_role.rb
+++ b/app/models/member_role.rb
@@ -21,9 +21,9 @@ class MemberRole < ApplicationRecord
belongs_to :member
belongs_to :role
+ after_create :add_role_to_group_users, :add_role_to_subprojects
after_destroy :remove_member_if_empty
- after_create :add_role_to_group_users, :add_role_to_subprojects
after_destroy :remove_inherited_roles
validates_presence_of :role
diff --git a/app/models/project.rb b/app/models/project.rb
index 09927b4cc..42499ae58 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -87,13 +87,13 @@ class Project < ApplicationRecord
validates_exclusion_of :identifier, :in => %w(new)
validate :validate_parent
+ after_update :update_versions_from_hierarchy_change,
+ :if => proc {|project| project.saved_change_to_parent_id?}
+ before_destroy :delete_all_members
after_save :update_inherited_members,
:if => proc {|project| project.saved_change_to_inherit_members?}
after_save :remove_inherited_member_roles, :add_inherited_member_roles,
:if => proc {|project| project.saved_change_to_parent_id?}
- after_update :update_versions_from_hierarchy_change,
- :if => proc {|project| project.saved_change_to_parent_id?}
- before_destroy :delete_all_members
scope :has_module, (lambda do |mod|
where("#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s)
diff --git a/app/models/user.rb b/app/models/user.rb
index 4d78070d0..6e364c5c1 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -126,11 +126,11 @@ class User < Principal
self.valid_statuses = [STATUS_ACTIVE, STATUS_REGISTERED, STATUS_LOCKED]
before_validation :instantiate_email_address
- before_create :set_mail_notification
before_save :generate_password_if_needed, :update_hashed_password
+ before_create :set_mail_notification
before_destroy :remove_references_before_destroy
- after_save :update_notified_project_ids, :destroy_tokens, :deliver_security_notification
after_destroy :deliver_security_notification
+ after_save :update_notified_project_ids, :destroy_tokens, :deliver_security_notification
scope :admin, (lambda do |*args|
admin = args.size > 0 ? !!args.first : true
diff --git a/app/models/version.rb b/app/models/version.rb
index eed2e22d7..7434f0c32 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -123,8 +123,8 @@ class Version < ApplicationRecord
include Redmine::SafeAttributes
after_update :update_issues_from_sharing_change
- after_save :update_default_project_version
before_destroy :nullify_projects_default_version
+ after_save :update_default_project_version
belongs_to :project
has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id', :dependent => :nullify, :extend => FixedIssuesExtension
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index cf23612c0..d76e288d8 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -58,8 +58,8 @@ class WikiPage < ApplicationRecord
validates_associated :content
validate :validate_parent_title
- before_destroy :delete_redirects
before_save :handle_rename_or_move, :update_wiki_start_page
+ before_destroy :delete_redirects
after_save :handle_children_move, :delete_selected_attachments
# eager load information about last updates, without loading text