To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / workflows_controller.rb @ 1535:e2c122809c5c

History | View | Annotate | Download (5.2 KB)

1 0:513646585e45 Chris
# Redmine - project management software
2 1494:e248c7af89ec Chris
# Copyright (C) 2006-2014  Jean-Philippe Lang
3 0:513646585e45 Chris
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8 909:cbb26bc654de Chris
#
9 0:513646585e45 Chris
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13 909:cbb26bc654de Chris
#
14 0:513646585e45 Chris
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18
class WorkflowsController < ApplicationController
19
  layout 'admin'
20 909:cbb26bc654de Chris
21 1115:433d4f72a19b Chris
  before_filter :require_admin, :find_roles, :find_trackers
22 909:cbb26bc654de Chris
23 0:513646585e45 Chris
  def index
24 1115:433d4f72a19b Chris
    @workflow_counts = WorkflowTransition.count_by_tracker_and_role
25 0:513646585e45 Chris
  end
26 909:cbb26bc654de Chris
27 0:513646585e45 Chris
  def edit
28 1115:433d4f72a19b Chris
    @role = Role.find_by_id(params[:role_id]) if params[:role_id]
29
    @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
30 909:cbb26bc654de Chris
31 0:513646585e45 Chris
    if request.post?
32 1115:433d4f72a19b Chris
      WorkflowTransition.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id])
33 245:051f544170fe Chris
      (params[:issue_status] || []).each { |status_id, transitions|
34
        transitions.each { |new_status_id, options|
35
          author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
36
          assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always')
37 1115:433d4f72a19b Chris
          WorkflowTransition.create(:role_id => @role.id, :tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee)
38 0:513646585e45 Chris
        }
39
      }
40
      if @role.save
41 1517:dffacf8a6908 Chris
        flash[:notice] = l(:notice_successful_update)
42 1464:261b3d9a4903 Chris
        redirect_to workflows_edit_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
43 245:051f544170fe Chris
        return
44 0:513646585e45 Chris
      end
45
    end
46 909:cbb26bc654de Chris
47 0:513646585e45 Chris
    @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
48
    if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
49
      @statuses = @tracker.issue_statuses
50
    end
51 1115:433d4f72a19b Chris
    @statuses ||= IssueStatus.sorted.all
52 909:cbb26bc654de Chris
53 245:051f544170fe Chris
    if @tracker && @role && @statuses.any?
54 1115:433d4f72a19b Chris
      workflows = WorkflowTransition.where(:role_id => @role.id, :tracker_id => @tracker.id).all
55 245:051f544170fe Chris
      @workflows = {}
56
      @workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
57
      @workflows['author'] = workflows.select {|w| w.author}
58
      @workflows['assignee'] = workflows.select {|w| w.assignee}
59
    end
60 0:513646585e45 Chris
  end
61 909:cbb26bc654de Chris
62 1115:433d4f72a19b Chris
  def permissions
63
    @role = Role.find_by_id(params[:role_id]) if params[:role_id]
64
    @tracker = Tracker.find_by_id(params[:tracker_id]) if params[:tracker_id]
65
66
    if request.post? && @role && @tracker
67
      WorkflowPermission.replace_permissions(@tracker, @role, params[:permissions] || {})
68 1517:dffacf8a6908 Chris
      flash[:notice] = l(:notice_successful_update)
69 1464:261b3d9a4903 Chris
      redirect_to workflows_permissions_path(:role_id => @role, :tracker_id => @tracker, :used_statuses_only => params[:used_statuses_only])
70 1115:433d4f72a19b Chris
      return
71
    end
72
73
    @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
74
    if @tracker && @used_statuses_only && @tracker.issue_statuses.any?
75
      @statuses = @tracker.issue_statuses
76
    end
77
    @statuses ||= IssueStatus.sorted.all
78
79
    if @role && @tracker
80
      @fields = (Tracker::CORE_FIELDS_ALL - @tracker.disabled_core_fields).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
81
      @custom_fields = @tracker.custom_fields
82 1517:dffacf8a6908 Chris
      @permissions = WorkflowPermission.
83
          where(:tracker_id => @tracker.id, :role_id => @role.id).inject({}) do |h, w|
84 1115:433d4f72a19b Chris
        h[w.old_status_id] ||= {}
85
        h[w.old_status_id][w.field_name] = w.rule
86
        h
87
      end
88
      @statuses.each {|status| @permissions[status.id] ||= {}}
89
    end
90
  end
91
92 0:513646585e45 Chris
  def copy
93
    if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
94
      @source_tracker = nil
95
    else
96
      @source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i)
97
    end
98
    if params[:source_role_id].blank? || params[:source_role_id] == 'any'
99
      @source_role = nil
100
    else
101
      @source_role = Role.find_by_id(params[:source_role_id].to_i)
102
    end
103 1517:dffacf8a6908 Chris
    @target_trackers = params[:target_tracker_ids].blank? ?
104
        nil : Tracker.where(:id => params[:target_tracker_ids]).all
105
    @target_roles = params[:target_role_ids].blank? ?
106
        nil : Role.where(:id => params[:target_role_ids]).all
107 0:513646585e45 Chris
    if request.post?
108
      if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
109
        flash.now[:error] = l(:error_workflow_copy_source)
110 1464:261b3d9a4903 Chris
      elsif @target_trackers.blank? || @target_roles.blank?
111 0:513646585e45 Chris
        flash.now[:error] = l(:error_workflow_copy_target)
112
      else
113 1115:433d4f72a19b Chris
        WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
114 0:513646585e45 Chris
        flash[:notice] = l(:notice_successful_update)
115 1464:261b3d9a4903 Chris
        redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role)
116 0:513646585e45 Chris
      end
117
    end
118
  end
119
120
  private
121
122
  def find_roles
123 1115:433d4f72a19b Chris
    @roles = Role.sorted.all
124 0:513646585e45 Chris
  end
125 909:cbb26bc654de Chris
126 0:513646585e45 Chris
  def find_trackers
127 1115:433d4f72a19b Chris
    @trackers = Tracker.sorted.all
128 0:513646585e45 Chris
  end
129
end