Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto create PBI is done #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 17 additions & 33 deletions app/controllers/scrum_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ def new_pbi

def create_pbi
begin
@continue = !(params[:create_and_continue].nil?)
@top = !(params[:top].nil?)
@pbi = Issue.new
@pbi.project = @project
@pbi.author = User.current
@pbi.tracker_id = params[:issue][:tracker_id]
update_attributes(@pbi, params)
if @top
@pbi.set_on_top
@pbi.save!
continue = !(params[:create_and_continue].nil?)
top = !(params[:top].nil?)
pbi = Issue.new
pbi.project = @sprint.project
pbi.author = User.current
pbi.tracker_id = params['issue']['tracker_id']
@sprint.update_pbi_attributes(pbi, params)
if top
pbi.set_on_top
pbi.save!
end
@pbi.sprint = @sprint
@pbi.save!
rescue Exception => @exception
logger.error("Exception: #{@exception.inspect}")
pbi.sprint = @sprint
pbi.save!
rescue Exception => e
logger.error("Exception: #{e.inspect}")
end
respond_to do |format|
format.js
Expand All @@ -132,7 +132,7 @@ def edit_pbi
def update_pbi
begin
@pbi.init_journal(User.current, params[:issue][:notes])
update_attributes(@pbi, params)
@sprint.update_pbi_attributes(@pbi, params)
@pbi.save!
rescue Exception => @exception
logger.error("Exception: #{@exception.inspect}")
Expand Down Expand Up @@ -215,7 +215,7 @@ def create_task
@task.author = User.current
@task.sprint = @sprint
@task.tracker_id = params[:issue][:tracker_id]
update_attributes(@task, params)
@sprint.update_pbi_attributes(@task, params)
@task.save!
@task.pending_effort = params[:issue][:pending_effort]
rescue Exception => @exception
Expand All @@ -235,7 +235,7 @@ def update_task
begin
@issue.init_journal(User.current, params[:issue][:notes])
@old_status = @issue.status
update_attributes(@issue, params)
@sprint.update_pbi_attributes(@issue, params)
@issue.save!
@issue.pending_effort = params[:issue][:pending_effort]
rescue Exception => @exception
Expand Down Expand Up @@ -311,22 +311,6 @@ def authorize_edit_issues
authorize_action_on_current_project(:edit_issues)
end

def update_attributes(issue, params)
issue.status_id = params[:issue][:status_id] unless params[:issue][:status_id].nil?
raise 'New status is not allowed' unless issue.new_statuses_allowed_to.include?(issue.status)
issue.assigned_to_id = params[:issue][:assigned_to_id] unless params[:issue][:assigned_to_id].nil?
issue.subject = params[:issue][:subject] unless params[:issue][:subject].nil?
issue.priority_id = params[:issue][:priority_id] unless params[:issue][:priority_id].nil?
issue.estimated_hours = params[:issue][:estimated_hours].gsub(',', '.') unless params[:issue][:estimated_hours].nil?
issue.done_ratio = params[:issue][:done_ratio] unless params[:issue][:done_ratio].nil?
issue.description = params[:issue][:description] unless params[:issue][:description].nil?
issue.category_id = params[:issue][:category_id] if issue.safe_attribute?(:category_id) and (!(params[:issue][:category_id].nil?))
issue.fixed_version_id = params[:issue][:fixed_version_id] if issue.safe_attribute?(:fixed_version_id) and (!(params[:issue][:fixed_version_id].nil?))
issue.start_date = params[:issue][:start_date] if issue.safe_attribute?(:start_date) and (!(params[:issue][:start_date].nil?))
issue.due_date = params[:issue][:due_date] if issue.safe_attribute?(:due_date) and (!(params[:issue][:due_date].nil?))
issue.custom_field_values = params[:issue][:custom_field_values] unless params[:issue][:custom_field_values].nil?
end

def move_issue_to_sprint(issue, sprint)
issue.init_journal(User.current)
issue.sprint = sprint
Expand Down
51 changes: 51 additions & 0 deletions app/models/sprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Sprint < ActiveRecord::Base
include Redmine::SafeAttributes
safe_attributes :name, :description, :sprint_start_date, :sprint_end_date, :status, :shared
attr_protected :id
after_create :set_product_backlog

SPRINT_STATUSES = %w(open closed)

Expand All @@ -27,6 +28,56 @@ class Sprint < ActiveRecord::Base
validates_presence_of :sprint_end_date, :unless => :is_product_backlog?
validates_inclusion_of :status, :in => SPRINT_STATUSES

def set_product_backlog
params = { 'issue' => { 'tracker_id' => Tracker.find_by_name('Product Backlog').id,
'sprint_id' => self.id,
'subject' => "#{self.name} pbi",
'status_id' => IssueStatus.find_by_name('In Progress').id,
'priority_id' => Enumeration.find_by_name('Normal').id,
'assigned_to_id' => '',
'start_date' => self.sprint_start_date,
'due_date' => self.sprint_end_date,
'estimated_hours' => '',
'done_ratio' => '0',
'custom_field_values' => { CustomField.find_by_name('Story Points').id.to_s => CustomField.find_by_name('Story Points').default_value.to_s },
'description' => ''
}
}
begin
continue = !(params[:create_and_continue].nil?)
top = !(params[:top].nil?)
pbi = Issue.new
pbi.project = self.project
pbi.author = User.current
pbi.tracker_id = params['issue']['tracker_id']
update_pbi_attributes(pbi, params)
if top
pbi.set_on_top
pbi.save!
end
pbi.sprint = self
pbi.save!
rescue Exception => e
logger.error("Exception: #{e.inspect}")
end
end

def update_pbi_attributes(issue, params)
iissue.status_id = params['issue']['status_id'] unless params['issue']['status_id'].nil?
raise 'New status is not allowed' unless issue.new_statuses_allowed_to.include?(issue.status)
issue.assigned_to_id = params['issue']['assigned_to_id'] unless params['issue']['assigned_to_id'].nil?
issue.subject = params['issue']['subject'] unless params['issue']['subject'].nil?
issue.priority_id = params['issue']['priority_id'] unless params['issue']['priority_id'].nil?
issue.estimated_hours = params['issue']['estimated_hours'].gsub(',', '.') unless params['issue']['estimated_hours'].nil?
issue.done_ratio = params['issue']['done_ratio'] unless params['issue']['done_ratio'].nil?
issue.description = params['issue']['description'] unless params['issue']['description'].nil?
issue.category_id = params['issue']['category_id'] if issue.safe_attribute?('category_id') and (!(params['issue']['category_id'].nil?))
issue.fixed_version_id = params['issue']['fixed_version_id'] if issue.safe_attribute?('fixed_version_id') and (!(params['issue']['fixed_version_id'].nil?))
issue.start_date = params['issue']['start_date'] if issue.safe_attribute?('start_date') and (!(params['issue']['start_date'].nil?))
issue.due_date = params['issue']['due_date'] if issue.safe_attribute?('due_date') and (!(params['issue']['due_date'].nil?))
issue.custom_field_values = params['issue']['custom_field_values'] unless params['issue']['custom_field_values'].nil?
end

def to_s
name
end
Expand Down