Feature #3322 » 0001-Setting-to-restrict-spent-times-on-future-dates-3322.patch
| app/models/time_entry.rb | ||
|---|---|---|
|
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)
|
||
| app/views/settings/_timelog.html.erb | ||
|---|---|---|
|
<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">
|
||
| config/locales/en.yml | ||
|---|---|---|
|
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:'
|
||
| ... | ... | |
|
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
|
||
| config/settings.yml | ||
|---|---|---|
|
timelog_max_hours_per_day:
|
||
|
format: int
|
||
|
default: 999
|
||
|
timelog_accept_future_dates:
|
||
|
default: 1
|
||
| test/unit/time_entry_test.rb | ||
|---|---|---|
|
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 = ''
|
||