Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

avoid eager loading magic

ulfertsc2b5d38b23bc
diff --git a/app/models/project.rb b/app/models/project.rb
index dfa3c5bef24..69929b12508 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -182,6 +182,9 @@ class Project < ActiveRecord::Base
scope :newest, -> { order(created_at: :desc) }
scope :active, -> { where(active: true) }
+ scope_classes Projects::Scopes::ActivatedTimeActivity,
+ Projects::Scopes::VisibleWithActivatedTimeActivity
+
def visible?(user = User.current)
active? and (public? or user.admin? or user.member_of?(self))
end
diff --git a/app/models/scopes/scoped.rb b/app/models/scopes/scoped.rb
index 6d65104de25..ebe99700c19 100644
--- a/app/models/scopes/scoped.rb
+++ b/app/models/scopes/scoped.rb
@@ -30,16 +30,14 @@ module Scopes::Scoped
extend ActiveSupport::Concern
included do
- base_namespace = name.pluralize.constantize
+ def self.scope_classes(*classes)
+ classes.each do |klass|
+ scope = klass.name.demodulize.underscore
- base_namespace::Scopes.constants.each do |scope|
- scope_class = base_namespace::Scopes.const_get(scope)
-
- define_singleton_method(scope.to_s.underscore) do |*args|
- scope_class.fetch(*args)
+ define_singleton_method(scope) do |*args|
+ klass.fetch(*args)
+ end
end
end
- rescue NameError
- # Do nothing as there apparently are no matching scopes defined
end
end
diff --git a/app/models/version.rb b/app/models/version.rb
index f7dafb50f0c..991d2519712 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -50,6 +50,8 @@ class Version < ActiveRecord::Base
validates_inclusion_of :sharing, in: VERSION_SHARINGS
validate :validate_start_date_before_effective_date
+ scope_classes ::Versions::Scopes::OrderBySemverName
+
scope :visible, ->(*args) {
joins(:project)
.merge(Project.allowed_to(args.first || User.current, :view_work_packages))