[refs #90] fixed changing base project

This commit is contained in:
Alexander Machehin 2012-10-01 23:43:15 +06:00
parent 948e0892bf
commit f92f209323
2 changed files with 13 additions and 3 deletions

View File

@ -8,7 +8,7 @@ class Projects::PullRequestsController < Projects::BaseController
load_and_authorize_resource :instance_name => :pull, :through => :issue, :singleton => true, :except => [:index, :autocomplete_base_project]
def new
base_project = (Project.find(params[:base_project_id]) if params[:base_project_id]) || @project.root
base_project = set_base_project(false)
authorize! :read, base_project
@pull = base_project.pull_requests.new
@ -33,7 +33,7 @@ class Projects::PullRequestsController < Projects::BaseController
raise 'expect pull_request params' # for debug
redirect :back
end
base_project = Project.find(params[:base_project_id])
base_project = set_base_project
authorize! :read, base_project
@pull = base_project.pull_requests.new pull_params
@ -142,6 +142,17 @@ class Projects::PullRequestsController < Projects::BaseController
@stats = @pull.diff_stats repo, @base_commit, @head_commit
end
def set_base_project bang=true
args = params[:base_project].try(:split, '/') || []
if bang
raise ActiveRecord::RecordNotFound if args.length != 2
Project.find_by_owner_and_name! *args
else
return @project.root if args.length != 2
Project.find_by_owner_and_name(*args) || @project.root
end
end
def set_attrs
if pull_params && pull_params[:issue_attributes]
@pull.issue.title = pull_params[:issue_attributes][:title].presence

View File

@ -17,7 +17,6 @@
.leftlist=f.label :base_project, t("#{ar}.base_project"), :class => :label
%div
.l=f.autocomplete_field :base_project, autocomplete_base_project_project_pull_requests_path, :value => @pull.base_project.name_with_owner, :id_element => 'pull_request_base_project_id', :name => 'base_project'
=f.hidden_field :base_project_id, :name => 'base_project_id'
=render 'ref_select', :kind => 'base', :project => @pull.base_project, :current => @pull.base_ref
.both
.leftlist.big-list