mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Fixed validation when logging time on issue (#19464).
git-svn-id: http://svn.redmine.org/redmine/trunk@14162 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
8c6e5513a1
commit
3d1c40cd52
@ -68,9 +68,14 @@ class TimeEntry < ActiveRecord::Base
|
||||
def safe_attributes=(attrs, user=User.current)
|
||||
if attrs
|
||||
attrs = super(attrs)
|
||||
if issue_id_changed? && attrs[:project_id].blank? && issue && issue.project_id != project_id
|
||||
if issue_id_changed? && issue
|
||||
if user.allowed_to?(:log_time, issue.project)
|
||||
self.project_id = issue.project_id
|
||||
if attrs[:project_id].blank? && issue.project_id != project_id
|
||||
self.project_id = issue.project_id
|
||||
end
|
||||
@invalid_issue_id = nil
|
||||
else
|
||||
@invalid_issue_id = issue_id
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -84,7 +89,7 @@ class TimeEntry < ActiveRecord::Base
|
||||
def validate_time_entry
|
||||
errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000)
|
||||
errors.add :project_id, :invalid if project.nil?
|
||||
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project)
|
||||
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
|
||||
end
|
||||
|
||||
def hours=(h)
|
||||
|
||||
@ -162,6 +162,56 @@ class TimelogControllerTest < ActionController::TestCase
|
||||
assert_equal 3, t.user_id
|
||||
end
|
||||
|
||||
def test_create_on_project_with_time_tracking_disabled_should_fail
|
||||
Project.find(1).disable_module! :time_tracking
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
assert_no_difference 'TimeEntry.count' do
|
||||
post :create, :time_entry => {
|
||||
:project_id => '1', :issue_id => '',
|
||||
:activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_create_on_project_without_permission_should_fail
|
||||
Role.find(1).remove_permission! :log_time
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
assert_no_difference 'TimeEntry.count' do
|
||||
post :create, :time_entry => {
|
||||
:project_id => '1', :issue_id => '',
|
||||
:activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_create_on_issue_in_project_with_time_tracking_disabled_should_fail
|
||||
Project.find(1).disable_module! :time_tracking
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
assert_no_difference 'TimeEntry.count' do
|
||||
post :create, :time_entry => {
|
||||
:project_id => '', :issue_id => '1',
|
||||
:activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
|
||||
}
|
||||
assert_select_error /Issue is invalid/
|
||||
end
|
||||
end
|
||||
|
||||
def test_create_on_issue_in_project_without_permission_should_fail
|
||||
Role.find(1).remove_permission! :log_time
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
assert_no_difference 'TimeEntry.count' do
|
||||
post :create, :time_entry => {
|
||||
:project_id => '', :issue_id => '1',
|
||||
:activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
|
||||
}
|
||||
assert_select_error /Issue is invalid/
|
||||
end
|
||||
end
|
||||
|
||||
def test_create_and_continue_at_project_level
|
||||
@request.session[:user_id] = 2
|
||||
assert_difference 'TimeEntry.count' do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user