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
fix queries
Klaus Zanders30ea409178a0
diff --git a/modules/costs/app/models/queries/time_entries.rb b/modules/costs/app/models/queries/time_entries.rbindex dad4e720714..8db6dc35a1b 100644--- a/modules/costs/app/models/queries/time_entries.rb+++ b/modules/costs/app/models/queries/time_entries.rb@@ -29,7 +29,8 @@module Queries::TimeEntries::Queries::Register.register(TimeEntryQuery) dofilter Filters::UserFilter- filter Filters::WorkPackageFilter+ filter Filters::EntityIdFilter+ filter Filters::EntityTypeFilterfilter Filters::ProjectFilterfilter Filters::SpentOnFilterfilter Filters::CreatedAtFilterdiff --git a/modules/costs/app/models/queries/time_entries/filters/activity_filter.rb b/modules/costs/app/models/queries/time_entries/filters/activity_filter.rbindex d75586824d1..d96b2904940 100644--- a/modules/costs/app/models/queries/time_entries/filters/activity_filter.rb+++ b/modules/costs/app/models/queries/time_entries/filters/activity_filter.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/modules/costs/app/models/queries/time_entries/filters/created_at_filter.rb b/modules/costs/app/models/queries/time_entries/filters/created_at_filter.rbindex c5d11aea2e6..1ed1fb70761 100644--- a/modules/costs/app/models/queries/time_entries/filters/created_at_filter.rb+++ b/modules/costs/app/models/queries/time_entries/filters/created_at_filter.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/modules/costs/app/models/queries/time_entries/filters/entity_id_filter.rb b/modules/costs/app/models/queries/time_entries/filters/entity_id_filter.rbnew file mode 100644index 00000000000..c6ebc01ea79--- /dev/null+++ b/modules/costs/app/models/queries/time_entries/filters/entity_id_filter.rb@@ -0,0 +1,39 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++class Queries::TimeEntries::Filters::EntityIdFilter < Queries::TimeEntries::Filters::TimeEntryFilter+ def type+ :integer+ end++ def self.key+ :entity_id+ end+enddiff --git a/modules/costs/app/models/queries/time_entries/filters/work_package_filter.rb b/modules/costs/app/models/queries/time_entries/filters/entity_type_filter.rbsimilarity index 81%rename from modules/costs/app/models/queries/time_entries/filters/work_package_filter.rbrename to modules/costs/app/models/queries/time_entries/filters/entity_type_filter.rbindex 59370929b7e..3705c319b91 100644--- a/modules/costs/app/models/queries/time_entries/filters/work_package_filter.rb+++ b/modules/costs/app/models/queries/time_entries/filters/entity_type_filter.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -26,17 +28,19 @@# See COPYRIGHT and LICENSE files for more details.#++-class Queries::TimeEntries::Filters::WorkPackageFilter < Queries::TimeEntries::Filters::TimeEntryFilter- def allowed_values- # We don't care for the first value as we do not display the values visibly- @allowed_values ||= ::WorkPackage.visible.pluck(:id).map { |id| [id, id.to_s] }- end-+class Queries::TimeEntries::Filters::EntityTypeFilter < Queries::TimeEntries::Filters::TimeEntryFilterdef type:list_optionalend+ def allowed_values+ [+ [WorkPackage.name, WorkPackage.name],+ [Meeting.name, Meeting.name]+ ]+ end+def self.key- :work_package_id+ :entity_typeendenddiff --git a/modules/costs/app/models/queries/time_entries/filters/ongoing_filter.rb b/modules/costs/app/models/queries/time_entries/filters/ongoing_filter.rbindex ee06b12271a..30bd8552b00 100644--- a/modules/costs/app/models/queries/time_entries/filters/ongoing_filter.rb+++ b/modules/costs/app/models/queries/time_entries/filters/ongoing_filter.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/modules/costs/app/models/queries/time_entries/filters/project_filter.rb b/modules/costs/app/models/queries/time_entries/filters/project_filter.rbindex 8e8060c7119..4ed5d79b4e7 100644--- a/modules/costs/app/models/queries/time_entries/filters/project_filter.rb+++ b/modules/costs/app/models/queries/time_entries/filters/project_filter.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/modules/costs/app/models/queries/time_entries/filters/spent_on_filter.rb b/modules/costs/app/models/queries/time_entries/filters/spent_on_filter.rbindex f792cbae8cf..53e0b64d3f2 100644--- a/modules/costs/app/models/queries/time_entries/filters/spent_on_filter.rb+++ b/modules/costs/app/models/queries/time_entries/filters/spent_on_filter.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/modules/costs/app/models/queries/time_entries/filters/time_entry_filter.rb b/modules/costs/app/models/queries/time_entries/filters/time_entry_filter.rbindex e4631a97396..d335dbc1f1b 100644--- a/modules/costs/app/models/queries/time_entries/filters/time_entry_filter.rb+++ b/modules/costs/app/models/queries/time_entries/filters/time_entry_filter.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/modules/costs/app/models/queries/time_entries/filters/updated_at_filter.rb b/modules/costs/app/models/queries/time_entries/filters/updated_at_filter.rbindex 25a83fce299..b036fbc552b 100644--- a/modules/costs/app/models/queries/time_entries/filters/updated_at_filter.rb+++ b/modules/costs/app/models/queries/time_entries/filters/updated_at_filter.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/modules/costs/app/models/queries/time_entries/filters/user_filter.rb b/modules/costs/app/models/queries/time_entries/filters/user_filter.rbindex c6339c87ca2..b1d73a0402c 100644--- a/modules/costs/app/models/queries/time_entries/filters/user_filter.rb+++ b/modules/costs/app/models/queries/time_entries/filters/user_filter.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbHdiff --git a/modules/costs/app/models/time_entries/scopes/ongoing.rb b/modules/costs/app/models/time_entries/scopes/ongoing.rbindex 6a4dec0c6f7..5160f27aa2b 100644--- a/modules/costs/app/models/time_entries/scopes/ongoing.rb+++ b/modules/costs/app/models/time_entries/scopes/ongoing.rb@@ -37,7 +37,12 @@ module TimeEntries::Scopesdef visible_ongoing(user = User.current)TimeEntry- .where(work_package_id: visible_work_packages(user).select(:id), user:, ongoing: true)+ .where(+ entity_type: "WorkPackage",+ entity_id: visible_work_packages(user).select(:id),+ user:,+ ongoing: true+ )enddef visible_work_packages(user)diff --git a/modules/costs/lib/api/v3/time_entries/available_work_packages_on_edit_api.rb b/modules/costs/lib/api/v3/time_entries/available_work_packages_on_edit_api.rbindex d054c3344c4..bbf2c9c44fc 100644--- a/modules/costs/lib/api/v3/time_entries/available_work_packages_on_edit_api.rb+++ b/modules/costs/lib/api/v3/time_entries/available_work_packages_on_edit_api.rb@@ -42,7 +42,7 @@ module APIdef allowed_scopeedit_scope = WorkPackage.where(project_id: Project.allowed_to(User.current, :edit_time_entries))edit_own_scope = WorkPackage.where(id: WorkPackage.allowed_to(User.current, :edit_own_time_entries))- ongoing_scope = WorkPackage.where(id: TimeEntry.visible_ongoing.select(:work_package_id))+ ongoing_scope = WorkPackage.where(id: TimeEntry.where(entity_type: "WorkPackage").visible_ongoing.select(:entity_id))edit_scope.or(edit_own_scope)diff --git a/modules/costs/spec/models/queries/time_entries/filters/work_package_filter_spec.rb b/modules/costs/spec/models/queries/time_entries/filters/entity_id_filter_spec.rbsimilarity index 55%rename from modules/costs/spec/models/queries/time_entries/filters/work_package_filter_spec.rbrename to modules/costs/spec/models/queries/time_entries/filters/entity_id_filter_spec.rbindex ab70ef0d26f..417cea1cecd 100644--- a/modules/costs/spec/models/queries/time_entries/filters/work_package_filter_spec.rb+++ b/modules/costs/spec/models/queries/time_entries/filters/entity_id_filter_spec.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -28,34 +30,6 @@require "spec_helper"-RSpec.describe Queries::TimeEntries::Filters::WorkPackageFilter do- let(:work_package1) { build_stubbed(:work_package) }- let(:work_package2) { build_stubbed(:work_package) }-- before do- allow(WorkPackage)- .to receive_message_chain(:visible, :pluck)- .with(:id)- .and_return([work_package1.id, work_package2.id])- end-- it_behaves_like "basic query filter" do- let(:class_key) { :work_package_id }- let(:type) { :list_optional }- let(:name) { TimeEntry.human_attribute_name(:work_package) }-- describe "#allowed_values" do- it "is a list of the possible values" do- expected = [[work_package1.id, work_package1.id.to_s], [work_package2.id, work_package2.id.to_s]]-- expect(instance.allowed_values).to match_array(expected)- end- end- end-- it_behaves_like "list_optional query filter" do- let(:attribute) { :work_package_id }- let(:model) { TimeEntry }- let(:valid_values) { [work_package1.id.to_s] }- end+RSpec.describe Queries::TimeEntries::Filters::EntityIdFilter do+ pending "implement me"enddiff --git a/modules/costs/spec/models/queries/time_entries/filters/entity_type_filter_spec.rb b/modules/costs/spec/models/queries/time_entries/filters/entity_type_filter_spec.rbnew file mode 100644index 00000000000..f18a1d4f005--- /dev/null+++ b/modules/costs/spec/models/queries/time_entries/filters/entity_type_filter_spec.rb@@ -0,0 +1,35 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++require "spec_helper"++RSpec.describe Queries::TimeEntries::Filters::EntityTypeFilter do+ pending "implement me"+enddiff --git a/modules/costs/spec/models/queries/time_entries/time_entry_query_integration_spec.rb b/modules/costs/spec/models/queries/time_entries/time_entry_query_integration_spec.rbindex 60039fd1cd4..1a25807c89f 100644--- a/modules/costs/spec/models/queries/time_entries/time_entry_query_integration_spec.rb+++ b/modules/costs/spec/models/queries/time_entries/time_entry_query_integration_spec.rb@@ -37,13 +37,13 @@ RSpec.describe Queries::TimeEntries::TimeEntryQuery, "integration" docontext "when using ongoing filter" dolet(:project) { create(:project, enabled_module_names: %w[costs]) }- let(:user) { create(:user, member_with_permissions: { project => %i[log_own_time] }) }+ let(:user) { create(:user, member_with_permissions: { project => %i[log_own_time view_own_time_entries] }) }let(:work_package) { create(:work_package, project:) }- let(:other_user) { create(:user, member_with_permissions: { project => %i[log_own_time] }) }+ let(:other_user) { create(:user, member_with_permissions: { project => %i[log_own_time view_own_time_entries] }) }let(:other_work_package) { create(:work_package, project:) }- let!(:user_timer) { create(:time_entry, user:, work_package:, ongoing: true) }- let!(:other_user_timer) { create(:time_entry, user: other_user, work_package: other_work_package, ongoing: true) }+ let!(:user_timer) { create(:time_entry, user:, entity: work_package, ongoing: true) }+ let!(:other_user_timer) { create(:time_entry, user: other_user, entity: other_work_package, ongoing: true) }describe "#results" dosubject { instance.results }@@ -56,8 +56,8 @@ RSpec.describe Queries::TimeEntries::TimeEntryQuery, "integration" doexpect(subject).to contain_exactly(user_timer)end- context "when user has log_time permission" do- let(:user) { create(:user, member_with_permissions: { project => %i[log_time] }) }+ context "when user has log_time and view_time_entries permission" do+ let(:user) { create(:user, member_with_permissions: { project => %i[log_time view_time_entries] }) }it "still returns the users own time entries" doexpect(subject).to contain_exactly(user_timer)