From a09b2a23b91206be0ac30dab76650d029340ad58 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 3 Apr 2007 18:34:22 +0000 Subject: [PATCH] Feature 9784 Set status when raising issue. git-svn-id: http://redmine.rubyforge.org/svn/trunk@407 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/projects_controller.rb | 10 +++++++++- app/models/issue.rb | 2 +- app/views/projects/add_issue.rhtml | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5f188a4dd..a778e5af2 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -212,12 +212,20 @@ class ProjectsController < ApplicationController def add_issue @tracker = Tracker.find(params[:tracker_id]) @priorities = Enumeration::get_values('IPRI') - @issue = Issue.new(:project => @project, :tracker => @tracker) + + default_status = IssueStatus.default + @issue = Issue.new(:project => @project, :tracker => @tracker, :status => default_status) + @allowed_statuses = [default_status] + default_status.workflows.find(:all, :order => 'position', :include => :new_status, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } + if request.get? @issue.start_date = Date.today @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } else @issue.attributes = params[:issue] + + requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) + @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status + @issue.author_id = self.logged_in_user.id if self.logged_in_user # Multiple file upload @attachments = [] diff --git a/app/models/issue.rb b/app/models/issue.rb index dd512017f..bb7797c40 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -38,7 +38,7 @@ class Issue < ActiveRecord::Base # set default status for new issues def before_validation - self.status = IssueStatus.default if new_record? + self.status = IssueStatus.default if status.nil? end def validate diff --git a/app/views/projects/add_issue.rhtml b/app/views/projects/add_issue.rhtml index 4f592ff7a..36c6d5869 100644 --- a/app/views/projects/add_issue.rhtml +++ b/app/views/projects/add_issue.rhtml @@ -7,6 +7,7 @@ <%= hidden_field_tag 'tracker_id', @tracker.id %>
+

<%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %>

<%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), :required => true %>

<%= f.select :assigned_to_id, (@issue.project.members.collect {|m| [m.name, m.user_id]}), :include_blank => true %>

<%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %>

-- 2.39.5