Feature #13244 » 13244.patch
app/models/time_entry.rb | ||
---|---|---|
180 | 180 |
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id |
181 | 181 |
errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity) |
182 | 182 |
if spent_on && spent_on_changed? && user |
183 |
max_days_for_past = [Setting.timelog_max_days_for_past.to_i, 0].max |
|
183 | 184 |
errors.add :base, I18n.t(:error_spent_on_future_date) if !Setting.timelog_accept_future_dates? && (spent_on > user.today) |
185 |
errors.add :base, I18n.t(:error_spent_on_past_date, :max_days => max_days_for_past) if max_days_for_past < (user.today - spent_on) |
|
184 | 186 |
end |
185 | 187 |
end |
186 | 188 |
app/views/settings/_timelog.html.erb | ||
---|---|---|
9 | 9 |
<p><%= setting_check_box :timelog_accept_0_hours %></p> |
10 | 10 | |
11 | 11 |
<p><%= setting_check_box :timelog_accept_future_dates %></p> |
12 | ||
13 |
<p><%= setting_text_field :timelog_max_days_for_past, :size => 6 %></p> |
|
12 | 14 |
</div> |
13 | 15 | |
14 | 16 |
<fieldset class="box"> |
config/locales/en.yml | ||
---|---|---|
235 | 235 |
error_exceeds_maximum_hours_per_day: "Cannot log more than %{max_hours} hours on the same day (%{logged_hours} hours have already been logged)" |
236 | 236 |
error_can_not_delete_auth_source: "This authentication mode is in use and cannot be deleted." |
237 | 237 |
error_spent_on_future_date: "Cannot log time on a future date" |
238 |
error_spent_on_past_date: "Cannot log time on a past date more than %{max_days} days ago." |
|
238 | 239 |
error_not_allowed_to_log_time_for_other_users: "You are not allowed to log time for other users" |
239 | 240 |
error_can_not_execute_macro_html: "Error executing the <strong>%{name}</strong> macro (%{error})" |
240 | 241 |
error_macro_does_not_accept_block: "This macro does not accept a block of text" |
... | ... | |
519 | 520 |
setting_timelog_accept_0_hours: Accept time logs with 0 hours |
520 | 521 |
setting_timelog_max_hours_per_day: Maximum hours that can be logged per day and user |
521 | 522 |
setting_timelog_accept_future_dates: Accept time logs on future dates |
523 |
setting_timelog_max_days_for_past: Accept time logs within the past N days |
|
522 | 524 |
setting_show_status_changes_in_mail_subject: Show status changes in issue mail notifications subject |
523 | 525 |
setting_project_list_defaults: Projects list defaults |
524 | 526 |
setting_twofa: Two-factor authentication |
config/settings.yml | ||
---|---|---|
347 | 347 |
default: 999 |
348 | 348 |
timelog_accept_future_dates: |
349 | 349 |
default: 1 |
350 |
timelog_max_days_for_past: |
|
351 |
format: int |
|
352 |
default: 36525 |
|
350 | 353 |
show_status_changes_in_mail_subject: |
351 | 354 |
default: 1 |
test/unit/time_entry_test.rb | ||
---|---|---|
171 | 171 |
end |
172 | 172 |
end |
173 | 173 | |
174 |
def test_should_restrict_past_dates |
|
175 |
with_settings :timelog_max_days_for_past => '2' do |
|
176 |
entry_two_days_ago = TimeEntry.generate |
|
177 |
entry_two_days_ago.spent_on = User.current.today - 2 |
|
178 |
assert entry_two_days_ago.save |
|
179 | ||
180 |
entry_three_days_ago = TimeEntry.generate |
|
181 |
entry_three_days_ago.spent_on = User.current.today - 3 |
|
182 |
assert !entry_three_days_ago.save |
|
183 |
assert entry_three_days_ago.errors[:base].present? |
|
184 |
end |
|
185 |
end |
|
186 | ||
174 | 187 |
def test_should_require_spent_on |
175 | 188 |
with_settings :timelog_accept_future_dates => '0' do |
176 | 189 |
entry = TimeEntry.find(1) |