Project

General

Profile

Feature #13244 » 0001-project-setting-to-deny-time-logging-on-closed-issue.patch

Jens Krämer, 2024-12-09 09:48

View differences:

app/controllers/context_menus_controller.rb
@can = {
:edit => @issues.all?(&:attributes_editable?),
:log_time => (@project && User.current.allowed_to?(:log_time, @project)),
:log_time => @issue&.time_loggable?,
:copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?,
:add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
:delete => @issues.all?(&:deletable?),
app/models/issue.rb
end
end
# Returns true if user or current user is allowed to log time on the issue
def time_loggable?(user=User.current)
user.allowed_to?(:log_time, project) && (project.timelog_on_closed_issues? || !closed?)
end
# Returns true if user or current user is allowed to edit or add notes to the issue
def editable?(user=User.current)
attributes_editable?(user) || notes_addable?(user)
app/models/project.rb
'parent_id',
'default_version_id',
'default_issue_query_id',
'default_assigned_to_id')
'default_assigned_to_id',
'timelog_on_closed_issues')
safe_attributes(
'is_public',
app/models/time_entry.rb
if spent_on && 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
if project && !project.timelog_on_closed_issues? && issue&.closed? && issue&.was_closed?
errors.add :base, I18n.t(:error_timelog_on_closed_issue)
end
end
def hours=(h)
app/views/issues/_action_menu.html.erb
:onclick => 'showAndScrollTo("update", "issue_notes"); return false;',
:class => 'icon icon-edit ', :accesskey => accesskey(:edit) if @issue.editable? %>
<%= link_to sprite_icon('time-add', l(:button_log_time)), new_issue_time_entry_path(@issue),
:class => 'icon icon-time-add ' if User.current.allowed_to?(:log_time, @project) %>
:class => 'icon icon-time-add ' if @issue.time_loggable? %>
<%= watcher_link(@issue, User.current) %>
<%= link_to sprite_icon('copy', l(:button_copy)), project_copy_issue_path(@project, @issue),
:class => 'icon icon-copy ' if User.current.allowed_to?(:copy_issues, @project) && Issue.allowed_target_projects.any? %>
app/views/issues/_edit.html.erb
</div>
</fieldset>
<% end %>
<% if User.current.allowed_to?(:log_time, @issue.project) %>
<% if @issue.time_loggable? %>
<fieldset class="tabular" id="log_time"><legend><%= l(:button_log_time) %></legend>
<%= labelled_fields_for :time_entry, @time_entry do |time_entry| %>
<div class="splitcontent">
app/views/projects/settings/_issues.html.erb
<% end %>
</div>
<% if @project.module_enabled?('time_tracking') %>
<div class="box tabular">
<p>
<%= f.check_box :timelog_on_closed_issues %><em class="info"><%=l(:text_timelog_on_closed_issues)%></em>
</p>
</div>
<% end %>
<p><%= submit_tag l(:button_save) %></p>
<% end %>
config/locales/de.yml
zero: "%{filename}"
one: "%{filename} and 1 file"
other: "%{filename} and %{count} files"
field_timelog_on_closed_issues: Zeiterfassung an geschlossenen Aufgaben
text_timelog_on_closed_issues: Deaktivieren um die Zeiterfassung an geschlossenen Aufgaben zu verhindern.
error_timelog_on_closed_issue: Zeiterfassung an geschlossenen Aufgaben ist nicht möglich.
config/locales/en.yml
text_user_destroy_confirmation: "Are you sure you want to delete this user and remove all references to them? This cannot be undone. Often, locking a user instead of deleting them is the better solution. To confirm, please enter their login (%{login}) below."
text_project_destroy_enter_identifier: "To confirm, please enter the project's identifier (%{identifier}) below."
field_name_or_email_or_login: Name, email or login
field_timelog_on_closed_issues: Time tracking on closed issues
text_timelog_on_closed_issues: Uncheck to prevent users from logging time on closed issues.
error_timelog_on_closed_issue: Cannot log time on a closed issue
db/migrate/20241113033816_add_timelog_on_closed_issues_flag_to_projects.rb
class AddTimelogOnClosedIssuesFlagToProjects < ActiveRecord::Migration[5.2]
def change
add_column :projects, :timelog_on_closed_issues, :bool, default: true, null: false
end
end
test/functional/issues_controller_test.rb
assert_select 'input[name=?]', 'time_entry[hours]', 0
end
def test_get_edit_should_not_display_the_time_entry_form_on_closed_issue
@request.session[:user_id] = 2
issue = Issue.find(1)
issue.project.update_attribute(:timelog_on_closed_issues, false)
issue.update :status => IssueStatus.find(5)
get(:edit, :params => {:id => 1})
assert_select 'input[name=?]', 'time_entry[hours]', 0
end
def test_get_edit_with_params
@request.session[:user_id] = 2
get(
......
assert mail.subject.include?("(#{IssueStatus.find(2).name})")
end
def test_update_should_accept_time_entry_when_closing_issue
issue = Issue.find(1)
issue.project.update_attribute(:timelog_on_closed_issues, false)
assert_equal 1, issue.status_id
@request.session[:user_id] = 2
assert_difference('TimeEntry.count', 1) do
put(
:update,
:params => {
:id => 1,
:issue => {
:status_id => 5,
},
:time_entry => {
:hours => '2',
:comments => '',
:activity_id => TimeEntryActivity.first
}
}
)
end
assert_redirected_to :action => 'show', :id => '1'
issue.reload
assert issue.closed?
end
def test_update_should_not_accept_time_entry_on_closed_issue
issue = Issue.find(1)
issue.project.update_attribute(:timelog_on_closed_issues, false)
issue.update :status => IssueStatus.find(5)
@request.session[:user_id] = 2
assert_no_difference('TimeEntry.count') do
put(
:update,
:params => {
:id => 1,
:issue => {
},
:time_entry => {
:hours => '2',
:comments => '',
:activity_id => TimeEntryActivity.first
}
}
)
end
assert_response :success
end
def test_put_update_with_note_only
notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
test/unit/time_entry_test.rb
end
end
def test_should_not_accept_closed_issue
project = Project.find(1)
project.update_attribute(:timelog_on_closed_issues, false)
entry = TimeEntry.generate project: project
issue = project.issues.to_a.detect(&:closed?)
entry.issue = issue
assert !entry.save
assert entry.errors[:base].present?
assert_equal 'Cannot log time on a closed issue', entry.errors[:base].first
end
def test_should_require_spent_on
with_settings :timelog_accept_future_dates => '0' do
entry = TimeEntry.find(1)
(10-10/11)