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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
use compact definition for all projects filters
Ivan Kuchin8f3cd0d04c1f
diff --git a/app/models/queries/projects/filters/ancestor_filter.rb b/app/models/queries/projects/filters/ancestor_filter.rbindex 352b78499ab..e919f346676 100644--- a/app/models/queries/projects/filters/ancestor_filter.rb+++ b/app/models/queries/projects/filters/ancestor_filter.rb@@ -26,69 +26,63 @@# See COPYRIGHT and LICENSE files for more details.#++-module Queries- module Projects- module Filters- class AncestorFilter < ::Queries::Projects::Filters::Base- def apply_to(_query_scope)- case operator- when "="- super- .where(exists_condition.exists)- when "!"- super- .where.not(exists_condition.exists)- else- raise "unsupported operator"- end- end+class Queries::Projects::Filters::AncestorFilter < Queries::Projects::Filters::Base+ def apply_to(_query_scope)+ case operator+ when "="+ super+ .where(exists_condition.exists)+ when "!"+ super+ .where.not(exists_condition.exists)+ else+ raise "unsupported operator"+ end+ end- def where- nil- end+ def where+ nil+ end- def type- :list- end+ def type+ :list+ end- def self.key- :ancestor- end+ def self.key+ :ancestor+ end- private+ private- def type_strategy- # Instead of getting the IDs of all the projects a user is allowed- # to see we only check that the value is an integer. Non valid ids- # will then simply create an empty result but will not cause any- # harm.- @type_strategy ||= ::Queries::Filters::Strategies::IntegerList.new(self)- end+ def type_strategy+ # Instead of getting the IDs of all the projects a user is allowed+ # to see we only check that the value is an integer. Non valid ids+ # will then simply create an empty result but will not cause any+ # harm.+ @type_strategy ||= ::Queries::Filters::Strategies::IntegerList.new(self)+ end- def exists_condition- Project.from("#{Project.table_name} ancestors")- .where(ancestor_condition.and(ancestor_in_values_condition))- .arel- end+ def exists_condition+ Project.from("#{Project.table_name} ancestors")+ .where(ancestor_condition.and(ancestor_in_values_condition))+ .arel+ end- def ancestor_condition- projects_table[:lft]- .gt(projects_ancestor_table[:lft])- .and(projects_table[:rgt].lt(projects_ancestor_table[:rgt]))- end+ def ancestor_condition+ projects_table[:lft]+ .gt(projects_ancestor_table[:lft])+ .and(projects_table[:rgt].lt(projects_ancestor_table[:rgt]))+ end- def ancestor_in_values_condition- projects_ancestor_table[:id].in(values)- end+ def ancestor_in_values_condition+ projects_ancestor_table[:id].in(values)+ end- def projects_table- Project.arel_table- end+ def projects_table+ Project.arel_table+ end- def projects_ancestor_table- projects_table.alias(:ancestors)- end- end- end+ def projects_ancestor_table+ projects_table.alias(:ancestors)endenddiff --git a/app/models/queries/projects/filters/project_status_filter.rb b/app/models/queries/projects/filters/project_status_filter.rbindex 2d5efb60192..62df7e56fbe 100644--- a/app/models/queries/projects/filters/project_status_filter.rb+++ b/app/models/queries/projects/filters/project_status_filter.rb@@ -26,34 +26,28 @@# See COPYRIGHT and LICENSE files for more details.#++-module Queries- module Projects- module Filters- class ProjectStatusFilter < ::Queries::Projects::Filters::Base- include ProjectStatusHelper+class Queries::Projects::Filters::ProjectStatusFilter < Queries::Projects::Filters::Base+ include ProjectStatusHelper- def allowed_values- @allowed_values ||= Project.status_codes.map do |code, id|- [project_status_name_for_code(code), id.to_s]- end- end+ def allowed_values+ @allowed_values ||= Project.status_codes.map do |code, id|+ [project_status_name_for_code(code), id.to_s]+ end+ end- def type- :list_optional- end+ def type+ :list_optional+ end- def where- operator_strategy.sql_for_field(values, model.table_name, :status_code)- end+ def where+ operator_strategy.sql_for_field(values, model.table_name, :status_code)+ end- def self.key- :project_status_code- end+ def self.key+ :project_status_code+ end- def human_name- I18n.t("js.grid.widgets.project_status.title")- end- end- end+ def human_name+ I18n.t("js.grid.widgets.project_status.title")endenddiff --git a/app/models/queries/projects/filters/type_filter.rb b/app/models/queries/projects/filters/type_filter.rbindex bc6ccddf4d3..a5cb9d3978f 100644--- a/app/models/queries/projects/filters/type_filter.rb+++ b/app/models/queries/projects/filters/type_filter.rb@@ -26,40 +26,34 @@# See COPYRIGHT and LICENSE files for more details.#++-module Queries- module Projects- module Filters- class TypeFilter < ::Queries::Projects::Filters::Base- def allowed_values- @allowed_values ||= Type.pluck(:name, :id)- end+class Queries::Projects::Filters::TypeFilter < Queries::Projects::Filters::Base+ def allowed_values+ @allowed_values ||= Type.pluck(:name, :id)+ end- def joins- :types- end+ def joins+ :types+ end- def where- operator_strategy.sql_for_field(values, Type.table_name, :id)- end+ def where+ operator_strategy.sql_for_field(values, Type.table_name, :id)+ end- def type- :list- end+ def type+ :list+ end- def self.key- :type_id- end+ def self.key+ :type_id+ end- private+ private- def type_strategy- # Instead of getting the IDs of all the projects a user is allowed- # to see we only check that the value is an integer. Non valid ids- # will then simply create an empty result but will not cause any- # harm.- @type_strategy ||= ::Queries::Filters::Strategies::IntegerList.new(self)- end- end- end+ def type_strategy+ # Instead of getting the IDs of all the projects a user is allowed+ # to see we only check that the value is an integer. Non valid ids+ # will then simply create an empty result but will not cause any+ # harm.+ @type_strategy ||= ::Queries::Filters::Strategies::IntegerList.new(self)endenddiff --git a/app/models/queries/projects/filters/user_action_filter.rb b/app/models/queries/projects/filters/user_action_filter.rbindex e2e3e180342..2ec56e3c7eb 100644--- a/app/models/queries/projects/filters/user_action_filter.rb+++ b/app/models/queries/projects/filters/user_action_filter.rb@@ -26,50 +26,44 @@# See COPYRIGHT and LICENSE files for more details.#++-module Queries- module Projects- module Filters- class UserActionFilter < ::Queries::Projects::Filters::Base- def allowed_values- @allowed_values ||= Action.default.pluck(:id, :id)- end+class Queries::Projects::Filters::UserActionFilter < Queries::Projects::Filters::Base+ def allowed_values+ @allowed_values ||= Action.default.pluck(:id, :id)+ end- def type- :list_all- end+ def type+ :list_all+ end- def where- operator = if operator_class <= ::Queries::Operators::Equals || operator_class <= ::Queries::Operators::EqualsAll- "IN"- elsif operator_class <= ::Queries::Operators::NotEquals- "NOT IN"- else- raise ArgumentError- end+ def where+ operator = if operator_class <= ::Queries::Operators::Equals || operator_class <= ::Queries::Operators::EqualsAll+ "IN"+ elsif operator_class <= ::Queries::Operators::NotEquals+ "NOT IN"+ else+ raise ArgumentError+ end- capability_select_queries- .map { |query| "#{Project.table_name}.id #{operator} (#{query.to_sql})" }- .join(" AND ")- end+ capability_select_queries+ .map { |query| "#{Project.table_name}.id #{operator} (#{query.to_sql})" }+ .join(" AND ")+ end- private+ private- def capability_select_queries- if operator_class <= ::Queries::Operators::EqualsAll- values.map do |val|- Capability- .where(action: val)- .where(principal: User.current)- .reselect(:context_id)- end- else- [Capability- .where(action: values)- .where(principal: User.current)- .reselect(:context_id)]- end- end+ def capability_select_queries+ if operator_class <= ::Queries::Operators::EqualsAll+ values.map do |val|+ Capability+ .where(action: val)+ .where(principal: User.current)+ .reselect(:context_id)end+ else+ [Capability+ .where(action: values)+ .where(principal: User.current)+ .reselect(:context_id)]endendenddiff --git a/app/models/queries/projects/filters/visible_filter.rb b/app/models/queries/projects/filters/visible_filter.rbindex e279801e364..952665de522 100644--- a/app/models/queries/projects/filters/visible_filter.rb+++ b/app/models/queries/projects/filters/visible_filter.rb@@ -29,41 +29,35 @@# Returns projects visible for a user.# This filter is only useful for admins which want to scope down the list of all the projects to those# visible by a user. For a non admin user, the vanilla project query is already limited to the visible projects.-module Queries- module Projects- module Filters- class VisibleFilter < ::Queries::Projects::Filters::Base- validate :validate_only_single_value+class Queries::Projects::Filters::VisibleFilter < Queries::Projects::Filters::Base+ validate :validate_only_single_value- def allowed_values- # Disregard the need for a proper name (as it is no longer actually displayed)- # in favor of speed.- @allowed_values ||= User.pluck(:id, :id)- end+ def allowed_values+ # Disregard the need for a proper name (as it is no longer actually displayed)+ # in favor of speed.+ @allowed_values ||= User.pluck(:id, :id)+ end- def apply_to(_query_scope)- super.where(id: Project.visible(User.find(values.first)))- end+ def apply_to(_query_scope)+ super.where(id: Project.visible(User.find(values.first)))+ end- def where- # Handled by scope- nil- end+ def where+ # Handled by scope+ nil+ end- def type- :list- end+ def type+ :list+ end- def available_operators- [::Queries::Operators::Equals]- end+ def available_operators+ [::Queries::Operators::Equals]+ end- private+ private- def validate_only_single_value- errors.add(:values, :invalid) if values.length != 1- end- end- end+ def validate_only_single_value+ errors.add(:values, :invalid) if values.length != 1endend