Project

General

Profile

Feature #13244 » 0001-Rework patch-from-13244.patch

Marius BĂLTEANU, 2024-12-11 23:35

View differences:

app/models/setting.rb
250 250
    twofa == '3'
251 251
  end
252 252

  
253
  def self.timelog_days_within_past
254
    [Setting.timelog_accept_within_past_days.to_i, 0].max
255
  end
256

  
253 257
  # Helper that returns an array based on per_page_options setting
254 258
  def self.per_page_options_array
255 259
    per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
app/models/time_entry.rb
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 183
      errors.add :base, I18n.t(:error_spent_on_future_date) if !Setting.timelog_accept_future_dates? && (spent_on > user.today)
184
      max_past_date = user.today - Setting.timelog_days_within_past
185
      errors.add :base, I18n.t(:error_spent_on_past_date, :max_days => Setting.timelog_accept_within_past_days.to_i, :max_past_date => format_date(max_past_date)) if spent_on < max_past_date
184 186
    end
185 187
    if !Setting.timelog_accept_closed_issues? && issue&.closed? && issue.was_closed?
186 188
      errors.add :base, I18n.t(:error_spent_on_closed_issue)
app/views/settings/_timelog.html.erb
11 11
<p><%= setting_check_box :timelog_accept_future_dates %></p>
12 12

  
13 13
<p><%= setting_check_box :timelog_accept_closed_issues %></p>
14

  
15
<p><%= setting_text_field :timelog_accept_within_past_days, :size => 6 %> <%= l(:label_day_plural) %></p>
14 16
</div>
15 17

  
16 18
<fieldset class="box">
config/locales/en.yml
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 238
  error_spent_on_closed_issue: "Cannot log time on a closed issue"
239
  error_spent_on_past_date: "Cannot log time on a date older than %{max_past_date} (%{max_days} days ago)"
239 240
  error_not_allowed_to_log_time_for_other_users: "You are not allowed to log time for other users"
240 241
  error_can_not_execute_macro_html: "Error executing the <strong>%{name}</strong> macro (%{error})"
241 242
  error_macro_does_not_accept_block: "This macro does not accept a block of text"
......
521 522
  setting_timelog_max_hours_per_day: Maximum hours that can be logged per day and user
522 523
  setting_timelog_accept_future_dates: Accept time logs on future dates
523 524
  setting_timelog_accept_closed_issues: Accept time logs on closed issues
525
  setting_timelog_accept_within_past_days: Accept time logs within the past
524 526
  setting_show_status_changes_in_mail_subject: Show status changes in issue mail notifications subject
525 527
  setting_project_list_defaults: Projects list defaults
526 528
  setting_twofa: Two-factor authentication
config/settings.yml
349 349
  default: 1
350 350
timelog_accept_closed_issues:
351 351
  default: 1
352
timelog_accept_within_past_days:
353
  format: int
354
  default: 36525
352 355
show_status_changes_in_mail_subject:
353 356
  default: 1
354 357
wiki_tablesort_enabled:
test/unit/time_entry_test.rb
197 197
    end
198 198
  end
199 199

  
200
  def test_should_restrict_past_dates
201
    with_settings :timelog_accept_within_past_days => '2' do
202
      entry_two_days_ago = TimeEntry.generate
203
      entry_two_days_ago.spent_on = User.current.today - 2
204
      assert entry_two_days_ago.save
205

  
206
      entry_three_days_ago = TimeEntry.generate
207
      entry_three_days_ago.spent_on = User.current.today - 3
208
      assert !entry_three_days_ago.save
209
      assert entry_three_days_ago.errors[:base].present?
210
    end
211
  end
212

  
200 213
  def test_should_require_spent_on
201 214
    with_settings :timelog_accept_future_dates => '0' do
202 215
      entry = TimeEntry.find(1)
(11-11/11)