summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/time_entry.rb3
-rw-r--r--app/views/settings/_timelog.html.erb2
-rw-r--r--config/locales/en.yml2
-rw-r--r--config/settings.yml2
-rw-r--r--test/unit/time_entry_test.rb17
5 files changed, 26 insertions, 0 deletions
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb
index d64c311fa..095653266 100644
--- a/app/models/time_entry.rb
+++ b/app/models/time_entry.rb
@@ -136,6 +136,9 @@ class TimeEntry < ActiveRecord::Base
errors.add :project_id, :invalid if project.nil?
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
+ if spent_on_changed? && user
+ errors.add :base, I18n.t(:error_spent_on_future_date) if (!Setting.timelog_accept_future_dates? && (spent_on > user.today))
+ end
end
def hours=(h)
diff --git a/app/views/settings/_timelog.html.erb b/app/views/settings/_timelog.html.erb
index bc5f054c2..01d42384b 100644
--- a/app/views/settings/_timelog.html.erb
+++ b/app/views/settings/_timelog.html.erb
@@ -7,6 +7,8 @@
<p><%= setting_text_field :timelog_max_hours_per_day, :size => 6 %></p>
<p><%= setting_check_box :timelog_accept_0_hours %></p>
+
+<p><%= setting_check_box :timelog_accept_future_dates %></p>
</div>
<fieldset class="box">
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 36d2099c8..28da4cecb 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -223,6 +223,7 @@ en:
warning_fields_cleared_on_bulk_edit: "Changes will result in the automatic deletion of values from one or more fields on the selected objects"
error_exceeds_maximum_hours_per_day: "Cannot log more than %{max_hours} hours on the same day (%{logged_hours} hours have already been logged)"
error_can_not_delete_auth_source: "This authentication mode is in use and cannot be deleted."
+ error_spent_on_future_date: "Cannot log time on a future date"
mail_subject_lost_password: "Your %{value} password"
mail_body_lost_password: 'To change your password, click on the following link:'
@@ -469,6 +470,7 @@ en:
setting_time_entry_list_defaults: Timelog list defaults
setting_timelog_accept_0_hours: Accept time logs with 0 hours
setting_timelog_max_hours_per_day: Maximum hours that can be logged per day and user
+ setting_timelog_accept_future_dates: Accept time logs on future dates
permission_add_project: Create project
permission_add_subprojects: Create subprojects
diff --git a/config/settings.yml b/config/settings.yml
index 80946ec42..b6c026104 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -308,3 +308,5 @@ timelog_accept_0_hours:
timelog_max_hours_per_day:
format: int
default: 999
+timelog_accept_future_dates:
+ default: 1
diff --git a/test/unit/time_entry_test.rb b/test/unit/time_entry_test.rb
index 9b3fbf78b..2551c6fa4 100644
--- a/test/unit/time_entry_test.rb
+++ b/test/unit/time_entry_test.rb
@@ -119,6 +119,23 @@ class TimeEntryTest < ActiveSupport::TestCase
end
end
+ def test_should_accept_future_dates
+ entry = TimeEntry.generate
+ entry.spent_on = User.current.today + 1
+
+ assert entry.save
+ end
+
+ def test_should_not_accept_future_dates_if_disabled
+ with_settings :timelog_accept_future_dates => '0' do
+ entry = TimeEntry.generate
+ entry.spent_on = User.current.today + 1
+
+ assert !entry.save
+ assert entry.errors[:base].present?
+ end
+ end
+
def test_spent_on_with_blank
c = TimeEntry.new
c.spent_on = ''