Mercurial > hg > soundsoftware-site
comparison app/controllers/projects_controller.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 0c939c159af4 |
children | 5e80956cc792 5f33065ddc4b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 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 | 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. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 class ProjectsController < ApplicationController | 18 class ProjectsController < ApplicationController |
19 menu_item :overview | 19 menu_item :overview |
20 menu_item :roadmap, :only => :roadmap | 20 menu_item :roadmap, :only => :roadmap |
21 menu_item :settings, :only => :settings | 21 menu_item :settings, :only => :settings |
22 | 22 |
23 before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ] | 23 before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ] |
24 before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy] | 24 before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy] |
25 before_filter :authorize_global, :only => [:new, :create] | 25 before_filter :authorize_global, :only => [:new, :create] |
26 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] | 26 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] |
27 accept_rss_auth :index | 27 accept_rss_auth :index |
34 end | 34 end |
35 | 35 |
36 helper :sort | 36 helper :sort |
37 include SortHelper | 37 include SortHelper |
38 helper :custom_fields | 38 helper :custom_fields |
39 include CustomFieldsHelper | 39 include CustomFieldsHelper |
40 helper :issues | 40 helper :issues |
41 helper :queries | 41 helper :queries |
42 include QueriesHelper | 42 include QueriesHelper |
43 helper :repositories | 43 helper :repositories |
44 include RepositoriesHelper | 44 include RepositoriesHelper |
45 include ProjectsHelper | 45 include ProjectsHelper |
46 | 46 |
47 # Lists visible projects | 47 # Lists visible projects |
48 def index | 48 def index |
49 respond_to do |format| | 49 respond_to do |format| |
50 format.html { | 50 format.html { |
51 @projects = Project.visible.find(:all, :order => 'lft') | 51 @projects = Project.visible.find(:all, :order => 'lft') |
52 } | 52 } |
53 format.api { | 53 format.api { |
54 @offset, @limit = api_offset_and_limit | 54 @offset, @limit = api_offset_and_limit |
55 @project_count = Project.visible.count | 55 @project_count = Project.visible.count |
56 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft') | 56 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft') |
60 :limit => Setting.feeds_limit.to_i) | 60 :limit => Setting.feeds_limit.to_i) |
61 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") | 61 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") |
62 } | 62 } |
63 end | 63 end |
64 end | 64 end |
65 | 65 |
66 def new | 66 def new |
67 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 67 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
68 @trackers = Tracker.all | 68 @trackers = Tracker.all |
69 @project = Project.new(params[:project]) | 69 @project = Project.new(params[:project]) |
70 end | 70 end |
83 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first | 83 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first |
84 m = Member.new(:user => User.current, :roles => [r]) | 84 m = Member.new(:user => User.current, :roles => [r]) |
85 @project.members << m | 85 @project.members << m |
86 end | 86 end |
87 respond_to do |format| | 87 respond_to do |format| |
88 format.html { | 88 format.html { |
89 flash[:notice] = l(:notice_successful_create) | 89 flash[:notice] = l(:notice_successful_create) |
90 redirect_to :controller => 'projects', :action => 'settings', :id => @project | 90 redirect_to(params[:continue] ? |
91 {:controller => 'projects', :action => 'new', :project => {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}} : | |
92 {:controller => 'projects', :action => 'settings', :id => @project} | |
93 ) | |
91 } | 94 } |
92 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } | 95 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } |
93 end | 96 end |
94 else | 97 else |
95 respond_to do |format| | 98 respond_to do |format| |
96 format.html { render :action => 'new' } | 99 format.html { render :action => 'new' } |
97 format.api { render_validation_errors(@project) } | 100 format.api { render_validation_errors(@project) } |
98 end | 101 end |
99 end | 102 end |
100 | 103 |
101 end | 104 end |
102 | 105 |
103 def copy | 106 def copy |
104 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 107 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
105 @trackers = Tracker.all | 108 @trackers = Tracker.all |
106 @root_projects = Project.find(:all, | 109 @root_projects = Project.find(:all, |
107 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", | 110 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", |
111 @project = Project.copy_from(@source_project) | 114 @project = Project.copy_from(@source_project) |
112 if @project | 115 if @project |
113 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? | 116 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? |
114 else | 117 else |
115 redirect_to :controller => 'admin', :action => 'projects' | 118 redirect_to :controller => 'admin', :action => 'projects' |
116 end | 119 end |
117 else | 120 else |
118 Mailer.with_deliveries(params[:notifications] == '1') do | 121 Mailer.with_deliveries(params[:notifications] == '1') do |
119 @project = Project.new | 122 @project = Project.new |
120 @project.safe_attributes = params[:project] | 123 @project.safe_attributes = params[:project] |
121 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) | 124 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) |
139 def show | 142 def show |
140 if params[:jump] | 143 if params[:jump] |
141 # try to redirect to the requested menu item | 144 # try to redirect to the requested menu item |
142 redirect_to_project_menu_item(@project, params[:jump]) && return | 145 redirect_to_project_menu_item(@project, params[:jump]) && return |
143 end | 146 end |
144 | 147 |
145 @users_by_role = @project.users_by_role | 148 @users_by_role = @project.users_by_role |
146 @subprojects = @project.children.visible.all | 149 @subprojects = @project.children.visible.all |
147 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | 150 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
148 @trackers = @project.rolled_up_trackers | 151 @trackers = @project.rolled_up_trackers |
149 | 152 |
150 cond = @project.project_condition(Setting.display_subprojects_issues?) | 153 cond = @project.project_condition(Setting.display_subprojects_issues?) |
151 | 154 |
152 @open_issues_by_tracker = Issue.visible.count(:group => :tracker, | 155 @open_issues_by_tracker = Issue.visible.count(:group => :tracker, |
153 :include => [:project, :status, :tracker], | 156 :include => [:project, :status, :tracker], |
154 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) | 157 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) |
155 @total_issues_by_tracker = Issue.visible.count(:group => :tracker, | 158 @total_issues_by_tracker = Issue.visible.count(:group => :tracker, |
156 :include => [:project, :status, :tracker], | 159 :include => [:project, :status, :tracker], |
157 :conditions => cond) | 160 :conditions => cond) |
158 | 161 |
159 if User.current.allowed_to?(:view_time_entries, @project) | 162 if User.current.allowed_to?(:view_time_entries, @project) |
160 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f | 163 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f |
161 end | 164 end |
162 | 165 |
163 @key = User.current.rss_key | 166 @key = User.current.rss_key |
164 | 167 |
165 respond_to do |format| | 168 respond_to do |format| |
166 format.html | 169 format.html |
167 format.api | 170 format.api |
168 end | 171 end |
169 end | 172 end |
174 @member ||= @project.members.new | 177 @member ||= @project.members.new |
175 @trackers = Tracker.all | 178 @trackers = Tracker.all |
176 @repository ||= @project.repository | 179 @repository ||= @project.repository |
177 @wiki ||= @project.wiki | 180 @wiki ||= @project.wiki |
178 end | 181 end |
179 | 182 |
180 def edit | 183 def edit |
181 end | 184 end |
182 | 185 |
183 # TODO: convert to PUT only | 186 # TODO: convert to PUT only |
184 verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | 187 verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
185 def update | 188 def update |
186 @project.safe_attributes = params[:project] | 189 @project.safe_attributes = params[:project] |
187 if validate_parent_id && @project.save | 190 if validate_parent_id && @project.save |
188 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | 191 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
189 respond_to do |format| | 192 respond_to do |format| |
190 format.html { | 193 format.html { |
191 flash[:notice] = l(:notice_successful_update) | 194 flash[:notice] = l(:notice_successful_update) |
192 redirect_to :action => 'settings', :id => @project | 195 redirect_to :action => 'settings', :id => @project |
193 } | 196 } |
194 format.api { head :ok } | 197 format.api { head :ok } |
195 end | 198 end |
196 else | 199 else |
197 respond_to do |format| | 200 respond_to do |format| |
198 format.html { | 201 format.html { |
199 settings | 202 settings |
200 render :action => 'settings' | 203 render :action => 'settings' |
201 } | 204 } |
202 format.api { render_validation_errors(@project) } | 205 format.api { render_validation_errors(@project) } |
203 end | 206 end |
217 flash[:error] = l(:error_can_not_archive_project) | 220 flash[:error] = l(:error_can_not_archive_project) |
218 end | 221 end |
219 end | 222 end |
220 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) | 223 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) |
221 end | 224 end |
222 | 225 |
223 def unarchive | 226 def unarchive |
224 @project.unarchive if request.post? && !@project.active? | 227 @project.unarchive if request.post? && !@project.active? |
225 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) | 228 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) |
226 end | 229 end |
227 | 230 |
228 # Delete @project | 231 # Delete @project |
229 def destroy | 232 def destroy |
230 @project_to_destroy = @project | 233 @project_to_destroy = @project |
231 if request.get? | 234 if request.get? |
232 # display confirmation view | 235 # display confirmation view |