Feature #3322 » 0001-Setting-to-restrict-spent-times-on-future-dates-3322.patch
app/models/time_entry.rb | ||
---|---|---|
136 | 136 |
errors.add :project_id, :invalid if project.nil? |
137 | 137 |
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id |
138 | 138 |
errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity) |
139 |
if spent_on_changed? && user |
|
140 |
errors.add :base, I18n.t(:error_spent_on_future_date) if (!Setting.timelog_accept_future_dates? && (spent_on > user.today)) |
|
141 |
end |
|
139 | 142 |
end |
140 | 143 | |
141 | 144 |
def hours=(h) |
app/views/settings/_timelog.html.erb | ||
---|---|---|
7 | 7 |
<p><%= setting_text_field :timelog_max_hours_per_day, :size => 6 %></p> |
8 | 8 | |
9 | 9 |
<p><%= setting_check_box :timelog_accept_0_hours %></p> |
10 | ||
11 |
<p><%= setting_check_box :timelog_accept_future_dates %></p> |
|
10 | 12 |
</div> |
11 | 13 | |
12 | 14 |
<fieldset class="box"> |
config/locales/en.yml | ||
---|---|---|
223 | 223 |
warning_fields_cleared_on_bulk_edit: "Changes will result in the automatic deletion of values from one or more fields on the selected objects" |
224 | 224 |
error_exceeds_maximum_hours_per_day: "Cannot log more than %{max_hours} hours on the same day (%{logged_hours} hours have already been logged)" |
225 | 225 |
error_can_not_delete_auth_source: "This authentication mode is in use and cannot be deleted." |
226 |
error_spent_on_future_date: "Cannot log time on a future date" |
|
226 | 227 | |
227 | 228 |
mail_subject_lost_password: "Your %{value} password" |
228 | 229 |
mail_body_lost_password: 'To change your password, click on the following link:' |
... | ... | |
469 | 470 |
setting_time_entry_list_defaults: Timelog list defaults |
470 | 471 |
setting_timelog_accept_0_hours: Accept time logs with 0 hours |
471 | 472 |
setting_timelog_max_hours_per_day: Maximum hours that can be logged per day and user |
473 |
setting_timelog_accept_future_dates: Accept time logs on future dates |
|
472 | 474 | |
473 | 475 |
permission_add_project: Create project |
474 | 476 |
permission_add_subprojects: Create subprojects |
config/settings.yml | ||
---|---|---|
308 | 308 |
timelog_max_hours_per_day: |
309 | 309 |
format: int |
310 | 310 |
default: 999 |
311 |
timelog_accept_future_dates: |
|
312 |
default: 1 |
test/unit/time_entry_test.rb | ||
---|---|---|
119 | 119 |
end |
120 | 120 |
end |
121 | 121 | |
122 |
def test_should_accept_future_dates |
|
123 |
entry = TimeEntry.generate |
|
124 |
entry.spent_on = User.current.today + 1 |
|
125 | ||
126 |
assert entry.save |
|
127 |
end |
|
128 | ||
129 |
def test_should_not_accept_future_dates_if_disabled |
|
130 |
with_settings :timelog_accept_future_dates => '0' do |
|
131 |
entry = TimeEntry.generate |
|
132 |
entry.spent_on = User.current.today + 1 |
|
133 | ||
134 |
assert !entry.save |
|
135 |
assert entry.errors[:base].present? |
|
136 |
end |
|
137 |
end |
|
138 | ||
122 | 139 |
def test_spent_on_with_blank |
123 | 140 |
c = TimeEntry.new |
124 | 141 |
c.spent_on = '' |