Project

General

Profile

« Previous | Next » 

Revision 1200

Added git support branch.

View differences:

branches/work/git/Rakefile
1
# Add your own tasks in files placed in lib/tasks ending in .rake,
2
# for example lib/tasks/switchtower.rake, and they will automatically be available to Rake.
3

  
4
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5

  
6
require 'rake'
7
require 'rake/testtask'
8
require 'rake/rdoctask'
9

  
10
require 'tasks/rails'
branches/work/git/app/apis/sys_api.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2007  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 SysApi < ActionWebService::API::Base
19
  api_method :projects,
20
             :expects => [],
21
             :returns => [[Project]]
22
  api_method :repository_created,
23
             :expects => [:string, :string],
24
             :returns => [:int]
25
end
0 26

  
branches/work/git/app/controllers/account_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2007  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 AccountController < ApplicationController
19
  layout 'base'	
20
  helper :custom_fields
21
  include CustomFieldsHelper   
22
  
23
  # prevents login action to be filtered by check_if_login_required application scope filter
24
  skip_before_filter :check_if_login_required, :only => [:login, :lost_password, :register, :activate]
25

  
26
  # Show user's account
27
  def show
28
    @user = User.find_active(params[:id])
29
    @custom_values = @user.custom_values.find(:all, :include => :custom_field)
30
    
31
    # show only public projects and private projects that the logged in user is also a member of
32
    @memberships = @user.memberships.select do |membership|
33
      membership.project.is_public? || (User.current.member_of?(membership.project))
34
    end
35
  rescue ActiveRecord::RecordNotFound
36
    render_404
37
  end
38

  
39
  # Login request and validation
40
  def login
41
    if request.get?
42
      # Logout user
43
      self.logged_user = nil
44
    else
45
      # Authenticate user
46
      user = User.try_to_login(params[:username], params[:password])
47
      if user
48
        self.logged_user = user
49
        # generate a key and set cookie if autologin
50
        if params[:autologin] && Setting.autologin?
51
          token = Token.create(:user => user, :action => 'autologin')
52
          cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
53
        end
54
        redirect_back_or_default :controller => 'my', :action => 'page'
55
      else
56
        flash.now[:error] = l(:notice_account_invalid_creditentials)
57
      end
58
    end
59
  end
60

  
61
  # Log out current user and redirect to welcome page
62
  def logout
63
    cookies.delete :autologin
64
    Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) if User.current.logged?
65
    self.logged_user = nil
66
    redirect_to home_url
67
  end
68
  
69
  # Enable user to choose a new password
70
  def lost_password
71
    redirect_to(home_url) && return unless Setting.lost_password?
72
    if params[:token]
73
      @token = Token.find_by_action_and_value("recovery", params[:token])
74
      redirect_to(home_url) && return unless @token and [email protected]?
75
      @user = @token.user
76
      if request.post?
77
        @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
78
        if @user.save
79
          @token.destroy
80
          flash[:notice] = l(:notice_account_password_updated)
81
          redirect_to :action => 'login'
82
          return
83
        end 
84
      end
85
      render :template => "account/password_recovery"
86
      return
87
    else
88
      if request.post?
89
        user = User.find_by_mail(params[:mail])
90
        # user not found in db
91
        flash.now[:error] = l(:notice_account_unknown_email) and return unless user
92
        # user uses an external authentification
93
        flash.now[:error] = l(:notice_can_t_change_password) and return if user.auth_source_id
94
        # create a new token for password recovery
95
        token = Token.new(:user => user, :action => "recovery")
96
        if token.save
97
          Mailer.deliver_lost_password(token)
98
          flash[:notice] = l(:notice_account_lost_email_sent)
99
          redirect_to :action => 'login'
100
          return
101
        end
102
      end
103
    end
104
  end
105
  
106
  # User self-registration
107
  def register
108
    redirect_to(home_url) && return unless Setting.self_registration?
109
    if request.get?
110
      @user = User.new(:language => Setting.default_language)
111
      @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
112
    else
113
      @user = User.new(params[:user])
114
      @user.admin = false
115
      @user.login = params[:user][:login]
116
      @user.status = User::STATUS_REGISTERED
117
      @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
118
      @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, 
119
                                                                                :customized => @user, 
120
                                                                                :value => (params["custom_fields"] ? params["custom_fields"][x.id.to_s] : nil)) }
121
      @user.custom_values = @custom_values
122
      case Setting.self_registration
123
      when '1'
124
        # Email activation
125
        token = Token.new(:user => @user, :action => "register")
126
        if @user.save and token.save
127
          Mailer.deliver_register(token)
128
          flash[:notice] = l(:notice_account_register_done)
129
          redirect_to :action => 'login'
130
        end
131
      when '3'
132
        # Automatic activation
133
        @user.status = User::STATUS_ACTIVE
134
        if @user.save
135
          flash[:notice] = l(:notice_account_activated)
136
          redirect_to :action => 'login'
137
        end
138
      else
139
        # Manual activation by the administrator
140
        if @user.save
141
          # Sends an email to the administrators
142
          Mailer.deliver_account_activation_request(@user)
143
          flash[:notice] = l(:notice_account_pending)
144
          redirect_to :action => 'login'
145
        end
146
      end
147
    end
148
  end
149
  
150
  # Token based account activation
151
  def activate
152
    redirect_to(home_url) && return unless Setting.self_registration? && params[:token]
153
    token = Token.find_by_action_and_value('register', params[:token])
154
    redirect_to(home_url) && return unless token and !token.expired?
155
    user = token.user
156
    redirect_to(home_url) && return unless user.status == User::STATUS_REGISTERED
157
    user.status = User::STATUS_ACTIVE
158
    if user.save
159
      token.destroy
160
      flash[:notice] = l(:notice_account_activated)
161
    end
162
    redirect_to :action => 'login'
163
  end
164
  
165
private
166
  def logged_user=(user)
167
    if user && user.is_a?(User)
168
      User.current = user
169
      session[:user_id] = user.id
170
    else
171
      User.current = User.anonymous
172
      session[:user_id] = nil
173
    end
174
  end
175
end
0 176

  
branches/work/git/app/controllers/admin_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006  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 AdminController < ApplicationController
19
  layout 'base'	
20
  before_filter :require_admin
21

  
22
  helper :sort
23
  include SortHelper	
24

  
25
  def index
26
    @no_configuration_data = Redmine::DefaultData::Loader::no_data?
27
  end
28
	
29
  def projects
30
    sort_init 'name', 'asc'
31
    sort_update
32
    
33
    @status = params[:status] ? params[:status].to_i : 0
34
    conditions = nil
35
    conditions = ["status=?", @status] unless @status == 0
36
    
37
    @project_count = Project.count(:conditions => conditions)
38
    @project_pages = Paginator.new self, @project_count,
39
								per_page_option,
40
								params['page']								
41
    @projects = Project.find :all, :order => sort_clause,
42
                        :conditions => conditions,
43
						:limit  =>  @project_pages.items_per_page,
44
						:offset =>  @project_pages.current.offset
45

  
46
    render :action => "projects", :layout => false if request.xhr?
47
  end
48
  
49
  # Loads the default configuration
50
  # (roles, trackers, statuses, workflow, enumerations)
51
  def default_configuration
52
    if request.post?
53
      begin
54
        Redmine::DefaultData::Loader::load(params[:lang])
55
        flash[:notice] = l(:notice_default_data_loaded)
56
      rescue Exception => e
57
        flash[:error] = l(:error_can_t_load_default_data, e.message)
58
      end
59
    end
60
    redirect_to :action => 'index'
61
  end
62
  
63
  def test_email
64
    raise_delivery_errors = ActionMailer::Base.raise_delivery_errors
65
    # Force ActionMailer to raise delivery errors so we can catch it
66
    ActionMailer::Base.raise_delivery_errors = true
67
    begin
68
      @test = Mailer.deliver_test(User.current)
69
      flash[:notice] = l(:notice_email_sent, User.current.mail)
70
    rescue Exception => e
71
      flash[:error] = l(:notice_email_error, e.message)
72
    end
73
    ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
74
    redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications'
75
  end
76
  
77
  def info
78
    @db_adapter_name = ActiveRecord::Base.connection.adapter_name
79
    @flags = {
80
      :default_admin_changed => User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?,
81
      :file_repository_writable => File.writable?(Attachment.storage_path),
82
      :rmagick_available => Object.const_defined?(:Magick)
83
    }
84
    @plugins = Redmine::Plugin.registered_plugins
85
  end  
86
end
0 87

  
branches/work/git/app/controllers/application.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2007  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 ApplicationController < ActionController::Base
19
  before_filter :user_setup, :check_if_login_required, :set_localization
20
  filter_parameter_logging :password
21
  
22
  include Redmine::MenuManager::MenuController
23
  helper Redmine::MenuManager::MenuHelper
24
  
25
  REDMINE_SUPPORTED_SCM.each do |scm|
26
    require_dependency "repository/#{scm.underscore}"
27
  end
28
  
29
  def current_role
30
    @current_role ||= User.current.role_for_project(@project)
31
  end
32
  
33
  def user_setup
34
    # Check the settings cache for each request
35
    Setting.check_cache
36
    # Find the current user
37
    User.current = find_current_user
38
  end
39
  
40
  # Returns the current user or nil if no user is logged in
41
  def find_current_user
42
    if session[:user_id]
43
      # existing session
44
      (User.find_active(session[:user_id]) rescue nil)
45
    elsif cookies[:autologin] && Setting.autologin?
46
      # auto-login feature
47
      User.find_by_autologin_key(cookies[:autologin])
48
    elsif params[:key] && accept_key_auth_actions.include?(params[:action])
49
      # RSS key authentication
50
      User.find_by_rss_key(params[:key])
51
    end
52
  end
53
  
54
  # check if login is globally required to access the application
55
  def check_if_login_required
56
    # no check needed if user is already logged in
57
    return true if User.current.logged?
58
    require_login if Setting.login_required?
59
  end 
60
  
61
  def set_localization
62
    User.current.language = nil unless User.current.logged?
63
    lang = begin
64
      if !User.current.language.blank? and GLoc.valid_languages.include? User.current.language.to_sym
65
        User.current.language
66
      elsif request.env['HTTP_ACCEPT_LANGUAGE']
67
        accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first
68
        if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym
69
          User.current.language = accept_lang
70
        end
71
      end
72
    rescue
73
      nil
74
    end || Setting.default_language
75
    set_language_if_valid(lang)    
76
  end
77
  
78
  def require_login
79
    if !User.current.logged?
80
      store_location
81
      redirect_to :controller => "account", :action => "login"
82
      return false
83
    end
84
    true
85
  end
86

  
87
  def require_admin
88
    return unless require_login
89
    if !User.current.admin?
90
      render_403
91
      return false
92
    end
93
    true
94
  end
95

  
96
  # Authorize the user for the requested action
97
  def authorize(ctrl = params[:controller], action = params[:action])
98
    allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project)
99
    allowed ? true : (User.current.logged? ? render_403 : require_login)
100
  end
101
  
102
  # make sure that the user is a member of the project (or admin) if project is private
103
  # used as a before_filter for actions that do not require any particular permission on the project
104
  def check_project_privacy
105
    unless @project.active?
106
      @project = nil
107
      render_404
108
      return false
109
    end
110
    return true if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
111
    User.current.logged? ? render_403 : require_login
112
  end
113

  
114
  # store current uri in session.
115
  # return to this location by calling redirect_back_or_default
116
  def store_location
117
    session[:return_to_params] = params
118
  end
119

  
120
  # move to the last store_location call or to the passed default one
121
  def redirect_back_or_default(default)
122
    if session[:return_to_params].nil?
123
      redirect_to default
124
    else
125
      redirect_to session[:return_to_params]
126
      session[:return_to_params] = nil
127
    end
128
  end
129
  
130
  def render_403
131
    @project = nil
132
    render :template => "common/403", :layout => !request.xhr?, :status => 403
133
    return false
134
  end
135
    
136
  def render_404
137
    render :template => "common/404", :layout => !request.xhr?, :status => 404
138
    return false
139
  end
140
  
141
  def render_error(msg)
142
    flash.now[:error] = msg
143
    render :nothing => true, :layout => !request.xhr?, :status => 500
144
  end
145
  
146
  def render_feed(items, options={})    
147
    @items = items || []
148
    @items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
149
    @title = options[:title] || Setting.app_title
150
    render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
151
  end
152
  
153
  def self.accept_key_auth(*actions)
154
    actions = actions.flatten.map(&:to_s)
155
    write_inheritable_attribute('accept_key_auth_actions', actions)
156
  end
157
  
158
  def accept_key_auth_actions
159
    self.class.read_inheritable_attribute('accept_key_auth_actions') || []
160
  end
161
  
162
  # TODO: move to model
163
  def attach_files(obj, attachments)
164
    attached = []
165
    if attachments && attachments.is_a?(Hash)
166
      attachments.each_value do |attachment|
167
        file = attachment['file']
168
        next unless file && file.size > 0
169
        a = Attachment.create(:container => obj, 
170
                              :file => file,
171
                              :description => attachment['description'].to_s.strip,
172
                              :author => User.current)
173
        attached << a unless a.new_record?
174
      end
175
    end
176
    attached
177
  end
178

  
179
  # Returns the number of objects that should be displayed
180
  # on the paginated list
181
  def per_page_option
182
    per_page = nil
183
    if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
184
      per_page = params[:per_page].to_s.to_i
185
      session[:per_page] = per_page
186
    elsif session[:per_page]
187
      per_page = session[:per_page]
188
    else
189
      per_page = Setting.per_page_options_array.first || 25
190
    end
191
    per_page
192
  end
193

  
194
  # qvalues http header parser
195
  # code taken from webrick
196
  def parse_qvalues(value)
197
    tmp = []
198
    if value
199
      parts = value.split(/,\s*/)
200
      parts.each {|part|
201
        if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
202
          val = m[1]
203
          q = (m[2] or 1).to_f
204
          tmp.push([val, q])
205
        end
206
      }
207
      tmp = tmp.sort_by{|val, q| -q}
208
      tmp.collect!{|val, q| val}
209
    end
210
    return tmp
211
  end
212
  
213
  # Returns a string that can be used as filename value in Content-Disposition header
214
  def filename_for_content_disposition(name)
215
    request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
216
  end
217
end
0 218

  
branches/work/git/app/controllers/attachments_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2007  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 AttachmentsController < ApplicationController
19
  layout 'base'
20
  before_filter :find_project, :check_project_privacy
21

  
22
  def download
23
    # images are sent inline
24
    send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
25
                                    :type => @attachment.content_type, 
26
                                    :disposition => (@attachment.image? ? 'inline' : 'attachment')
27
  rescue
28
    # in case the disk file was deleted
29
    render_404
30
  end
31
 
32
private
33
  def find_project
34
    @attachment = Attachment.find(params[:id])
35
    @project = @attachment.project
36
  rescue
37
    render_404
38
  end
39
end
0 40

  
branches/work/git/app/controllers/auth_sources_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006  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 AuthSourcesController < ApplicationController
19
  layout 'base'	
20
  before_filter :require_admin
21

  
22
  def index
23
    list
24
    render :action => 'list' unless request.xhr?
25
  end
26

  
27
  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
28
  verify :method => :post, :only => [ :destroy, :create, :update ],
29
         :redirect_to => { :action => :list }
30

  
31
  def list
32
    @auth_source_pages, @auth_sources = paginate :auth_sources, :per_page => 10
33
    render :action => "list", :layout => false if request.xhr?
34
  end
35

  
36
  def new
37
    @auth_source = AuthSourceLdap.new
38
  end
39

  
40
  def create
41
    @auth_source = AuthSourceLdap.new(params[:auth_source])
42
    if @auth_source.save
43
      flash[:notice] = l(:notice_successful_create)
44
      redirect_to :action => 'list'
45
    else
46
      render :action => 'new'
47
    end
48
  end
49

  
50
  def edit
51
    @auth_source = AuthSource.find(params[:id])
52
  end
53

  
54
  def update
55
    @auth_source = AuthSource.find(params[:id])
56
    if @auth_source.update_attributes(params[:auth_source])
57
      flash[:notice] = l(:notice_successful_update)
58
      redirect_to :action => 'list'
59
    else
60
      render :action => 'edit'
61
    end
62
  end
63
  
64
  def test_connection
65
    @auth_method = AuthSource.find(params[:id])
66
    begin
67
      @auth_method.test_connection
68
      flash[:notice] = l(:notice_successful_connection)
69
    rescue => text
70
      flash[:error] = "Unable to connect (#{text})"
71
    end
72
    redirect_to :action => 'list'
73
  end
74

  
75
  def destroy
76
    @auth_source = AuthSource.find(params[:id])
77
    unless @auth_source.users.find(:first)
78
      @auth_source.destroy
79
      flash[:notice] = l(:notice_successful_delete)
80
    end
81
    redirect_to :action => 'list'
82
  end
83
end
0 84

  
branches/work/git/app/controllers/boards_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2007  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 BoardsController < ApplicationController
19
  layout 'base'
20
  before_filter :find_project, :authorize
21

  
22
  helper :messages
23
  include MessagesHelper
24
  helper :sort
25
  include SortHelper
26
  helper :watchers
27
  include WatchersHelper
28
 
29
  def index
30
    @boards = @project.boards
31
    # show the board if there is only one
32
    if @boards.size == 1
33
      @board = @boards.first
34
      show
35
    end
36
  end
37

  
38
  def show
39
    sort_init "#{Message.table_name}.updated_on", "desc"
40
    sort_update	
41
      
42
    @topic_count = @board.topics.count
43
    @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
44
    @topics =  @board.topics.find :all, :order => "#{Message.table_name}.sticky DESC, #{sort_clause}",
45
                                  :include => [:author, {:last_reply => :author}],
46
                                  :limit  =>  @topic_pages.items_per_page,
47
                                  :offset =>  @topic_pages.current.offset
48
    render :action => 'show', :layout => !request.xhr?
49
  end
50
  
51
  verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
52

  
53
  def new
54
    @board = Board.new(params[:board])
55
    @board.project = @project
56
    if request.post? && @board.save
57
      flash[:notice] = l(:notice_successful_create)
58
      redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
59
    end
60
  end
61

  
62
  def edit
63
    if request.post? && @board.update_attributes(params[:board])
64
      case params[:position]
65
      when 'highest'; @board.move_to_top
66
      when 'higher'; @board.move_higher
67
      when 'lower'; @board.move_lower
68
      when 'lowest'; @board.move_to_bottom
69
      end if params[:position]
70
      redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
71
    end
72
  end
73

  
74
  def destroy
75
    @board.destroy
76
    redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
77
  end
78
  
79
private
80
  def find_project
81
    @project = Project.find(params[:project_id])
82
    @board = @project.boards.find(params[:id]) if params[:id]
83
  rescue ActiveRecord::RecordNotFound
84
    render_404
85
  end
86
end
0 87

  
branches/work/git/app/controllers/custom_fields_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006  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 CustomFieldsController < ApplicationController
19
  layout 'base'		
20
  before_filter :require_admin
21

  
22
  def index
23
    list
24
    render :action => 'list' unless request.xhr?
25
  end
26

  
27
  def list
28
    @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
29
    @tab = params[:tab] || 'IssueCustomField'
30
    render :action => "list", :layout => false if request.xhr?
31
  end
32
  
33
  def new
34
    case params[:type]
35
      when "IssueCustomField" 
36
        @custom_field = IssueCustomField.new(params[:custom_field])
37
        @custom_field.trackers = Tracker.find(params[:tracker_ids]) if params[:tracker_ids]
38
      when "UserCustomField" 
39
        @custom_field = UserCustomField.new(params[:custom_field])
40
      when "ProjectCustomField" 
41
        @custom_field = ProjectCustomField.new(params[:custom_field])
42
      else
43
        redirect_to :action => 'list'
44
        return
45
    end  
46
    if request.post? and @custom_field.save
47
      flash[:notice] = l(:notice_successful_create)
48
      redirect_to :action => 'list', :tab => @custom_field.class.name
49
    end
50
    @trackers = Tracker.find(:all, :order => 'position')
51
  end
52

  
53
  def edit
54
    @custom_field = CustomField.find(params[:id])
55
    if request.post? and @custom_field.update_attributes(params[:custom_field])
56
      if @custom_field.is_a? IssueCustomField
57
        @custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : []
58
      end
59
      flash[:notice] = l(:notice_successful_update)
60
      redirect_to :action => 'list', :tab => @custom_field.class.name
61
    end
62
    @trackers = Tracker.find(:all, :order => 'position')
63
  end
64

  
65
  def move
66
    @custom_field = CustomField.find(params[:id])
67
    case params[:position]
68
    when 'highest'
69
      @custom_field.move_to_top
70
    when 'higher'
71
      @custom_field.move_higher
72
    when 'lower'
73
      @custom_field.move_lower
74
    when 'lowest'
75
      @custom_field.move_to_bottom
76
    end if params[:position]
77
    redirect_to :action => 'list', :tab => @custom_field.class.name
78
  end
79
  
80
  def destroy
81
    @custom_field = CustomField.find(params[:id]).destroy
82
    redirect_to :action => 'list', :tab => @custom_field.class.name
83
  rescue
84
    flash[:error] = "Unable to delete custom field"
85
    redirect_to :action => 'list'
86
  end
87
end
0 88

  
branches/work/git/app/controllers/documents_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2007  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 DocumentsController < ApplicationController
19
  layout 'base'
20
  before_filter :find_project, :only => [:index, :new]
21
  before_filter :find_document, :except => [:index, :new]
22
  before_filter :authorize
23
  
24
  helper :attachments
25
  
26
  def index
27
    @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
28
    documents = @project.documents.find :all, :include => [:attachments, :category]
29
    case @sort_by
30
    when 'date'
31
      @grouped = documents.group_by {|d| d.created_on.to_date }
32
    when 'title'
33
      @grouped = documents.group_by {|d| d.title.first.upcase}
34
    when 'author'
35
      @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
36
    else
37
      @grouped = documents.group_by(&:category)
38
    end
39
    render :layout => false if request.xhr?
40
  end
41
  
42
  def show
43
    @attachments = @document.attachments.find(:all, :order => "created_on DESC")
44
  end
45

  
46
  def new
47
    @document = @project.documents.build(params[:document])    
48
    if request.post? and @document.save	
49
      attach_files(@document, params[:attachments])
50
      flash[:notice] = l(:notice_successful_create)
51
      Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
52
      redirect_to :action => 'index', :project_id => @project
53
    end
54
  end
55
  
56
  def edit
57
    @categories = Enumeration::get_values('DCAT')
58
    if request.post? and @document.update_attributes(params[:document])
59
      flash[:notice] = l(:notice_successful_update)
60
      redirect_to :action => 'show', :id => @document
61
    end
62
  end  
63

  
64
  def destroy
65
    @document.destroy
66
    redirect_to :controller => 'documents', :action => 'index', :project_id => @project
67
  end
68

  
69
  def download
70
    @attachment = @document.attachments.find(params[:attachment_id])
71
    @attachment.increment_download
72
    send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
73
                                    :type => @attachment.content_type
74
  rescue
75
    render_404
76
  end 
77
  
78
  def add_attachment
79
    attachments = attach_files(@document, params[:attachments])
80
    Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('document_added')
81
    redirect_to :action => 'show', :id => @document
82
  end
83
  
84
  def destroy_attachment
85
    @document.attachments.find(params[:attachment_id]).destroy
86
    redirect_to :action => 'show', :id => @document
87
  end
88

  
89
private
90
  def find_project
91
    @project = Project.find(params[:project_id])
92
  rescue ActiveRecord::RecordNotFound
93
    render_404
94
  end
95

  
96
  def find_document
97
    @document = Document.find(params[:id])
98
    @project = @document.project
99
  rescue ActiveRecord::RecordNotFound
100
    render_404
101
  end
102
end
0 103

  
branches/work/git/app/controllers/enumerations_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006  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 EnumerationsController < ApplicationController
19
  layout 'base'
20
  before_filter :require_admin
21
  
22
  def index
23
    list
24
    render :action => 'list'
25
  end
26

  
27
  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
28
  verify :method => :post, :only => [ :destroy, :create, :update ],
29
         :redirect_to => { :action => :list }
30

  
31
  def list
32
  end
33

  
34
  def new
35
    @enumeration = Enumeration.new(:opt => params[:opt])
36
  end
37

  
38
  def create
39
    @enumeration = Enumeration.new(params[:enumeration])
40
    if @enumeration.save
41
      flash[:notice] = l(:notice_successful_create)
42
      redirect_to :action => 'list', :opt => @enumeration.opt
43
    else
44
      render :action => 'new'
45
    end
46
  end
47

  
48
  def edit
49
    @enumeration = Enumeration.find(params[:id])
50
  end
51

  
52
  def update
53
    @enumeration = Enumeration.find(params[:id])
54
    if @enumeration.update_attributes(params[:enumeration])
55
      flash[:notice] = l(:notice_successful_update)
56
      redirect_to :action => 'list', :opt => @enumeration.opt
57
    else
58
      render :action => 'edit'
59
    end
60
  end
61

  
62
  def move
63
    @enumeration = Enumeration.find(params[:id])
64
    case params[:position]
65
    when 'highest'
66
      @enumeration.move_to_top
67
    when 'higher'
68
      @enumeration.move_higher
69
    when 'lower'
70
      @enumeration.move_lower
71
    when 'lowest'
72
      @enumeration.move_to_bottom
73
    end if params[:position]
74
    redirect_to :action => 'index'
75
  end
76
  
77
  def destroy
78
    Enumeration.find(params[:id]).destroy
79
    flash[:notice] = l(:notice_successful_delete)
80
    redirect_to :action => 'list'
81
  rescue
82
    flash[:error] = "Unable to delete enumeration"
83
    redirect_to :action => 'list'
84
  end
85
end
0 86

  
branches/work/git/app/controllers/issue_categories_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006  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 IssueCategoriesController < ApplicationController
19
  layout 'base'
20
  menu_item :settings
21
  before_filter :find_project, :authorize
22
  
23
  verify :method => :post, :only => :destroy
24

  
25
  def edit
26
    if request.post? and @category.update_attributes(params[:category])
27
      flash[:notice] = l(:notice_successful_update)
28
      redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
29
    end
30
  end
31

  
32
  def destroy
33
    @issue_count = @category.issues.size
34
    if @issue_count == 0
35
      # No issue assigned to this category
36
      @category.destroy
37
      redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
38
    elsif params[:todo]
39
      reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign'
40
      @category.destroy(reassign_to)
41
      redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
42
    end
43
    @categories = @project.issue_categories - [@category]
44
  end
45

  
46
private
47
  def find_project
48
    @category = IssueCategory.find(params[:id])
49
    @project = @category.project
50
  rescue ActiveRecord::RecordNotFound
51
    render_404
52
  end    
53
end
0 54

  
branches/work/git/app/controllers/issue_relations_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2007  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 IssueRelationsController < ApplicationController
19
  layout 'base'
20
  before_filter :find_project, :authorize
21
  
22
  def new
23
    @relation = IssueRelation.new(params[:relation])
24
    @relation.issue_from = @issue
25
    @relation.save if request.post?
26
    respond_to do |format|
27
      format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
28
      format.js do
29
        render :update do |page|
30
          page.replace_html "relations", :partial => 'issues/relations'
31
          if @relation.errors.empty?
32
            page << "$('relation_delay').value = ''"
33
            page << "$('relation_issue_to_id').value = ''"
34
          end
35
        end
36
      end
37
    end
38
  end
39
  
40
  def destroy
41
    relation = IssueRelation.find(params[:id])
42
    if request.post? && @issue.relations.include?(relation)
43
      relation.destroy
44
      @issue.reload
45
    end
46
    respond_to do |format|
47
      format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
48
      format.js { render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} }
49
    end
50
  end
51
  
52
private
53
  def find_project
54
    @issue = Issue.find(params[:issue_id])
55
    @project = @issue.project
56
  rescue ActiveRecord::RecordNotFound
57
    render_404
58
  end
59
end
0 60

  
branches/work/git/app/controllers/issue_statuses_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006  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 IssueStatusesController < ApplicationController
19
  layout 'base'	
20
  before_filter :require_admin
21

  
22
  verify :method => :post, :only => [ :destroy, :create, :update, :move ],
23
         :redirect_to => { :action => :list }
24
         
25
  def index
26
    list
27
    render :action => 'list' unless request.xhr?
28
  end
29

  
30
  def list
31
    @issue_status_pages, @issue_statuses = paginate :issue_statuses, :per_page => 25, :order => "position"
32
    render :action => "list", :layout => false if request.xhr?
33
  end
34

  
35
  def new
36
    @issue_status = IssueStatus.new
37
  end
38

  
39
  def create
40
    @issue_status = IssueStatus.new(params[:issue_status])
41
    if @issue_status.save
42
      flash[:notice] = l(:notice_successful_create)
43
      redirect_to :action => 'list'
44
    else
45
      render :action => 'new'
46
    end
47
  end
48

  
49
  def edit
50
    @issue_status = IssueStatus.find(params[:id])
51
  end
52

  
53
  def update
54
    @issue_status = IssueStatus.find(params[:id])
55
    if @issue_status.update_attributes(params[:issue_status])
56
      flash[:notice] = l(:notice_successful_update)
57
      redirect_to :action => 'list'
58
    else
59
      render :action => 'edit'
60
    end
61
  end
62
  
63
  def move
64
    @issue_status = IssueStatus.find(params[:id])
65
    case params[:position]
66
    when 'highest'
67
      @issue_status.move_to_top
68
    when 'higher'
69
      @issue_status.move_higher
70
    when 'lower'
71
      @issue_status.move_lower
72
    when 'lowest'
73
      @issue_status.move_to_bottom
74
    end if params[:position]
75
    redirect_to :action => 'list'
76
  end
77

  
78
  def destroy
79
    IssueStatus.find(params[:id]).destroy
80
    redirect_to :action => 'list'
81
  rescue
82
    flash[:error] = "Unable to delete issue status"
83
    redirect_to :action => 'list'
84
  end  	
85
end
0 86

  
branches/work/git/app/controllers/issues_controller.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2007  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 IssuesController < ApplicationController
19
  layout 'base'
20
  menu_item :new_issue, :only => :new
21
  
22
  before_filter :find_issue, :only => [:show, :edit, :destroy_attachment]
23
  before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
24
  before_filter :find_project, :only => [:new, :update_form, :preview]
25
  before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu]
26
  before_filter :find_optional_project, :only => [:index, :changes]
27
  accept_key_auth :index, :changes
28

  
29
  helper :journals
30
  helper :projects
31
  include ProjectsHelper   
32
  helper :custom_fields
33
  include CustomFieldsHelper
34
  helper :ifpdf
35
  include IfpdfHelper
36
  helper :issue_relations
37
  include IssueRelationsHelper
38
  helper :watchers
39
  include WatchersHelper
40
  helper :attachments
41
  include AttachmentsHelper
42
  helper :queries
43
  helper :sort
44
  include SortHelper
45
  include IssuesHelper
46

  
47
  def index
48
    sort_init "#{Issue.table_name}.id", "desc"
49
    sort_update
50
    retrieve_query
51
    if @query.valid?
52
      limit = per_page_option
53
      respond_to do |format|
54
        format.html { }
55
        format.atom { }
56
        format.csv  { limit = Setting.issues_export_limit.to_i }
57
        format.pdf  { limit = Setting.issues_export_limit.to_i }
58
      end
59
      @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
60
      @issue_pages = Paginator.new self, @issue_count, limit, params['page']
61
      @issues = Issue.find :all, :order => sort_clause,
62
                           :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
63
                           :conditions => @query.statement,
64
                           :limit  =>  limit,
65
                           :offset =>  @issue_pages.current.offset
66
      respond_to do |format|
67
        format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
68
        format.atom { render_feed(@issues, :title => l(:label_issue_plural)) }
69
        format.csv  { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
70
        format.pdf  { send_data(render(:template => 'issues/index.rfpdf', :layout => false), :type => 'application/pdf', :filename => 'export.pdf') }
71
      end
72
    else
73
      # Send html if the query is not valid
74
      render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
75
    end
76
  end
77
  
78
  def changes
79
    sort_init "#{Issue.table_name}.id", "desc"
80
    sort_update
81
    retrieve_query
82
    if @query.valid?
83
      @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
84
                                     :conditions => @query.statement,
85
                                     :limit => 25,
86
                                     :order => "#{Journal.table_name}.created_on DESC"
87
    end
88
    @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
89
    render :layout => false, :content_type => 'application/atom+xml'
90
  end
91
  
92
  def show
93
    @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) }
94
    @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
95
    @journals.each_with_index {|j,i| j.indice = i+1}
96
    @journals.reverse! if User.current.wants_comments_in_reverse_order?
97
    @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
98
    @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
99
    @activities = Enumeration::get_values('ACTI')
100
    @priorities = Enumeration::get_values('IPRI')
101
    respond_to do |format|
102
      format.html { render :template => 'issues/show.rhtml' }
103
      format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
104
      format.pdf  { send_data(render(:template => 'issues/show.rfpdf', :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
105
    end
106
  end
107

  
108
  # Add a new issue
109
  # The new issue will be created from an existing one if copy_from parameter is given
110
  def new
111
    @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
112
    @issue.project = @project
113
    @issue.author = User.current
114
    @issue.tracker ||= @project.trackers.find(params[:tracker_id] ? params[:tracker_id] : :first)
115
    if @issue.tracker.nil?
116
      flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
117
      render :nothing => true, :layout => true
118
      return
119
    end
120
    
121
    default_status = IssueStatus.default
122
    unless default_status
123
      flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
124
      render :nothing => true, :layout => true
125
      return
126
    end    
127
    @issue.status = default_status
128
    @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker)).uniq
129
    
130
    if request.get? || request.xhr?
131
      @issue.start_date ||= Date.today
132
      @custom_values = @issue.custom_values.empty? ?
133
        @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
134
        @issue.custom_values
135
    else
136
      requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
137
      # Check that the user is allowed to apply the requested status
138
      @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
139
      @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
140
      @issue.custom_values = @custom_values
141
      if @issue.save
142
        attach_files(@issue, params[:attachments])
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff