Browse Source

Use ApplicationRecord instead of ActiveRecord::Base (#38975).

Patch by Minoru Maeda (@maeda-m).

git-svn-id: https://svn.redmine.org/redmine/trunk@22619 e93f8b46-1217-0410-a6f0-8f06a7374b81
pull/145/merge
Marius Balteanu 3 months ago
parent
commit
13aeb797cf
63 changed files with 118 additions and 86 deletions
  1. 4
    0
      .rubocop.yml
  2. 0
    4
      .rubocop_todo.yml
  3. 1
    1
      app/controllers/watchers_controller.rb
  4. 32
    0
      app/models/application_record.rb
  5. 1
    1
      app/models/attachment.rb
  6. 1
    1
      app/models/auth_source.rb
  7. 1
    1
      app/models/board.rb
  8. 1
    1
      app/models/change.rb
  9. 1
    1
      app/models/changeset.rb
  10. 1
    1
      app/models/comment.rb
  11. 1
    1
      app/models/custom_field.rb
  12. 1
    1
      app/models/custom_field_enumeration.rb
  13. 1
    1
      app/models/custom_value.rb
  14. 1
    1
      app/models/document.rb
  15. 1
    1
      app/models/email_address.rb
  16. 1
    1
      app/models/enabled_module.rb
  17. 1
    1
      app/models/enumeration.rb
  18. 1
    1
      app/models/import.rb
  19. 1
    1
      app/models/import_item.rb
  20. 1
    1
      app/models/issue.rb
  21. 1
    1
      app/models/issue_category.rb
  22. 1
    1
      app/models/issue_relation.rb
  23. 1
    1
      app/models/issue_status.rb
  24. 1
    1
      app/models/journal.rb
  25. 1
    1
      app/models/journal_detail.rb
  26. 1
    1
      app/models/member.rb
  27. 1
    1
      app/models/member_role.rb
  28. 1
    1
      app/models/message.rb
  29. 1
    1
      app/models/news.rb
  30. 1
    1
      app/models/principal.rb
  31. 1
    1
      app/models/project.rb
  32. 1
    1
      app/models/query.rb
  33. 1
    1
      app/models/repository.rb
  34. 1
    1
      app/models/role.rb
  35. 1
    1
      app/models/setting.rb
  36. 1
    1
      app/models/time_entry.rb
  37. 1
    1
      app/models/token.rb
  38. 1
    1
      app/models/tracker.rb
  39. 1
    1
      app/models/user_preference.rb
  40. 1
    1
      app/models/version.rb
  41. 1
    1
      app/models/watcher.rb
  42. 1
    1
      app/models/wiki.rb
  43. 1
    1
      app/models/wiki_content.rb
  44. 1
    1
      app/models/wiki_content_version.rb
  45. 1
    1
      app/models/wiki_page.rb
  46. 1
    1
      app/models/wiki_redirect.rb
  47. 1
    1
      app/models/workflow_rule.rb
  48. 0
    16
      config/initializers/10-patches.rb
  49. 1
    1
      extra/sample_plugin/app/models/meeting.rb
  50. 1
    1
      lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
  51. 3
    1
      lib/plugins/acts_as_activity_provider/init.rb
  52. 3
    1
      lib/plugins/acts_as_attachable/init.rb
  53. 3
    1
      lib/plugins/acts_as_customizable/init.rb
  54. 3
    1
      lib/plugins/acts_as_event/init.rb
  55. 3
    1
      lib/plugins/acts_as_searchable/init.rb
  56. 1
    1
      lib/plugins/acts_as_tree/README
  57. 3
    1
      lib/plugins/acts_as_tree/init.rb
  58. 1
    1
      lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb
  59. 1
    1
      lib/plugins/acts_as_tree/test/acts_as_tree_test.rb
  60. 3
    1
      lib/plugins/acts_as_watchable/init.rb
  61. 3
    1
      lib/plugins/gravatar/init.rb
  62. 3
    3
      lib/redmine/preparation.rb
  63. 6
    6
      test/unit/initializers/patches_test.rb

+ 4
- 0
.rubocop.yml View File

# TODO: Need to check the impact on plugins. Disable for now. # TODO: Need to check the impact on plugins. Disable for now.
- 'lib/redmine/preparation.rb' - 'lib/redmine/preparation.rb'


Rails/ApplicationRecord:
Exclude:
- 'db/migrate/0*.rb'

Rails/BulkChangeTable: Rails/BulkChangeTable:
Exclude: Exclude:
- 'db/migrate/20120714122200_add_workflows_rule_fields.rb' - 'db/migrate/20120714122200_add_workflows_rule_fields.rb'

+ 0
- 4
.rubocop_todo.yml View File

- 'app/models/mail_handler.rb' - 'app/models/mail_handler.rb'
- 'app/models/mailer.rb' - 'app/models/mailer.rb'


# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/ApplicationRecord:
Enabled: false

# This cop supports safe autocorrection (--autocorrect). # This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Include. # Configuration parameters: Include.
# Include: **/test/**/* # Include: **/test/**/*

+ 1
- 1
app/controllers/watchers_controller.rb View File

nil nil
end end
return unless klass && Class === klass # rubocop:disable Style/CaseEquality return unless klass && Class === klass # rubocop:disable Style/CaseEquality
return unless klass < ActiveRecord::Base
return unless klass < ApplicationRecord
return unless klass < Redmine::Acts::Watchable::InstanceMethods return unless klass < Redmine::Acts::Watchable::InstanceMethods


scope = klass.where(:id => Array.wrap(params[:object_id])) scope = klass.where(:id => Array.wrap(params[:object_id]))

+ 32
- 0
app/models/application_record.rb View File

# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2023 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

# Translate attribute names for validation errors display
def self.human_attribute_name(attr, options = {})
prepared_attr = attr.to_s.sub(/_id$/, '').sub(/^.+\./, '')
class_prefix = name.underscore.tr('/', '_')
redmine_default = [
:"field_#{class_prefix}_#{prepared_attr}",
:"field_#{prepared_attr}"
]
options[:default] = redmine_default + Array(options[:default])
super
end
end

+ 1
- 1
app/models/attachment.rb View File

require "fileutils" require "fileutils"
require "zip" require "zip"


class Attachment < ActiveRecord::Base
class Attachment < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :container, :polymorphic => true belongs_to :container, :polymorphic => true
belongs_to :author, :class_name => "User" belongs_to :author, :class_name => "User"

+ 1
- 1
app/models/auth_source.rb View File

class AuthSourceException < StandardError; end class AuthSourceException < StandardError; end
class AuthSourceTimeoutException < AuthSourceException; end class AuthSourceTimeoutException < AuthSourceException; end


class AuthSource < ActiveRecord::Base
class AuthSource < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
include Redmine::SubclassFactory include Redmine::SubclassFactory
include Redmine::Ciphering include Redmine::Ciphering

+ 1
- 1
app/models/board.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Board < ActiveRecord::Base
class Board < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :project belongs_to :project
has_many :messages, lambda {order("#{Message.table_name}.created_on DESC")}, :dependent => :destroy has_many :messages, lambda {order("#{Message.table_name}.created_on DESC")}, :dependent => :destroy

+ 1
- 1
app/models/change.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Change < ActiveRecord::Base
class Change < ApplicationRecord
belongs_to :changeset belongs_to :changeset


validates_presence_of :changeset_id, :action, :path validates_presence_of :changeset_id, :action, :path

+ 1
- 1
app/models/changeset.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Changeset < ActiveRecord::Base
class Changeset < ApplicationRecord
belongs_to :repository belongs_to :repository
belongs_to :user belongs_to :user
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all has_many :filechanges, :class_name => 'Change', :dependent => :delete_all

+ 1
- 1
app/models/comment.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Comment < ActiveRecord::Base
class Comment < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :commented, :polymorphic => true, :counter_cache => true belongs_to :commented, :polymorphic => true, :counter_cache => true
belongs_to :author, :class_name => 'User' belongs_to :author, :class_name => 'User'

+ 1
- 1
app/models/custom_field.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class CustomField < ActiveRecord::Base
class CustomField < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
include Redmine::SubclassFactory include Redmine::SubclassFactory



+ 1
- 1
app/models/custom_field_enumeration.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class CustomFieldEnumeration < ActiveRecord::Base
class CustomFieldEnumeration < ApplicationRecord
belongs_to :custom_field belongs_to :custom_field


validates_presence_of :name, :position, :custom_field_id validates_presence_of :name, :position, :custom_field_id

+ 1
- 1
app/models/custom_value.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class CustomValue < ActiveRecord::Base
class CustomValue < ApplicationRecord
belongs_to :custom_field belongs_to :custom_field
belongs_to :customized, :polymorphic => true belongs_to :customized, :polymorphic => true



+ 1
- 1
app/models/document.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Document < ActiveRecord::Base
class Document < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :project belongs_to :project
belongs_to :category, :class_name => "DocumentCategory" belongs_to :category, :class_name => "DocumentCategory"

+ 1
- 1
app/models/email_address.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class EmailAddress < ActiveRecord::Base
class EmailAddress < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes


belongs_to :user belongs_to :user

+ 1
- 1
app/models/enabled_module.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class EnabledModule < ActiveRecord::Base
class EnabledModule < ApplicationRecord
belongs_to :project belongs_to :project
acts_as_watchable acts_as_watchable



+ 1
- 1
app/models/enumeration.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Enumeration < ActiveRecord::Base
class Enumeration < ApplicationRecord
include Redmine::SubclassFactory include Redmine::SubclassFactory


default_scope lambda {order(:position)} default_scope lambda {order(:position)}

+ 1
- 1
app/models/import.rb View File



require 'csv' require 'csv'


class Import < ActiveRecord::Base
class Import < ApplicationRecord
has_many :items, :class_name => 'ImportItem', :dependent => :delete_all has_many :items, :class_name => 'ImportItem', :dependent => :delete_all
belongs_to :user belongs_to :user
serialize :settings serialize :settings

+ 1
- 1
app/models/import_item.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class ImportItem < ActiveRecord::Base
class ImportItem < ApplicationRecord
belongs_to :import belongs_to :import


validates_presence_of :import_id, :position validates_presence_of :import_id, :position

+ 1
- 1
app/models/issue.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Issue < ActiveRecord::Base
class Issue < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
include Redmine::Utils::DateCalculation include Redmine::Utils::DateCalculation
include Redmine::I18n include Redmine::I18n

+ 1
- 1
app/models/issue_category.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class IssueCategory < ActiveRecord::Base
class IssueCategory < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :project belongs_to :project
belongs_to :assigned_to, :class_name => 'Principal' belongs_to :assigned_to, :class_name => 'Principal'

+ 1
- 1
app/models/issue_relation.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class IssueRelation < ActiveRecord::Base
class IssueRelation < ApplicationRecord
# Class used to represent the relations of an issue # Class used to represent the relations of an issue
class Relations < Array class Relations < Array
include Redmine::I18n include Redmine::I18n

+ 1
- 1
app/models/issue_status.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class IssueStatus < ActiveRecord::Base
class IssueStatus < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes


before_destroy :check_integrity before_destroy :check_integrity

+ 1
- 1
app/models/journal.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Journal < ActiveRecord::Base
class Journal < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes


belongs_to :journalized, :polymorphic => true belongs_to :journalized, :polymorphic => true

+ 1
- 1
app/models/journal_detail.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class JournalDetail < ActiveRecord::Base
class JournalDetail < ApplicationRecord
belongs_to :journal belongs_to :journal


def custom_field def custom_field

+ 1
- 1
app/models/member.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Member < ActiveRecord::Base
class Member < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :principal, :foreign_key => 'user_id' belongs_to :principal, :foreign_key => 'user_id'
has_many :member_roles, :dependent => :destroy has_many :member_roles, :dependent => :destroy

+ 1
- 1
app/models/member_role.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class MemberRole < ActiveRecord::Base
class MemberRole < ApplicationRecord
belongs_to :member belongs_to :member
belongs_to :role belongs_to :role



+ 1
- 1
app/models/message.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Message < ActiveRecord::Base
class Message < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :board belongs_to :board
belongs_to :author, :class_name => 'User' belongs_to :author, :class_name => 'User'

+ 1
- 1
app/models/news.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class News < ActiveRecord::Base
class News < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :project belongs_to :project
belongs_to :author, :class_name => 'User' belongs_to :author, :class_name => 'User'

+ 1
- 1
app/models/principal.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Principal < ActiveRecord::Base
class Principal < ApplicationRecord
self.table_name = "#{table_name_prefix}users#{table_name_suffix}" self.table_name = "#{table_name_prefix}users#{table_name_suffix}"


# Account statuses # Account statuses

+ 1
- 1
app/models/project.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Project < ActiveRecord::Base
class Project < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
include Redmine::NestedSet::ProjectNestedSet include Redmine::NestedSet::ProjectNestedSet



+ 1
- 1
app/models/query.rb View File

end end
end end


class Query < ActiveRecord::Base
class Query < ApplicationRecord
class StatementInvalid < ::ActiveRecord::StatementInvalid class StatementInvalid < ::ActiveRecord::StatementInvalid
end end



+ 1
- 1
app/models/repository.rb View File



class ScmFetchError < StandardError; end class ScmFetchError < StandardError; end


class Repository < ActiveRecord::Base
class Repository < ApplicationRecord
include Redmine::Ciphering include Redmine::Ciphering
include Redmine::SafeAttributes include Redmine::SafeAttributes



+ 1
- 1
app/models/role.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Role < ActiveRecord::Base
class Role < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes


# Custom coder for the permissions attribute that should be an # Custom coder for the permissions attribute that should be an

+ 1
- 1
app/models/setting.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Setting < ActiveRecord::Base
class Setting < ApplicationRecord
PASSWORD_CHAR_CLASSES = { PASSWORD_CHAR_CLASSES = {
'uppercase' => /[A-Z]/, 'uppercase' => /[A-Z]/,
'lowercase' => /[a-z]/, 'lowercase' => /[a-z]/,

+ 1
- 1
app/models/time_entry.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class TimeEntry < ActiveRecord::Base
class TimeEntry < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
# could have used polymorphic association # could have used polymorphic association
# project association here allows easy loading of time entries at project level with one database trip # project association here allows easy loading of time entries at project level with one database trip

+ 1
- 1
app/models/token.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Token < ActiveRecord::Base
class Token < ApplicationRecord
belongs_to :user belongs_to :user
validates_uniqueness_of :value, :case_sensitive => true validates_uniqueness_of :value, :case_sensitive => true



+ 1
- 1
app/models/tracker.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Tracker < ActiveRecord::Base
class Tracker < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes


CORE_FIELDS_UNDISABLABLE = %w(project_id tracker_id subject is_private).freeze CORE_FIELDS_UNDISABLABLE = %w(project_id tracker_id subject is_private).freeze

+ 1
- 1
app/models/user_preference.rb View File



require 'redmine/my_page' require 'redmine/my_page'


class UserPreference < ActiveRecord::Base
class UserPreference < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes


belongs_to :user belongs_to :user

+ 1
- 1
app/models/version.rb View File

end end
end end


class Version < ActiveRecord::Base
class Version < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes


after_update :update_issues_from_sharing_change after_update :update_issues_from_sharing_change

+ 1
- 1
app/models/watcher.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Watcher < ActiveRecord::Base
class Watcher < ApplicationRecord
belongs_to :watchable, :polymorphic => true belongs_to :watchable, :polymorphic => true
belongs_to :user, :class_name => 'Principal' belongs_to :user, :class_name => 'Principal'



+ 1
- 1
app/models/wiki.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class Wiki < ActiveRecord::Base
class Wiki < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :project belongs_to :project
has_many :pages, lambda {order(Arel.sql('LOWER(title)').asc)}, :class_name => 'WikiPage', :dependent => :destroy has_many :pages, lambda {order(Arel.sql('LOWER(title)').asc)}, :class_name => 'WikiPage', :dependent => :destroy

+ 1
- 1
app/models/wiki_content.rb View File



require 'zlib' require 'zlib'


class WikiContent < ActiveRecord::Base
class WikiContent < ApplicationRecord
self.locking_column = 'version' self.locking_column = 'version'
belongs_to :page, :class_name => 'WikiPage' belongs_to :page, :class_name => 'WikiPage'
belongs_to :author, :class_name => 'User' belongs_to :author, :class_name => 'User'

+ 1
- 1
app/models/wiki_content_version.rb View File



require 'zlib' require 'zlib'


class WikiContentVersion < ActiveRecord::Base
class WikiContentVersion < ApplicationRecord
belongs_to :page, :class_name => 'WikiPage' belongs_to :page, :class_name => 'WikiPage'
belongs_to :author, :class_name => 'User' belongs_to :author, :class_name => 'User'



+ 1
- 1
app/models/wiki_page.rb View File



require 'redmine/string_array_diff/diff' require 'redmine/string_array_diff/diff'


class WikiPage < ActiveRecord::Base
class WikiPage < ApplicationRecord
include Redmine::SafeAttributes include Redmine::SafeAttributes


belongs_to :wiki belongs_to :wiki

+ 1
- 1
app/models/wiki_redirect.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class WikiRedirect < ActiveRecord::Base
class WikiRedirect < ApplicationRecord
belongs_to :wiki belongs_to :wiki


validates_presence_of :wiki_id, :title, :redirects_to validates_presence_of :wiki_id, :title, :redirects_to

+ 1
- 1
app/models/workflow_rule.rb View File

# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class WorkflowRule < ActiveRecord::Base
class WorkflowRule < ApplicationRecord
self.table_name = "#{table_name_prefix}workflows#{table_name_suffix}" self.table_name = "#{table_name_prefix}workflows#{table_name_suffix}"


belongs_to :role belongs_to :role

+ 0
- 16
config/initializers/10-patches.rb View File

# frozen_string_literal: true # frozen_string_literal: true


module ActiveRecord module ActiveRecord
class Base
# Translate attribute names for validation errors display
def self.human_attribute_name(attr, options = {})
prepared_attr = attr.to_s.delete_suffix('_id').sub(/^.+\./, '')
class_prefix = name.underscore.tr('/', '_')

redmine_default = [
:"field_#{class_prefix}_#{prepared_attr}",
:"field_#{prepared_attr}"
]

options[:default] = redmine_default + Array(options[:default])

super
end
end


# Undefines private Kernel#open method to allow using `open` scopes in models. # Undefines private Kernel#open method to allow using `open` scopes in models.
# See Defect #11545 (http://www.redmine.org/issues/11545) for details. # See Defect #11545 (http://www.redmine.org/issues/11545) for details.

+ 1
- 1
extra/sample_plugin/app/models/meeting.rb View File

class Meeting < ActiveRecord::Base
class Meeting < ApplicationRecord
belongs_to :project belongs_to :project


acts_as_event :title => Proc.new {|o| "#{o.scheduled_on} Meeting"}, acts_as_event :title => Proc.new {|o| "#{o.scheduled_on} Meeting"},

+ 1
- 1
lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb View File

end end


def parent_class_name def parent_class_name
options[:parent] || "ActiveRecord::Base"
options[:parent] || "ApplicationRecord"
end end
end end

+ 3
- 1
lib/plugins/acts_as_activity_provider/init.rb View File

# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


require_relative 'lib/acts_as_activity_provider' require_relative 'lib/acts_as_activity_provider'
ActiveRecord::Base.send(:include, Redmine::Acts::ActivityProvider)
Rails.application.reloader.to_prepare do
ApplicationRecord.send(:include, Redmine::Acts::ActivityProvider)
end

+ 3
- 1
lib/plugins/acts_as_attachable/init.rb View File

# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


require_relative 'lib/acts_as_attachable' require_relative 'lib/acts_as_attachable'
ActiveRecord::Base.send(:include, Redmine::Acts::Attachable)
Rails.application.reloader.to_prepare do
ApplicationRecord.send(:include, Redmine::Acts::Attachable)
end

+ 3
- 1
lib/plugins/acts_as_customizable/init.rb View File

# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


require_relative 'lib/acts_as_customizable' require_relative 'lib/acts_as_customizable'
ActiveRecord::Base.send(:include, Redmine::Acts::Customizable)
Rails.application.reloader.to_prepare do
ApplicationRecord.send(:include, Redmine::Acts::Customizable)
end

+ 3
- 1
lib/plugins/acts_as_event/init.rb View File

# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


require_relative 'lib/acts_as_event' require_relative 'lib/acts_as_event'
ActiveRecord::Base.send(:include, Redmine::Acts::Event)
Rails.application.reloader.to_prepare do
ApplicationRecord.send(:include, Redmine::Acts::Event)
end

+ 3
- 1
lib/plugins/acts_as_searchable/init.rb View File

# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


require_relative 'lib/acts_as_searchable' require_relative 'lib/acts_as_searchable'
ActiveRecord::Base.send(:include, Redmine::Acts::Searchable)
Rails.application.reloader.to_prepare do
ApplicationRecord.send(:include, Redmine::Acts::Searchable)
end

+ 1
- 1
lib/plugins/acts_as_tree/README View File

Specify this +acts_as+ extension if you want to model a tree structure by providing a parent association and a children Specify this +acts_as+ extension if you want to model a tree structure by providing a parent association and a children
association. This requires that you have a foreign key column, which by default is called +parent_id+. association. This requires that you have a foreign key column, which by default is called +parent_id+.


class Category < ActiveRecord::Base
class Category < ApplicationRecord
acts_as_tree :order => "name" acts_as_tree :order => "name"
end end



+ 3
- 1
lib/plugins/acts_as_tree/init.rb View File

# frozen_string_literal: true # frozen_string_literal: true


require_relative 'lib/active_record/acts/tree' require_relative 'lib/active_record/acts/tree'
ActiveRecord::Base.send :include, ActiveRecord::Acts::Tree
Rails.application.reloader.to_prepare do
ApplicationRecord.send :include, ActiveRecord::Acts::Tree
end

+ 1
- 1
lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb View File

# Specify this +acts_as+ extension if you want to model a tree structure by providing a parent association and a children # Specify this +acts_as+ extension if you want to model a tree structure by providing a parent association and a children
# association. This requires that you have a foreign key column, which by default is called +parent_id+. # association. This requires that you have a foreign key column, which by default is called +parent_id+.
# #
# class Category < ActiveRecord::Base
# class Category < ApplicationRecord
# acts_as_tree :order => "name" # acts_as_tree :order => "name"
# end # end
# #

+ 1
- 1
lib/plugins/acts_as_tree/test/acts_as_tree_test.rb View File

end end
end end


class Mixin < ActiveRecord::Base
class Mixin < ApplicationRecord
end end


class TreeMixin < Mixin class TreeMixin < Mixin

+ 3
- 1
lib/plugins/acts_as_watchable/init.rb View File



# Include hook code here # Include hook code here
require_relative 'lib/acts_as_watchable' require_relative 'lib/acts_as_watchable'
ActiveRecord::Base.send(:include, Redmine::Acts::Watchable)
Rails.application.reloader.to_prepare do
ApplicationRecord.send(:include, Redmine::Acts::Watchable)
end

+ 3
- 1
lib/plugins/gravatar/init.rb View File

# frozen_string_literal: true # frozen_string_literal: true


require_relative 'lib/gravatar' require_relative 'lib/gravatar'
ActionView::Base.send :include, GravatarHelper::PublicMethods
Rails.application.reloader.to_prepare do
ApplicationRecord.send :include, GravatarHelper::PublicMethods
end

+ 3
- 3
lib/redmine/preparation.rb View File

module Redmine module Redmine
module Preparation module Preparation
def self.prepare def self.prepare
ActiveRecord::Base.include Redmine::Acts::Positioned
ActiveRecord::Base.include Redmine::Acts::Mentionable
ActiveRecord::Base.include Redmine::I18n
ApplicationRecord.include Redmine::Acts::Positioned
ApplicationRecord.include Redmine::Acts::Mentionable
ApplicationRecord.include Redmine::I18n


Scm::Base.add "Subversion" Scm::Base.add "Subversion"
Scm::Base.add "Mercurial" Scm::Base.add "Mercurial"

+ 6
- 6
test/unit/initializers/patches_test.rb View File

Setting.default_language = 'en' Setting.default_language = 'en'
end end


test "ActiveRecord::Base.human_attribute_name should transform name to field_name" do
assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on')
test "ApplicationRecord.human_attribute_name should transform name to field_name" do
assert_equal l('field_last_login_on'), ApplicationRecord.human_attribute_name('last_login_on')
end end


test "ActiveRecord::Base.human_attribute_name should cut extra _id suffix for better validation" do
assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on_id')
test "ApplicationRecord.human_attribute_name should cut extra _id suffix for better validation" do
assert_equal l('field_last_login_on'), ApplicationRecord.human_attribute_name('last_login_on_id')
end end


test "ActiveRecord::Base.human_attribute_name should default to humanized value if no translation has been found (useful for custom fields)" do
assert_equal 'Patch name', ActiveRecord::Base.human_attribute_name('Patch name')
test "ApplicationRecord.human_attribute_name should default to humanized value if no translation has been found (useful for custom fields)" do
assert_equal 'Patch name', ApplicationRecord.human_attribute_name('Patch name')
end end


test 'ActionView::Helpers::FormHelper.date_field should add max=9999-12-31 to limit year value to 4 digits by default' do test 'ActionView::Helpers::FormHelper.date_field should add max=9999-12-31 to limit year value to 4 digits by default' do

Loading…
Cancel
Save