From a206f07b553d245c386e25622e36b69d84e7d0de Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Fri, 23 Apr 2021 02:17:37 +0300 Subject: [PATCH] Allow adding time entry on an issue that became private for the current user (for ex: when assignee changes). Fixes #34856. --- app/models/time_entry.rb | 7 +++++++ test/functional/issues_controller_test.rb | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index cb852e218..b5926c612 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -119,6 +119,13 @@ class TimeEntry < ActiveRecord::Base self.project_id = issue.project_id end @invalid_issue_id = nil + elsif user.allowed_to?(:log_time, issue.project) && issue.assigned_to_id_changed? && issue.previous_assignee == User.current + current_assignee = issue.assigned_to + issue.assigned_to = issue.previous_assignee + unless issue.visible?(user) + @invalid_issue_id = issue_id + end + issue.assigned_to = current_assignee else @invalid_issue_id = issue_id end diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index ccebb4311..cbb8ac9dc 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -6501,6 +6501,29 @@ class IssuesControllerTest < Redmine::ControllerTest assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment' end + def test_put_with_spent_time_when_assigned_to_of_private_issue_is_update_at_the_same_time + @request.session[:user_id] = 3 + Role.find(2).update! :issues_visibility => 'own' + private_issue = Issue.find(3) + + assert_difference('TimeEntry.count', 1) do + put( + :update, + params: { + id: private_issue.id, + issue: { assigned_to_id: nil }, + time_entry: { + comments: "add spent time", activity_id: TimeEntryActivity.first.id, hours: 1 + } + } + ) + end + assert_select '#errorExplanation', {text: /Log time is invalid/, count: 0} + assert_select '#errorExplanation', {text: /Issue is invalid/, count: 0} + assert_redirected_to action: 'show', id: private_issue.id + assert_not private_issue.reload.visible? + end + def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject issue = Issue.find(2) @request.session[:user_id] = 2 -- 2.22.0