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

Re-introduce Feature Flag for Start- & End-Time tracking (#17808)

Klaus Zandersb8ac7c7212e2
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index 2e3cf9b7788..02c4b77922c 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -164,7 +164,8 @@ class TimeEntry < ApplicationRecord
class << self
def can_track_start_and_end_time?(_project: nil)
- Setting.allow_tracking_start_and_end_times?
+ OpenProject::FeatureDecisions.track_start_and_end_times_for_time_entries_active? &&
+ Setting.allow_tracking_start_and_end_times?
# TODO: Add project check when we have decided if we also want a project specific flag
end
diff --git a/modules/costs/app/views/costs_settings/show.html.erb b/modules/costs/app/views/costs_settings/show.html.erb
index 51d915e9962..1f4be12f663 100644
--- a/modules/costs/app/views/costs_settings/show.html.erb
+++ b/modules/costs/app/views/costs_settings/show.html.erb
@@ -52,13 +52,15 @@ See COPYRIGHT and LICENSE files for more details.
<%= setting_text_field :costs_currency_format, type: :string, container_class: "-middle" %>
</div>
- <div class="form--field">
- <%= setting_check_box :allow_tracking_start_and_end_times, container_class: "-middle" %>
- </div>
-
- <div class="form--field">
- <%= setting_check_box :enforce_tracking_start_and_end_times, container_class: "-middle" %>
- </div>
+ <%- if OpenProject::FeatureDecisions.track_start_and_end_times_for_time_entries_active? %>
+ <div class="form--field">
+ <%= setting_check_box :allow_tracking_start_and_end_times, container_class: "-middle" %>
+ </div>
+
+ <div class="form--field">
+ <%= setting_check_box :enforce_tracking_start_and_end_times, container_class: "-middle" %>
+ </div>
+ <%- end %>
</section>
diff --git a/modules/costs/lib/costs/engine.rb b/modules/costs/lib/costs/engine.rb
index ab08faaabaf..553062b1338 100644
--- a/modules/costs/lib/costs/engine.rb
+++ b/modules/costs/lib/costs/engine.rb
@@ -146,6 +146,11 @@ module Costs
::Settings::Definition.add "enforce_tracking_start_and_end_times", default: false, format: :boolean
end
+ initializer "costs.feature_decisions" do
+ OpenProject::FeatureDecisions.add :track_start_and_end_times_for_time_entries,
+ description: "Allows admins to enable tracking start and end times for time entries"
+ end
+
activity_provider :time_entries, class_name: "Activities::TimeEntryActivityProvider", default: false
patches %i[Project User PermittedParams]
diff --git a/modules/costs/spec/features/time_entry_dialog_spec.rb b/modules/costs/spec/features/time_entry_dialog_spec.rb
index 7718d45a06d..ac2f56cb27a 100644
--- a/modules/costs/spec/features/time_entry_dialog_spec.rb
+++ b/modules/costs/spec/features/time_entry_dialog_spec.rb
@@ -30,7 +30,7 @@
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper.rb")
-RSpec.describe "time entry dialog", :js do
+RSpec.describe "time entry dialog", :js, with_flag: :track_start_and_end_times_for_time_entries do
include Redmine::I18n
shared_let(:project) { create(:project_with_types) }
diff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rb
index c1b0dfa24be..10cba11697c 100644
--- a/modules/costs/spec/models/time_entry_spec.rb
+++ b/modules/costs/spec/models/time_entry_spec.rb
@@ -414,12 +414,24 @@ RSpec.describe TimeEntry do
end
describe ".can_track_start_and_end_time?" do
- context "with the setting enabled", with_settings: { allow_tracking_start_and_end_times: true } do
- it { expect(described_class).to be_can_track_start_and_end_time }
+ context "with the feature flag enabled", with_flag: { track_start_and_end_times_for_time_entries: true } do
+ context "with the setting enabled", with_settings: { allow_tracking_start_and_end_times: true } do
+ it { expect(described_class).to be_can_track_start_and_end_time }
+ end
+
+ context "with the setting disabled", with_settings: { allow_tracking_start_and_end_times: false } do
+ it { expect(described_class).not_to be_can_track_start_and_end_time }
+ end
end
- context "with the setting disabled", with_settings: { allow_tracking_start_and_end_times: false } do
- it { expect(described_class).not_to be_can_track_start_and_end_time }
+ context "with the feature flag disabled", with_flag: { track_start_and_end_times_for_time_entries: false } do
+ context "with the setting enabled", with_settings: { allow_tracking_start_and_end_times: true } do
+ it { expect(described_class).not_to be_can_track_start_and_end_time }
+ end
+
+ context "with the setting disabled", with_settings: { allow_tracking_start_and_end_times: false } do
+ it { expect(described_class).not_to be_can_track_start_and_end_time }
+ end
end
end
@@ -516,23 +528,47 @@ RSpec.describe TimeEntry do
end
describe ".must_track_start_and_end_time?" do
- context "with the allow setting enabled", with_settings: { allow_tracking_start_and_end_times: true } do
- context "with the enforce setting enabled", with_settings: { enforce_tracking_start_and_end_times: true } do
- it { expect(described_class).to be_must_track_start_and_end_time }
+ context "with the feature flag enabled", with_flag: { track_start_and_end_times_for_time_entries: true } do
+ context "with the allow setting enabled", with_settings: { allow_tracking_start_and_end_times: true } do
+ context "with the enforce setting enabled", with_settings: { enforce_tracking_start_and_end_times: true } do
+ it { expect(described_class).to be_must_track_start_and_end_time }
+ end
+
+ context "with the enforce setting disabled", with_settings: { enforce_tracking_start_and_end_times: false } do
+ it { expect(described_class).not_to be_must_track_start_and_end_time }
+ end
end
- context "with the enforce setting disabled", with_settings: { enforce_tracking_start_and_end_times: false } do
- it { expect(described_class).not_to be_must_track_start_and_end_time }
+ context "with the allow setting disabled", with_settings: { allow_tracking_start_and_end_times: false } do
+ context "with the enforce setting enabled", with_settings: { enforce_tracking_start_and_end_times: true } do
+ it { expect(described_class).not_to be_must_track_start_and_end_time }
+ end
+
+ context "with the enforce setting disabled", with_settings: { enforce_tracking_start_and_end_times: false } do
+ it { expect(described_class).not_to be_must_track_start_and_end_time }
+ end
end
end
- context "with the allow setting disabled", with_settings: { allow_tracking_start_and_end_times: false } do
- context "with the enforce setting enabled", with_settings: { enforce_tracking_start_and_end_times: true } do
- it { expect(described_class).not_to be_must_track_start_and_end_time }
+ context "with the feature flag disabled", with_flag: { track_start_and_end_times_for_time_entries: false } do
+ context "with the allow setting enabled", with_settings: { allow_tracking_start_and_end_times: true } do
+ context "with the enforce setting enabled", with_settings: { enforce_tracking_start_and_end_times: true } do
+ it { expect(described_class).not_to be_must_track_start_and_end_time }
+ end
+
+ context "with the enforce setting disabled", with_settings: { enforce_tracking_start_and_end_times: false } do
+ it { expect(described_class).not_to be_must_track_start_and_end_time }
+ end
end
- context "with the enforce setting disabled", with_settings: { enforce_tracking_start_and_end_times: false } do
- it { expect(described_class).not_to be_must_track_start_and_end_time }
+ context "with the allow setting disabled", with_settings: { allow_tracking_start_and_end_times: false } do
+ context "with the enforce setting enabled", with_settings: { enforce_tracking_start_and_end_times: true } do
+ it { expect(described_class).not_to be_must_track_start_and_end_time }
+ end
+
+ context "with the enforce setting disabled", with_settings: { enforce_tracking_start_and_end_times: false } do
+ it { expect(described_class).not_to be_must_track_start_and_end_time }
+ end
end
end
end
diff --git a/modules/costs/spec/requests/api/time_entries/create_resource_spec.rb b/modules/costs/spec/requests/api/time_entries/create_resource_spec.rb
index 8d035ab6bb0..2c0c4c09ba7 100644
--- a/modules/costs/spec/requests/api/time_entries/create_resource_spec.rb
+++ b/modules/costs/spec/requests/api/time_entries/create_resource_spec.rb
@@ -33,6 +33,7 @@ require "rack/test"
RSpec.describe "API v3 Time Entries resource",
content_type: :json,
+ with_flag: :track_start_and_end_times_for_time_entries,
with_settings: { allow_tracking_start_and_end_times: true } do
include Rack::Test::Methods
include API::V3::Utilities::PathHelper
diff --git a/modules/costs/spec/requests/api/time_entry_resource_spec.rb b/modules/costs/spec/requests/api/time_entry_resource_spec.rb
index 2d89a2c4c31..745961034f6 100644
--- a/modules/costs/spec/requests/api/time_entry_resource_spec.rb
+++ b/modules/costs/spec/requests/api/time_entry_resource_spec.rb
@@ -330,7 +330,9 @@ RSpec.describe "API v3 time_entry resource" do
end
end
- context "when start- & end-time tracking is enabled", with_settings: { allow_tracking_start_and_end_times: true } do
+ context "when start- & end-time tracking is enabled",
+ with_flag: { track_start_and_end_times_for_time_entries: true },
+ with_settings: { allow_tracking_start_and_end_times: true } do
context "when start and end time were tracked" do
let!(:time_entry) do
create(:time_entry, :with_start_and_end_time, project:, work_package:, user: current_user)
@@ -368,7 +370,9 @@ RSpec.describe "API v3 time_entry resource" do
end
end
- context "when start- & end-time tracking is disabled", with_settings: { allow_tracking_start_and_end_times: false } do
+ context "when start- & end-time tracking is disabled",
+ with_flag: { track_start_and_end_times_for_time_entries: false },
+ with_settings: { allow_tracking_start_and_end_times: false } do
context "when start and end time were tracked" do
let!(:time_entry) do
create(:time_entry, :with_start_and_end_time, project:, work_package:, user: current_user)
diff --git a/modules/reporting/spec/features/export_cost_report_spec.rb b/modules/reporting/spec/features/export_cost_report_spec.rb
index 09dc85507bf..a687fdd7cc4 100644
--- a/modules/reporting/spec/features/export_cost_report_spec.rb
+++ b/modules/reporting/spec/features/export_cost_report_spec.rb
@@ -31,7 +31,7 @@
require_relative "../spec_helper"
require_relative "support/pages/cost_report_page"
-RSpec.describe "Cost reports XLS export", :js do
+RSpec.describe "Cost reports XLS export", :js, with_flag: { track_start_and_end_times_for_time_entries: true } do
shared_let(:project) { create(:project) }
shared_let(:user) { create(:admin) }
shared_let(:cost_type) { create(:cost_type, name: "Post-war", unit: "cap", unit_plural: "caps") }
diff --git a/modules/reporting/spec/features/time_entries_spec.rb b/modules/reporting/spec/features/time_entries_spec.rb
index 59cf2e54764..d7867e33d44 100644
--- a/modules/reporting/spec/features/time_entries_spec.rb
+++ b/modules/reporting/spec/features/time_entries_spec.rb
@@ -4,7 +4,8 @@ require "spec_helper"
require_relative "support/pages/cost_report_page"
require_relative "support/components/cost_reports_base_table"
-RSpec.describe "Cost report showing time entries with start & end times", :js do
+RSpec.describe "Cost report showing time entries with start & end times", :js,
+ with_flag: { track_start_and_end_times_for_time_entries: true } do
shared_let(:project) { create(:project) }
shared_let(:user) { create(:admin) }
shared_let(:work_package) { create(:work_package, project:) }