Revision 1298:4f746d8966dd .svn/pristine/2a
| .svn/pristine/2a/2a26987d3e76c57b6a5ef62d32f7ea30699c2a7e.svn-base | ||
|---|---|---|
| 1 |
class AlphaPluginLibModel < ActiveRecord::Base |
|
| 2 |
def self.report_location; TestHelper::report_location(__FILE__); end |
|
| 3 |
end |
|
| .svn/pristine/2a/2a729c60b4face5ae26610fc483b9a2b1f7c2f71.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
|
| 3 |
# |
|
| 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 |
# |
|
| 9 |
# 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 |
# |
|
| 14 |
# 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 |
|
|
| 21 |
before_filter :require_admin |
|
| 22 |
before_filter :find_roles |
|
| 23 |
before_filter :find_trackers |
|
| 24 |
|
|
| 25 |
def index |
|
| 26 |
@workflow_counts = Workflow.count_by_tracker_and_role |
|
| 27 |
end |
|
| 28 |
|
|
| 29 |
def edit |
|
| 30 |
@role = Role.find_by_id(params[:role_id]) |
|
| 31 |
@tracker = Tracker.find_by_id(params[:tracker_id]) |
|
| 32 |
|
|
| 33 |
if request.post? |
|
| 34 |
Workflow.destroy_all( ["role_id=? and tracker_id=?", @role.id, @tracker.id]) |
|
| 35 |
(params[:issue_status] || []).each { |status_id, transitions|
|
|
| 36 |
transitions.each { |new_status_id, options|
|
|
| 37 |
author = options.is_a?(Array) && options.include?('author') && !options.include?('always')
|
|
| 38 |
assignee = options.is_a?(Array) && options.include?('assignee') && !options.include?('always')
|
|
| 39 |
@role.workflows.build(:tracker_id => @tracker.id, :old_status_id => status_id, :new_status_id => new_status_id, :author => author, :assignee => assignee) |
|
| 40 |
} |
|
| 41 |
} |
|
| 42 |
if @role.save |
|
| 43 |
flash[:notice] = l(:notice_successful_update) |
|
| 44 |
redirect_to :action => 'edit', :role_id => @role, :tracker_id => @tracker |
|
| 45 |
return |
|
| 46 |
end |
|
| 47 |
end |
|
| 48 |
|
|
| 49 |
@used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) |
|
| 50 |
if @tracker && @used_statuses_only && @tracker.issue_statuses.any? |
|
| 51 |
@statuses = @tracker.issue_statuses |
|
| 52 |
end |
|
| 53 |
@statuses ||= IssueStatus.find(:all, :order => 'position') |
|
| 54 |
|
|
| 55 |
if @tracker && @role && @statuses.any? |
|
| 56 |
workflows = Workflow.all(:conditions => {:role_id => @role.id, :tracker_id => @tracker.id})
|
|
| 57 |
@workflows = {}
|
|
| 58 |
@workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
|
|
| 59 |
@workflows['author'] = workflows.select {|w| w.author}
|
|
| 60 |
@workflows['assignee'] = workflows.select {|w| w.assignee}
|
|
| 61 |
end |
|
| 62 |
end |
|
| 63 |
|
|
| 64 |
def copy |
|
| 65 |
|
|
| 66 |
if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any' |
|
| 67 |
@source_tracker = nil |
|
| 68 |
else |
|
| 69 |
@source_tracker = Tracker.find_by_id(params[:source_tracker_id].to_i) |
|
| 70 |
end |
|
| 71 |
if params[:source_role_id].blank? || params[:source_role_id] == 'any' |
|
| 72 |
@source_role = nil |
|
| 73 |
else |
|
| 74 |
@source_role = Role.find_by_id(params[:source_role_id].to_i) |
|
| 75 |
end |
|
| 76 |
|
|
| 77 |
@target_trackers = params[:target_tracker_ids].blank? ? nil : Tracker.find_all_by_id(params[:target_tracker_ids]) |
|
| 78 |
@target_roles = params[:target_role_ids].blank? ? nil : Role.find_all_by_id(params[:target_role_ids]) |
|
| 79 |
|
|
| 80 |
if request.post? |
|
| 81 |
if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?) |
|
| 82 |
flash.now[:error] = l(:error_workflow_copy_source) |
|
| 83 |
elsif @target_trackers.nil? || @target_roles.nil? |
|
| 84 |
flash.now[:error] = l(:error_workflow_copy_target) |
|
| 85 |
else |
|
| 86 |
Workflow.copy(@source_tracker, @source_role, @target_trackers, @target_roles) |
|
| 87 |
flash[:notice] = l(:notice_successful_update) |
|
| 88 |
redirect_to :action => 'copy', :source_tracker_id => @source_tracker, :source_role_id => @source_role |
|
| 89 |
end |
|
| 90 |
end |
|
| 91 |
end |
|
| 92 |
|
|
| 93 |
private |
|
| 94 |
|
|
| 95 |
def find_roles |
|
| 96 |
@roles = Role.find(:all, :order => 'builtin, position') |
|
| 97 |
end |
|
| 98 |
|
|
| 99 |
def find_trackers |
|
| 100 |
@trackers = Tracker.find(:all, :order => 'position') |
|
| 101 |
end |
|
| 102 |
end |
|
| .svn/pristine/2a/2a8a6f95df9c9b5ea1480ac33b5f365836080244.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
|
| 3 |
# |
|
| 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 |
# |
|
| 9 |
# 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 |
# |
|
| 14 |
# 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 Setting < ActiveRecord::Base |
|
| 19 |
|
|
| 20 |
DATE_FORMATS = [ |
|
| 21 |
'%Y-%m-%d', |
|
| 22 |
'%d/%m/%Y', |
|
| 23 |
'%d.%m.%Y', |
|
| 24 |
'%d-%m-%Y', |
|
| 25 |
'%m/%d/%Y', |
|
| 26 |
'%d %b %Y', |
|
| 27 |
'%d %B %Y', |
|
| 28 |
'%b %d, %Y', |
|
| 29 |
'%B %d, %Y' |
|
| 30 |
] |
|
| 31 |
|
|
| 32 |
TIME_FORMATS = [ |
|
| 33 |
'%H:%M', |
|
| 34 |
'%I:%M %p' |
|
| 35 |
] |
|
| 36 |
|
|
| 37 |
ENCODINGS = %w(US-ASCII |
|
| 38 |
windows-1250 |
|
| 39 |
windows-1251 |
|
| 40 |
windows-1252 |
|
| 41 |
windows-1253 |
|
| 42 |
windows-1254 |
|
| 43 |
windows-1255 |
|
| 44 |
windows-1256 |
|
| 45 |
windows-1257 |
|
| 46 |
windows-1258 |
|
| 47 |
windows-31j |
|
| 48 |
ISO-2022-JP |
|
| 49 |
ISO-2022-KR |
|
| 50 |
ISO-8859-1 |
|
| 51 |
ISO-8859-2 |
|
| 52 |
ISO-8859-3 |
|
| 53 |
ISO-8859-4 |
|
| 54 |
ISO-8859-5 |
|
| 55 |
ISO-8859-6 |
|
| 56 |
ISO-8859-7 |
|
| 57 |
ISO-8859-8 |
|
| 58 |
ISO-8859-9 |
|
| 59 |
ISO-8859-13 |
|
| 60 |
ISO-8859-15 |
|
| 61 |
KOI8-R |
|
| 62 |
UTF-8 |
|
| 63 |
UTF-16 |
|
| 64 |
UTF-16BE |
|
| 65 |
UTF-16LE |
|
| 66 |
EUC-JP |
|
| 67 |
Shift_JIS |
|
| 68 |
CP932 |
|
| 69 |
GB18030 |
|
| 70 |
GBK |
|
| 71 |
ISCII91 |
|
| 72 |
EUC-KR |
|
| 73 |
Big5 |
|
| 74 |
Big5-HKSCS |
|
| 75 |
TIS-620) |
|
| 76 |
|
|
| 77 |
cattr_accessor :available_settings |
|
| 78 |
@@available_settings = YAML::load(File.open("#{Rails.root}/config/settings.yml"))
|
|
| 79 |
Redmine::Plugin.all.each do |plugin| |
|
| 80 |
next unless plugin.settings |
|
| 81 |
@@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
|
|
| 82 |
end |
|
| 83 |
|
|
| 84 |
validates_uniqueness_of :name |
|
| 85 |
validates_inclusion_of :name, :in => @@available_settings.keys |
|
| 86 |
validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }
|
|
| 87 |
|
|
| 88 |
# Hash used to cache setting values |
|
| 89 |
@cached_settings = {}
|
|
| 90 |
@cached_cleared_on = Time.now |
|
| 91 |
|
|
| 92 |
def value |
|
| 93 |
v = read_attribute(:value) |
|
| 94 |
# Unserialize serialized settings |
|
| 95 |
v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String) |
|
| 96 |
v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank? |
|
| 97 |
v |
|
| 98 |
end |
|
| 99 |
|
|
| 100 |
def value=(v) |
|
| 101 |
v = v.to_yaml if v && @@available_settings[name] && @@available_settings[name]['serialized'] |
|
| 102 |
write_attribute(:value, v.to_s) |
|
| 103 |
end |
|
| 104 |
|
|
| 105 |
# Returns the value of the setting named name |
|
| 106 |
def self.[](name) |
|
| 107 |
v = @cached_settings[name] |
|
| 108 |
v ? v : (@cached_settings[name] = find_or_default(name).value) |
|
| 109 |
end |
|
| 110 |
|
|
| 111 |
def self.[]=(name, v) |
|
| 112 |
setting = find_or_default(name) |
|
| 113 |
setting.value = (v ? v : "") |
|
| 114 |
@cached_settings[name] = nil |
|
| 115 |
setting.save |
|
| 116 |
setting.value |
|
| 117 |
end |
|
| 118 |
|
|
| 119 |
# Defines getter and setter for each setting |
|
| 120 |
# Then setting values can be read using: Setting.some_setting_name |
|
| 121 |
# or set using Setting.some_setting_name = "some value" |
|
| 122 |
@@available_settings.each do |name, params| |
|
| 123 |
src = <<-END_SRC |
|
| 124 |
def self.#{name}
|
|
| 125 |
self[:#{name}]
|
|
| 126 |
end |
|
| 127 |
|
|
| 128 |
def self.#{name}?
|
|
| 129 |
self[:#{name}].to_i > 0
|
|
| 130 |
end |
|
| 131 |
|
|
| 132 |
def self.#{name}=(value)
|
|
| 133 |
self[:#{name}] = value
|
|
| 134 |
end |
|
| 135 |
END_SRC |
|
| 136 |
class_eval src, __FILE__, __LINE__ |
|
| 137 |
end |
|
| 138 |
|
|
| 139 |
# Helper that returns an array based on per_page_options setting |
|
| 140 |
def self.per_page_options_array |
|
| 141 |
per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
|
|
| 142 |
end |
|
| 143 |
|
|
| 144 |
def self.openid? |
|
| 145 |
Object.const_defined?(:OpenID) && self[:openid].to_i > 0 |
|
| 146 |
end |
|
| 147 |
|
|
| 148 |
# Checks if settings have changed since the values were read |
|
| 149 |
# and clears the cache hash if it's the case |
|
| 150 |
# Called once per request |
|
| 151 |
def self.check_cache |
|
| 152 |
settings_updated_on = Setting.maximum(:updated_on) |
|
| 153 |
if settings_updated_on && @cached_cleared_on <= settings_updated_on |
|
| 154 |
clear_cache |
|
| 155 |
end |
|
| 156 |
end |
|
| 157 |
|
|
| 158 |
# Clears the settings cache |
|
| 159 |
def self.clear_cache |
|
| 160 |
@cached_settings.clear |
|
| 161 |
@cached_cleared_on = Time.now |
|
| 162 |
logger.info "Settings cache cleared." if logger |
|
| 163 |
end |
|
| 164 |
|
|
| 165 |
private |
|
| 166 |
# Returns the Setting instance for the setting named name |
|
| 167 |
# (record found in database or new record with default value) |
|
| 168 |
def self.find_or_default(name) |
|
| 169 |
name = name.to_s |
|
| 170 |
raise "There's no setting named #{name}" unless @@available_settings.has_key?(name)
|
|
| 171 |
setting = find_by_name(name) |
|
| 172 |
unless setting |
|
| 173 |
setting = new(:name => name) |
|
| 174 |
setting.value = @@available_settings[name]['default'] |
|
| 175 |
end |
|
| 176 |
setting |
|
| 177 |
end |
|
| 178 |
end |
|
Also available in: Unified diff