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

add enterprise banner to costs settings

Klaus Zanders35d80fa153b4
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index 886dfe91e7f..c0ab8b203b5 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -168,14 +168,14 @@ class TimeEntry < ApplicationRecord
end
class << self
- def can_track_start_and_end_time?(_project: nil)
+ def can_track_start_and_end_time?
Setting.allow_tracking_start_and_end_times?
- # TODO: Add project check when we have decided if we also want a project specific flag
end
- def must_track_start_and_end_time?(_project: nil)
- Setting.enforce_tracking_start_and_end_times?
- # TODO: Add project check when we have decided if we also want a project specific flag
+ def must_track_start_and_end_time?
+ EnterpriseToken.allows_to?(:time_entry_time_restrictions) &&
+ can_track_start_and_end_time? &&
+ Setting.enforce_tracking_start_and_end_times?
end
end
diff --git a/modules/costs/app/views/admin/costs_settings/show.html.erb b/modules/costs/app/views/admin/costs_settings/show.html.erb
index 8d4092c7a1f..acb5fe7597f 100644
--- a/modules/costs/app/views/admin/costs_settings/show.html.erb
+++ b/modules/costs/app/views/admin/costs_settings/show.html.erb
@@ -57,7 +57,13 @@ render(Primer::Alpha::TabPanels.new(label: I18n.t(:project_module_costs))) do |c
end
form.check_box(name: :allow_tracking_start_and_end_times)
- form.check_box(name: :enforce_tracking_start_and_end_times)
+
+ unless EnterpriseToken.allows_to?(:time_entry_time_restrictions)
+ form.html_content do
+ render(::EnterpriseEdition::BannerComponent.new(:time_entry_time_restrictions, dismissable: false))
+ end
+ end
+ form.check_box(name: :enforce_tracking_start_and_end_times, disabled: !EnterpriseToken.allows_to?(:time_entry_time_restrictions))
form.submit
end
diff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.yml
index a8c08763869..dd77b2529e8 100644
--- a/modules/costs/config/locales/en.yml
+++ b/modules/costs/config/locales/en.yml
@@ -119,7 +119,6 @@ en:
description_costs_settings: "Define the desired format for the costs in all projects."
description_time_settings: "Define which fields are mandatory to fill when logging time in all projects."
-
group_by_others: "not in any group"
label_between: "between"
@@ -208,3 +207,10 @@ en:
errors:
validation:
start_time_different_date: "Date part of startTime (%{start_time}) must be the same as the spentOn (%{spent_on}) date."
+
+ ee:
+ features:
+ time_entry_time_restrictions: Require exact time tracking
+ upsale:
+ time_entry_time_restrictions:
+ description: "Improve your time tracking by requiring exact start and finish times when logging time."
diff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rb
index 904d8c6b184..b03088352b8 100644
--- a/modules/costs/spec/models/time_entry_spec.rb
+++ b/modules/costs/spec/models/time_entry_spec.rb
@@ -533,23 +533,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 "when the EnterpriseToken does not allow enforcement", with_ee: [] 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
- 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 "when the EnterpriseToken allows enforcement", with_ee: [:time_entry_time_restrictions] 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
end