-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix and refactor acts as favorable and acts as watchable #15985
Changes from 17 commits
722eb28
880c232
bde7c1b
965b69f
b406e5e
2c2e907
e4c15e2
48c8987
e7810b7
eaf2b1b
8be0804
a867b3a
83a2306
f9cf8b6
47ca977
4b37ca8
87e9803
f752884
ddf0dc2
73424a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
# 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 | ||
Project | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
# 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 | ||
Forum | ||
Meeting | ||
Message | ||
News | ||
Wiki | ||
WikiPage | ||
WorkPackage | ||
toy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end |
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) | ||
class_name = model_name.singularize.camelize | ||
|
||
class_name.constantize if class_names.include?(class_name) | ||
|
||
end | ||
|
||
def add(*models) | ||
instance_methods_module = module_parent.const_get(:InstanceMethods) | ||
acts_as_method_name = "acts_as_#{module_parent_name.demodulize.underscore}" | ||
|
||
models.each do |model| | ||
unless model.ancestors.include?(instance_methods_module) | ||
raise ArgumentError.new("Model #{model} does not include #{acts_as_method_name}") | ||
end | ||
|
||
class_names << model.name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we change the behavior here to put the class names (as string) in the set and not the classes anymore? This requires us to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is due to this:
But this could be fixed in the to_prepare call to simply clear out the registry. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you prefer a separate method to clear registry (or an argument of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Hash both resolves model reloading problem and doesn't need walking the set using |
||
end | ||
end | ||
|
||
private | ||
|
||
def class_names | ||
@class_names ||= Set.new | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This model is coming from meeting module, so it seems more appropriate to move this line to
modules/meeting/lib/open_project/meeting/engine.rb
, but all modules are loaded throughGemfile.modules
, so not sure what is better - keeping it here or moving it there.