GitLab ist wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht erreichbar.

Commit 2cd287b7 authored by jplang's avatar jplang

Fixed that project, issue and activity should be preserved when logging time...

Fixed that project, issue and activity should be preserved when logging time with "Create and continue" (#11038).

git-svn-id: https://svn.redmine.org/redmine/trunk@9741 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 2715aa7d
......@@ -18,12 +18,13 @@
class TimelogController < ApplicationController
menu_item :issues
before_filter :find_project, :only => [:create]
before_filter :find_project_for_new_time_entry, :only => [:create]
before_filter :find_time_entry, :only => [:show, :edit, :update]
before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
before_filter :authorize, :except => [:new, :index, :report]
before_filter :find_optional_project, :only => [:new, :index, :report]
before_filter :find_optional_project, :only => [:index, :report]
before_filter :find_optional_project_for_new_time_entry, :only => [:new]
before_filter :authorize_global, :only => [:new, :index, :report]
accept_rss_auth :index
......@@ -133,9 +134,13 @@ class TimelogController < ApplicationController
flash[:notice] = l(:notice_successful_create)
if params[:continue]
if params[:project_id]
redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue, :back_url => params[:back_url]
redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue,
:time_entry => {:issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
:back_url => params[:back_url]
else
redirect_to :action => 'new', :back_url => params[:back_url]
redirect_to :action => 'new',
:time_entry => {:project_id => @time_entry.project_id, :issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
:back_url => params[:back_url]
end
else
redirect_back_or_default :action => 'index', :project_id => @time_entry.project
......@@ -258,7 +263,7 @@ private
end
end
def find_project
def find_optional_project_for_new_time_entry
if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present?
@project = Project.find(project_id)
end
......@@ -266,12 +271,15 @@ private
@issue = Issue.find(issue_id)
@project ||= @issue.project
end
rescue ActiveRecord::RecordNotFound
render_404
end
def find_project_for_new_time_entry
find_optional_project_for_new_time_entry
if @project.nil?
render_404
return false
end
rescue ActiveRecord::RecordNotFound
render_404
end
def find_optional_project
......
......@@ -65,6 +65,17 @@ class TimelogControllerTest < ActionController::TestCase
assert_select 'input[name=project_id]', 0
end
def test_new_without_project_should_prefill_the_form
@request.session[:user_id] = 3
get :new, :time_entry => {:project_id => '1'}
assert_response :success
assert_template 'new'
assert_select 'select[name=?]', 'time_entry[project_id]' do
assert_select 'option[value=1][selected=selected]'
end
assert_select 'input[name=project_id]', 0
end
def test_new_without_project_should_deny_without_permission
Role.all.each {|role| role.remove_permission! :log_time}
@request.session[:user_id] = 3
......@@ -146,7 +157,7 @@ class TimelogControllerTest < ActionController::TestCase
:spent_on => '2008-03-14',
:hours => '7.3'},
:continue => '1'
assert_redirected_to '/projects/ecookbook/time_entries/new'
assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D='
end
def test_create_and_continue_with_issue_id
......@@ -157,7 +168,7 @@ class TimelogControllerTest < ActionController::TestCase
:spent_on => '2008-03-14',
:hours => '7.3'},
:continue => '1'
assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new'
assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1'
end
def test_create_and_continue_without_project
......@@ -169,7 +180,7 @@ class TimelogControllerTest < ActionController::TestCase
:hours => '7.3'},
:continue => '1'
assert_redirected_to '/time_entries/new'
assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
end
def test_create_without_log_time_permission_should_be_denied
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment