Project

General

Profile

Feature #13244 » 13244.patch

Go MAEDA, 2024-08-13 12:27

View differences:

app/models/time_entry.rb
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 && spent_on_changed? && user
max_days_for_past = [Setting.timelog_max_days_for_past.to_i, 0].max
errors.add :base, I18n.t(:error_spent_on_future_date) if !Setting.timelog_accept_future_dates? && (spent_on > user.today)
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)
end
end
app/views/settings/_timelog.html.erb
<p><%= setting_check_box :timelog_accept_0_hours %></p>
<p><%= setting_check_box :timelog_accept_future_dates %></p>
<p><%= setting_text_field :timelog_max_days_for_past, :size => 6 %></p>
</div>
<fieldset class="box">
config/locales/en.yml
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"
error_spent_on_past_date: "Cannot log time on a past date more than %{max_days} days ago."
error_not_allowed_to_log_time_for_other_users: "You are not allowed to log time for other users"
error_can_not_execute_macro_html: "Error executing the <strong>%{name}</strong> macro (%{error})"
error_macro_does_not_accept_block: "This macro does not accept a block of text"
......
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
setting_timelog_max_days_for_past: Accept time logs within the past N days
setting_show_status_changes_in_mail_subject: Show status changes in issue mail notifications subject
setting_project_list_defaults: Projects list defaults
setting_twofa: Two-factor authentication
config/settings.yml
default: 999
timelog_accept_future_dates:
default: 1
timelog_max_days_for_past:
format: int
default: 36525
show_status_changes_in_mail_subject:
default: 1
test/unit/time_entry_test.rb
end
end
def test_should_restrict_past_dates
with_settings :timelog_max_days_for_past => '2' do
entry_two_days_ago = TimeEntry.generate
entry_two_days_ago.spent_on = User.current.today - 2
assert entry_two_days_ago.save
entry_three_days_ago = TimeEntry.generate
entry_three_days_ago.spent_on = User.current.today - 3
assert !entry_three_days_ago.save
assert entry_three_days_ago.errors[:base].present?
end
end
def test_should_require_spent_on
with_settings :timelog_accept_future_dates => '0' do
entry = TimeEntry.find(1)
(7-7/11)