diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-02-14 08:03:51 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-02-14 08:03:51 +0000 |
commit | 3da7b1bc2882cfb02c5068680979158322242398 (patch) | |
tree | 87ed265520ff93243dbd7c1074e47f5e37c7abac /app | |
parent | b17883a2dff6cd49ea407b449ac0e97dca38e56a (diff) | |
download | redmine-3da7b1bc2882cfb02c5068680979158322242398.tar.gz redmine-3da7b1bc2882cfb02c5068680979158322242398.zip |
Implements /issues/new form for creating issues outside a project (#1003).
git-svn-id: http://svn.redmine.org/redmine/trunk@13999 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/issues_controller.rb | 55 | ||||
-rw-r--r-- | app/helpers/issues_helper.rb | 9 | ||||
-rw-r--r-- | app/models/issue.rb | 13 | ||||
-rw-r--r-- | app/views/issues/_form.html.erb | 2 | ||||
-rw-r--r-- | app/views/issues/new.html.erb | 4 |
5 files changed, 44 insertions, 39 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 8c1d73751..1cf909294 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -21,9 +21,8 @@ class IssuesController < ApplicationController before_filter :find_issue, :only => [:show, :edit, :update] before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] - before_filter :find_project, :only => [:new, :create] - before_filter :authorize, :except => [:index] - before_filter :find_optional_project, :only => [:index] + before_filter :authorize, :except => [:index, :new, :create] + before_filter :find_optional_project, :only => [:index, :new, :create] before_filter :build_new_issue_from_params, :only => [:new, :create] accept_rss_auth :index, :show accept_api_auth :index, :show, :create, :update, :destroy @@ -154,12 +153,7 @@ class IssuesController < ApplicationController format.html { render_attachment_warning_if_needed(@issue) flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject)) - if params[:continue] - attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} - redirect_to new_project_issue_path(@issue.project, :issue => attrs) - else - redirect_to issue_path(@issue) - end + redirect_after_create } format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } end @@ -359,13 +353,6 @@ class IssuesController < ApplicationController private - def find_project - project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id]) - @project = Project.find(project_id) - rescue ActiveRecord::RecordNotFound - render_404 - end - def retrieve_previous_and_next_issue_ids retrieve_query_from_session if @query @@ -434,6 +421,9 @@ class IssuesController < ApplicationController end end @issue.project = @project + if request.get? + @issue.project ||= @issue.allowed_target_projects.first + end @issue.author ||= User.current @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date? @@ -443,14 +433,16 @@ class IssuesController < ApplicationController end @issue.safe_attributes = attrs end - @issue.tracker ||= @project.trackers.first - if @issue.tracker.nil? - render_error l(:error_no_tracker_in_project) - return false - end - if @issue.status.nil? - render_error l(:error_no_default_issue_status) - return false + if @issue.project + @issue.tracker ||= @issue.project.trackers.first + if @issue.tracker.nil? + render_error l(:error_no_tracker_in_project) + return false + end + if @issue.status.nil? + render_error l(:error_no_default_issue_status) + return false + end end @priorities = IssuePriority.active @@ -505,4 +497,19 @@ class IssuesController < ApplicationController param == '1' end end + + # Redirects user after a successful issue creation + def redirect_after_create + if params[:continue] + attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} + if params[:project_id] + redirect_to new_project_issue_path(@issue.project, :issue => attrs) + else + attrs.merge! :project_id => @issue.project_id + redirect_to new_issue_path(:issue => attrs) + end + else + redirect_to issue_path(@issue) + end + end end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index e34039d76..a88adceb9 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -202,10 +202,15 @@ module IssuesHelper # Returns the path for updating the issue form # with project as the current project def update_issue_form_path(project, issue) + options = {:format => 'js'} if issue.new_record? - new_project_issue_path(project, :format => 'js') + if project + new_project_issue_path(project, options) + else + new_issue_path(options) + end else - edit_issue_path(issue, :format => 'js') + edit_issue_path(issue, options) end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 1e1fb9afc..5a49b0d7b 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -380,15 +380,7 @@ class Issue < ActiveRecord::Base end safe_attributes 'project_id', - :if => lambda {|issue, user| - if issue.new_record? - issue.copy? - else - user.allowed_to?(:edit_issues, issue.project) - end - } - - safe_attributes 'tracker_id', + 'tracker_id', 'status_id', 'category_id', 'assigned_to_id', @@ -429,7 +421,8 @@ class Issue < ActiveRecord::Base names = super names -= disabled_core_fields names -= read_only_attribute_names(user) - if new_record? && copy? + if new_record? + # Make sure that project_id can always be set for new issues names |= %w(project_id) end names diff --git a/app/views/issues/_form.html.erb b/app/views/issues/_form.html.erb index 44578610c..c071cb0e1 100644 --- a/app/views/issues/_form.html.erb +++ b/app/views/issues/_form.html.erb @@ -7,7 +7,7 @@ </p> <% end %> -<% if @issue.safe_attribute? 'project_id' %> +<% if @issue.safe_attribute?('project_id') && (!@issue.new_record? || @project.nil? || @issue.copy?) %> <p><%= f.select :project_id, project_tree_options_for_select(@issue.allowed_target_projects, :selected => @issue.project), {:required => true}, :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %></p> <% end %> diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb index f168c39a4..c93a1fc1f 100644 --- a/app/views/issues/new.html.erb +++ b/app/views/issues/new.html.erb @@ -2,7 +2,7 @@ <%= call_hook(:view_issues_new_top, {:issue => @issue}) %> -<%= labelled_form_for @issue, :url => project_issues_path(@project), +<%= labelled_form_for @issue, :url => _project_issues_path(@project), :html => {:id => 'issue-form', :multipart => true} do |f| %> <%= error_messages_for 'issue' %> <%= hidden_field_tag 'copy_from', params[:copy_from] if params[:copy_from] %> @@ -49,7 +49,7 @@ <%= submit_tag l(:button_create) %> <%= submit_tag l(:button_create_and_continue), :name => 'continue' %> - <%= preview_link preview_new_issue_path(:project_id => @project), 'issue-form' %> + <%= preview_link preview_new_issue_path(:project_id => @issue.project), 'issue-form' %> <% end %> <div id="preview" class="wiki"></div> |