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
Add a new attribute to limit entries to a single project
Klaus Zanders9e0001cfd610
diff --git a/modules/costs/app/components/time_entries/entry_dialog_component.html.erb b/modules/costs/app/components/time_entries/entry_dialog_component.html.erbindex bc944878f88..836bbdb7192 100644--- a/modules/costs/app/components/time_entries/entry_dialog_component.html.erb+++ b/modules/costs/app/components/time_entries/entry_dialog_component.html.erb@@ -5,7 +5,8 @@TimeEntries::TimeEntryFormComponent.new(time_entry: time_entry,show_user: show_user,- show_work_package: show_work_package+ show_work_package: show_work_package,+ limit_to_project_id: limit_to_project_id)) %><% end %>diff --git a/modules/costs/app/components/time_entries/entry_dialog_component.rb b/modules/costs/app/components/time_entries/entry_dialog_component.rbindex 8ce53c4ce0b..0cae2ce12a6 100644--- a/modules/costs/app/components/time_entries/entry_dialog_component.rb+++ b/modules/costs/app/components/time_entries/entry_dialog_component.rb@@ -35,21 +35,17 @@ module TimeEntriesMODAL_ID = "time-entry-dialog"- def initialize(time_entry:, show_user: true, show_work_package: true)- super()- @time_entry = time_entry- @show_user = show_user- @show_work_package = show_work_package- end+ options time_entry: nil,+ limit_to_project_id: nil,+ show_user: true,+ show_work_package: trueprivate- attr_reader :time_entry, :open, :show_user, :show_work_package-def can_delete_time_entry?return false if time_entry.new_record?- DeleteContract.deletion_allowed?(@time_entry, User.current)+ DeleteContract.deletion_allowed?(time_entry, User.current)endendenddiff --git a/modules/costs/app/components/time_entries/time_entry_form_component.html.erb b/modules/costs/app/components/time_entries/time_entry_form_component.html.erbindex 5a6c96ee728..58cdec812cf 100644--- a/modules/costs/app/components/time_entries/time_entry_form_component.html.erb+++ b/modules/costs/app/components/time_entries/time_entry_form_component.html.erb@@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.body.with_row { render(TimeEntries::DaysAndHoursForm.new(form)) }body.with_row(display: show_work_package ? :block : :none) dorender(- TimeEntries::WorkPackageForm.new(form, visible: show_work_package)+ TimeEntries::WorkPackageForm.new(form, visible: show_work_package, limit_to_project_id: limit_to_project_id))endbody.with_row { render(TimeEntries::ActivityForm.new(form)) }diff --git a/modules/costs/app/components/time_entries/time_entry_form_component.rb b/modules/costs/app/components/time_entries/time_entry_form_component.rbindex 70f45291a61..3b5fc39367b 100644--- a/modules/costs/app/components/time_entries/time_entry_form_component.rb+++ b/modules/costs/app/components/time_entries/time_entry_form_component.rb@@ -33,17 +33,13 @@ module TimeEntriesinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- def initialize(time_entry:, show_user: true, show_work_package: true)- super()- @time_entry = time_entry- @show_user = show_user- @show_work_package = show_work_package- end+ options time_entry: nil,+ limit_to_project_id: nil,+ show_user: true,+ show_work_package: trueprivate- attr_reader :time_entry, :show_user, :show_work_package-delegate :project, :work_package, to: :time_entrydef form_optionsdiff --git a/modules/costs/app/components/time_entries/work_package_form.rb b/modules/costs/app/components/time_entries/work_package_form.rbindex 5ea7936d906..e0d460237f1 100644--- a/modules/costs/app/components/time_entries/work_package_form.rb+++ b/modules/costs/app/components/time_entries/work_package_form.rb@@ -30,13 +30,15 @@module TimeEntriesclass WorkPackageForm < ApplicationForm- def initialize(visible: true)+ def initialize(visible: true, limit_to_project_id: nil)super()@visible = visible+ @limit_to_project_id = limit_to_project_idendform do |f|f.hidden name: :show_work_package, value: @visible+ f.hidden name: :limit_to_project_id, value: @limit_to_project_idif show_work_package_field?f.work_package_autocompleter name: :work_package_id,@@ -95,8 +97,8 @@ module TimeEntriesdef work_package_completer_filtersfilters = []- if model.project_id- filters << { name: "project_id", operator: "=", values: [model.project_id] }+ if @limit_to_project_id+ filters << { name: "project_id", operator: "=", values: [@limit_to_project_id] }endfiltersdiff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rbindex 191bb56a140..f7375086437 100644--- a/modules/costs/app/controllers/time_entries_controller.rb+++ b/modules/costs/app/controllers/time_entries_controller.rb@@ -47,6 +47,7 @@ class TimeEntriesController < ApplicationControllerdef dialog@show_work_package = params[:work_package_id].blank?@show_user = show_user_input_in_dialog+ @limit_to_project_id = @project&.id@time_entry.spent_on ||= params[:date].presence || Time.zone.todayend@@ -141,7 +142,8 @@ class TimeEntriesController < ApplicationControllerdef form_config_options{show_user: params[:time_entry][:show_user] == "true",- show_work_package: params[:time_entry][:show_work_package] == "true"+ show_work_package: params[:time_entry][:show_work_package] == "true",+ limit_to_project_id: params[:time_entry][:limit_to_project_id].presence}enddiff --git a/modules/costs/app/views/time_entries/dialog.turbo_stream.erb b/modules/costs/app/views/time_entries/dialog.turbo_stream.erbindex f717e85b818..01f4c930737 100644--- a/modules/costs/app/views/time_entries/dialog.turbo_stream.erb+++ b/modules/costs/app/views/time_entries/dialog.turbo_stream.erb@@ -3,7 +3,8 @@TimeEntries::EntryDialogComponent.new(time_entry: @time_entry,show_user: @show_user,- show_work_package: @show_work_package+ show_work_package: @show_work_package,+ limit_to_project_id: @limit_to_project_id))end %>diff --git a/modules/costs/spec/features/time_entry_dialog_spec.rb b/modules/costs/spec/features/time_entry_dialog_spec.rbindex 75c473de5b9..e33b8ab21ff 100644--- a/modules/costs/spec/features/time_entry_dialog_spec.rb+++ b/modules/costs/spec/features/time_entry_dialog_spec.rb@@ -216,6 +216,38 @@ RSpec.describe "time entry dialog", :js, with_flag: :track_start_and_end_times_flet(:permissions) { %i[log_own_time view_own_time_entries edit_own_time_entries view_work_packages] }let!(:time_entry) { create(:time_entry, work_package: work_package_a, project: work_package_a.project, user: user) }+ context "with work packages from different projects" do+ let(:other_project) { create(:project_with_types) }+ let(:work_package_c) { create(:work_package, subject: "WP C", project: other_project) }++ let(:user) { create(:user, member_with_permissions: { project => permissions, other_project => permissions }) }++ it "allows switching to a work package of a different project (Regression #62066)" do+ visit cost_reports_path(work_package_a.project_id,+ { fields: ["WorkPackageId"],+ operators: { WorkPackageId: "=" },+ values: { WorkPackageId: [work_package_a.id, work_package_b.id, work_package_c.id] },+ set_filter: 1 })++ # make sure that the work package is shown in the table+ expect(page).to have_css("#result-table td[raw-data='#{work_package_a.id}']", text: work_package_a.subject)++ find("opce-time-entry-trigger-actions .icon-edit").click++ time_logging_modal.is_visible(true)+ time_logging_modal.update_field("work_package_id", work_package_c.id)+ wait_for_network_idle # form refresh is happening here+ time_logging_modal.submit+ wait_for_network_idle++ expect(page).to have_css("#result-table td[raw-data='#{work_package_c.id}']", text: work_package_c.subject)++ # also check that everything is updated in the database+ time_entry.reload+ expect(time_entry.work_package).to eq(work_package_c)+ end+ end+it "updates the time entry instead of creating a new one (Regression #61657)" dovisit cost_reports_path(work_package_a.project_id,{ fields: ["WorkPackageId"],