2008-09-28 16:03:17 +04:00
|
|
|
# Redmine - project management software
|
2014-01-30 02:45:39 +04:00
|
|
|
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
2008-09-28 16:03:17 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-08-31 12:45:01 +04:00
|
|
|
#
|
2008-09-28 16:03:17 +04:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-08-31 12:45:01 +04:00
|
|
|
#
|
2008-09-28 16:03:17 +04:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
class WorkflowsController < ApplicationController
|
2009-12-17 21:21:02 +03:00
|
|
|
layout 'admin'
|
2011-08-31 12:45:01 +04:00
|
|
|
|
2014-02-25 06:54:47 +04:00
|
|
|
before_filter :require_admin
|
2011-08-31 12:45:01 +04:00
|
|
|
|
2008-09-28 16:03:17 +04:00
|
|
|
def index
|
2012-07-15 18:12:17 +04:00
|
|
|
@workflow_counts = WorkflowTransition.count_by_tracker_and_role
|
2008-09-28 16:03:17 +04:00
|
|
|
end
|
2011-08-31 12:45:01 +04:00
|
|
|
|
2008-09-28 16:03:17 +04:00
|
|
|
def edit
|
2014-02-25 06:54:47 +04:00
|
|
|
find_trackers_roles_and_statuses_for_edit
|
2011-08-31 12:45:01 +04:00
|
|
|
|
2014-02-25 06:54:47 +04:00
|
|
|
if request.post? && @roles && @trackers && params[:transitions]
|
|
|
|
transitions = params[:transitions].deep_dup
|
|
|
|
transitions.each do |old_status_id, transitions_by_new_status|
|
|
|
|
transitions_by_new_status.each do |new_status_id, transition_by_rule|
|
|
|
|
transition_by_rule.reject! {|rule, transition| transition == 'no_change'}
|
|
|
|
end
|
2008-09-28 16:03:17 +04:00
|
|
|
end
|
2014-02-25 06:54:47 +04:00
|
|
|
WorkflowTransition.replace_transitions(@trackers, @roles, transitions)
|
|
|
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
redirect_to_referer_or workflows_edit_path
|
|
|
|
return
|
2008-09-28 16:03:17 +04:00
|
|
|
end
|
2011-08-31 12:45:01 +04:00
|
|
|
|
2014-02-25 06:54:47 +04:00
|
|
|
if @trackers && @roles && @statuses.any?
|
|
|
|
workflows = WorkflowTransition.where(:role_id => @roles.map(&:id), :tracker_id => @trackers.map(&:id)).all
|
2011-02-20 18:38:07 +03:00
|
|
|
@workflows = {}
|
|
|
|
@workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
|
|
|
|
@workflows['author'] = workflows.select {|w| w.author}
|
|
|
|
@workflows['assignee'] = workflows.select {|w| w.assignee}
|
|
|
|
end
|
2008-09-28 16:03:17 +04:00
|
|
|
end
|
2011-08-31 12:45:01 +04:00
|
|
|
|
2012-07-15 18:12:17 +04:00
|
|
|
def permissions
|
2014-02-25 06:54:47 +04:00
|
|
|
find_trackers_roles_and_statuses_for_edit
|
2012-07-15 18:12:17 +04:00
|
|
|
|
2014-02-25 06:54:47 +04:00
|
|
|
if request.post? && @roles && @trackers && params[:permissions]
|
|
|
|
permissions = params[:permissions].deep_dup
|
|
|
|
permissions.each { |field, rule_by_status_id|
|
|
|
|
rule_by_status_id.reject! {|status_id, rule| rule == 'no_change'}
|
|
|
|
}
|
|
|
|
WorkflowPermission.replace_permissions(@trackers, @roles, permissions)
|
2014-01-25 17:17:08 +04:00
|
|
|
flash[:notice] = l(:notice_successful_update)
|
2014-02-25 06:54:47 +04:00
|
|
|
redirect_to_referer_or workflows_permissions_path
|
2012-07-15 19:46:14 +04:00
|
|
|
return
|
|
|
|
end
|
2012-07-15 18:12:17 +04:00
|
|
|
|
2014-02-25 06:54:47 +04:00
|
|
|
if @roles && @trackers
|
|
|
|
@fields = (Tracker::CORE_FIELDS_ALL - @trackers.map(&:disabled_core_fields).reduce(:&)).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
|
|
|
|
@custom_fields = @trackers.map(&:custom_fields).flatten.uniq.sort
|
|
|
|
@permissions = WorkflowPermission.rules_by_status_id(@trackers, @roles)
|
2012-07-15 18:12:17 +04:00
|
|
|
@statuses.each {|status| @permissions[status.id] ||= {}}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-12-12 13:06:07 +03:00
|
|
|
def copy
|
2014-02-25 06:54:47 +04:00
|
|
|
@roles = Role.sorted
|
|
|
|
@trackers = Tracker.sorted
|
|
|
|
|
2009-12-19 15:40:43 +03:00
|
|
|
if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
|
|
|
|
@source_tracker = nil
|
|
|
|
else
|
|
|
|
@source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
|
|
|
|
end
|
|
|
|
if params[:source_role_id].blank? || params[:source_role_id] == 'any'
|
|
|
|
@source_role = nil
|
|
|
|
else
|
|
|
|
@source_role = Role.find_by_id(params[:source_role_id].to_i)
|
|
|
|
end
|
2014-01-10 08:11:36 +04:00
|
|
|
@target_trackers = params[:target_tracker_ids].blank? ?
|
|
|
|
nil : Tracker.where(:id => params[:target_tracker_ids]).all
|
|
|
|
@target_roles = params[:target_role_ids].blank? ?
|
2014-01-10 08:19:47 +04:00
|
|
|
nil : Role.where(:id => params[:target_role_ids]).all
|
2009-12-12 13:06:07 +03:00
|
|
|
if request.post?
|
|
|
|
if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
|
|
|
|
flash.now[:error] = l(:error_workflow_copy_source)
|
2012-12-12 00:38:26 +04:00
|
|
|
elsif @target_trackers.blank? || @target_roles.blank?
|
2009-12-12 13:06:07 +03:00
|
|
|
flash.now[:error] = l(:error_workflow_copy_target)
|
|
|
|
else
|
2012-07-15 18:12:17 +04:00
|
|
|
WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
|
2009-12-12 13:06:07 +03:00
|
|
|
flash[:notice] = l(:notice_successful_update)
|
2012-12-11 23:39:47 +04:00
|
|
|
redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role)
|
2009-12-12 13:06:07 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-03-04 08:33:45 +03:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2014-02-25 06:54:47 +04:00
|
|
|
def find_trackers_roles_and_statuses_for_edit
|
|
|
|
find_roles
|
|
|
|
find_trackers
|
|
|
|
find_statuses
|
|
|
|
end
|
|
|
|
|
2010-03-04 08:33:45 +03:00
|
|
|
def find_roles
|
2014-02-25 06:54:47 +04:00
|
|
|
ids = Array.wrap(params[:role_id])
|
|
|
|
if ids == ['all']
|
|
|
|
@roles = Role.sorted.all
|
|
|
|
elsif ids.present?
|
|
|
|
@roles = Role.where(:id => ids).all
|
|
|
|
end
|
|
|
|
@roles = nil if @roles.blank?
|
2010-03-04 08:33:45 +03:00
|
|
|
end
|
2011-08-31 12:45:01 +04:00
|
|
|
|
2010-03-04 08:33:45 +03:00
|
|
|
def find_trackers
|
2014-02-25 06:54:47 +04:00
|
|
|
ids = Array.wrap(params[:tracker_id])
|
|
|
|
if ids == ['all']
|
|
|
|
@trackers = Tracker.sorted.all
|
|
|
|
elsif ids.present?
|
|
|
|
@trackers = Tracker.where(:id => ids).all
|
|
|
|
end
|
|
|
|
@trackers = nil if @trackers.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_statuses
|
|
|
|
@used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
|
|
|
|
if @trackers && @used_statuses_only
|
|
|
|
@statuses = @trackers.map(&:issue_statuses).flatten.uniq.sort.presence
|
|
|
|
end
|
|
|
|
@statuses ||= IssueStatus.sorted.all
|
2010-03-04 08:33:45 +03:00
|
|
|
end
|
2008-09-28 16:03:17 +04:00
|
|
|
end
|