-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15985 from opf/fix-acts_as_favorable
Fix and refactor acts as favorable and acts as watchable
- Loading branch information
Showing
15 changed files
with
311 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# Be sure to restart your server when you modify this file. | ||
|
||
# For development and non-eager load mode, we need to register the acts_as_favorable models manually | ||
# For development and non-eager load mode, we need to load models using acts_as_favorable manually | ||
# as no eager loading takes place | ||
Rails.application.config.after_initialize do | ||
OpenProject::Acts::Favorable::Registry | ||
.add(Project) | ||
Rails.application.config.to_prepare do | ||
OpenProject::Acts::Favorable::Registry.add( | ||
Project, | ||
reset: true | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
# Be sure to restart your server when you modify this file. | ||
|
||
# In development and non-eager loaded mode, we need to register the acts_as_watchable models manually | ||
# For development and non-eager load mode, we need to load models using acts_as_watchable manually | ||
# as no eager loading takes place | ||
Rails.application.config.after_initialize do | ||
OpenProject::Acts::Watchable::Registry | ||
.add(WorkPackage, Message, Forum, News, Meeting, Wiki, WikiPage) | ||
Rails.application.config.to_prepare do | ||
OpenProject::Acts::Watchable::Registry.add( | ||
Forum, | ||
Meeting, | ||
Message, | ||
News, | ||
Wiki, | ||
WikiPage, | ||
WorkPackage, | ||
reset: true | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2024 the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# 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. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
module OpenProject | ||
module Acts | ||
module RegistryMethods | ||
def instance(model_name) | ||
models[model_name.singularize.camelize] | ||
end | ||
|
||
def add(*models, reset: false) | ||
instance_methods_module = module_parent.const_get(:InstanceMethods) | ||
acts_as_method_name = "acts_as_#{module_parent_name.demodulize.underscore}" | ||
|
||
self.models.clear if reset | ||
|
||
models.each do |model| | ||
unless model.ancestors.include?(instance_methods_module) | ||
raise ArgumentError.new("Model #{model} does not include #{acts_as_method_name}") | ||
end | ||
|
||
self.models[model.name] = model | ||
end | ||
end | ||
|
||
private | ||
|
||
def models | ||
@models ||= Hash.new | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.