##// END OF EJS Templates
Removed unused instance variable....
Jean-Philippe Lang -
r10686:1951c6a3fdc0
parent child
Show More
@@ -1,264 +1,261
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
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
28 accept_api_auth :index, :show, :create, :update, :destroy
28 accept_api_auth :index, :show, :create, :update, :destroy
29
29
30 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
30 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller|
31 if controller.request.post?
31 if controller.request.post?
32 controller.send :expire_action, :controller => 'welcome', :action => 'robots'
32 controller.send :expire_action, :controller => 'welcome', :action => 'robots'
33 end
33 end
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 scope = Project
51 scope = Project
52 unless params[:closed]
52 unless params[:closed]
53 scope = scope.active
53 scope = scope.active
54 end
54 end
55 @projects = scope.visible.order('lft').all
55 @projects = scope.visible.order('lft').all
56 }
56 }
57 format.api {
57 format.api {
58 @offset, @limit = api_offset_and_limit
58 @offset, @limit = api_offset_and_limit
59 @project_count = Project.visible.count
59 @project_count = Project.visible.count
60 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft')
60 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft')
61 }
61 }
62 format.atom {
62 format.atom {
63 projects = Project.visible.find(:all, :order => 'created_on DESC',
63 projects = Project.visible.find(:all, :order => 'created_on DESC',
64 :limit => Setting.feeds_limit.to_i)
64 :limit => Setting.feeds_limit.to_i)
65 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
65 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
66 }
66 }
67 end
67 end
68 end
68 end
69
69
70 def new
70 def new
71 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
71 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
72 @trackers = Tracker.sorted.all
72 @trackers = Tracker.sorted.all
73 @project = Project.new
73 @project = Project.new
74 @project.safe_attributes = params[:project]
74 @project.safe_attributes = params[:project]
75 end
75 end
76
76
77 def create
77 def create
78 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
78 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
79 @trackers = Tracker.sorted.all
79 @trackers = Tracker.sorted.all
80 @project = Project.new
80 @project = Project.new
81 @project.safe_attributes = params[:project]
81 @project.safe_attributes = params[:project]
82
82
83 if validate_parent_id && @project.save
83 if validate_parent_id && @project.save
84 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
84 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
85 # Add current user as a project member if he is not admin
85 # Add current user as a project member if he is not admin
86 unless User.current.admin?
86 unless User.current.admin?
87 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
87 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
88 m = Member.new(:user => User.current, :roles => [r])
88 m = Member.new(:user => User.current, :roles => [r])
89 @project.members << m
89 @project.members << m
90 end
90 end
91 respond_to do |format|
91 respond_to do |format|
92 format.html {
92 format.html {
93 flash[:notice] = l(:notice_successful_create)
93 flash[:notice] = l(:notice_successful_create)
94 redirect_to(params[:continue] ?
94 redirect_to(params[:continue] ?
95 {:controller => 'projects', :action => 'new', :project => {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}} :
95 {:controller => 'projects', :action => 'new', :project => {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}} :
96 {:controller => 'projects', :action => 'settings', :id => @project}
96 {:controller => 'projects', :action => 'settings', :id => @project}
97 )
97 )
98 }
98 }
99 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
99 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
100 end
100 end
101 else
101 else
102 respond_to do |format|
102 respond_to do |format|
103 format.html { render :action => 'new' }
103 format.html { render :action => 'new' }
104 format.api { render_validation_errors(@project) }
104 format.api { render_validation_errors(@project) }
105 end
105 end
106 end
106 end
107
107
108 end
108 end
109
109
110 def copy
110 def copy
111 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
111 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
112 @trackers = Tracker.sorted.all
112 @trackers = Tracker.sorted.all
113 @root_projects = Project.find(:all,
114 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
115 :order => 'name')
116 @source_project = Project.find(params[:id])
113 @source_project = Project.find(params[:id])
117 if request.get?
114 if request.get?
118 @project = Project.copy_from(@source_project)
115 @project = Project.copy_from(@source_project)
119 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
116 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
120 else
117 else
121 Mailer.with_deliveries(params[:notifications] == '1') do
118 Mailer.with_deliveries(params[:notifications] == '1') do
122 @project = Project.new
119 @project = Project.new
123 @project.safe_attributes = params[:project]
120 @project.safe_attributes = params[:project]
124 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
121 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
125 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
122 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
126 flash[:notice] = l(:notice_successful_create)
123 flash[:notice] = l(:notice_successful_create)
127 redirect_to :controller => 'projects', :action => 'settings', :id => @project
124 redirect_to :controller => 'projects', :action => 'settings', :id => @project
128 elsif !@project.new_record?
125 elsif !@project.new_record?
129 # Project was created
126 # Project was created
130 # But some objects were not copied due to validation failures
127 # But some objects were not copied due to validation failures
131 # (eg. issues from disabled trackers)
128 # (eg. issues from disabled trackers)
132 # TODO: inform about that
129 # TODO: inform about that
133 redirect_to :controller => 'projects', :action => 'settings', :id => @project
130 redirect_to :controller => 'projects', :action => 'settings', :id => @project
134 end
131 end
135 end
132 end
136 end
133 end
137 rescue ActiveRecord::RecordNotFound
134 rescue ActiveRecord::RecordNotFound
138 # source_project not found
135 # source_project not found
139 render_404
136 render_404
140 end
137 end
141
138
142 # Show @project
139 # Show @project
143 def show
140 def show
144 if params[:jump]
141 if params[:jump]
145 # try to redirect to the requested menu item
142 # try to redirect to the requested menu item
146 redirect_to_project_menu_item(@project, params[:jump]) && return
143 redirect_to_project_menu_item(@project, params[:jump]) && return
147 end
144 end
148
145
149 @users_by_role = @project.users_by_role
146 @users_by_role = @project.users_by_role
150 @subprojects = @project.children.visible.all
147 @subprojects = @project.children.visible.all
151 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
148 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
152 @trackers = @project.rolled_up_trackers
149 @trackers = @project.rolled_up_trackers
153
150
154 cond = @project.project_condition(Setting.display_subprojects_issues?)
151 cond = @project.project_condition(Setting.display_subprojects_issues?)
155
152
156 @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker)
153 @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker)
157 @total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker)
154 @total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker)
158
155
159 if User.current.allowed_to?(:view_time_entries, @project)
156 if User.current.allowed_to?(:view_time_entries, @project)
160 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
157 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
161 end
158 end
162
159
163 @key = User.current.rss_key
160 @key = User.current.rss_key
164
161
165 respond_to do |format|
162 respond_to do |format|
166 format.html
163 format.html
167 format.api
164 format.api
168 end
165 end
169 end
166 end
170
167
171 def settings
168 def settings
172 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
169 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
173 @issue_category ||= IssueCategory.new
170 @issue_category ||= IssueCategory.new
174 @member ||= @project.members.new
171 @member ||= @project.members.new
175 @trackers = Tracker.sorted.all
172 @trackers = Tracker.sorted.all
176 @wiki ||= @project.wiki
173 @wiki ||= @project.wiki
177 end
174 end
178
175
179 def edit
176 def edit
180 end
177 end
181
178
182 def update
179 def update
183 @project.safe_attributes = params[:project]
180 @project.safe_attributes = params[:project]
184 if validate_parent_id && @project.save
181 if validate_parent_id && @project.save
185 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
182 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
186 respond_to do |format|
183 respond_to do |format|
187 format.html {
184 format.html {
188 flash[:notice] = l(:notice_successful_update)
185 flash[:notice] = l(:notice_successful_update)
189 redirect_to :action => 'settings', :id => @project
186 redirect_to :action => 'settings', :id => @project
190 }
187 }
191 format.api { render_api_ok }
188 format.api { render_api_ok }
192 end
189 end
193 else
190 else
194 respond_to do |format|
191 respond_to do |format|
195 format.html {
192 format.html {
196 settings
193 settings
197 render :action => 'settings'
194 render :action => 'settings'
198 }
195 }
199 format.api { render_validation_errors(@project) }
196 format.api { render_validation_errors(@project) }
200 end
197 end
201 end
198 end
202 end
199 end
203
200
204 def modules
201 def modules
205 @project.enabled_module_names = params[:enabled_module_names]
202 @project.enabled_module_names = params[:enabled_module_names]
206 flash[:notice] = l(:notice_successful_update)
203 flash[:notice] = l(:notice_successful_update)
207 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
204 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
208 end
205 end
209
206
210 def archive
207 def archive
211 if request.post?
208 if request.post?
212 unless @project.archive
209 unless @project.archive
213 flash[:error] = l(:error_can_not_archive_project)
210 flash[:error] = l(:error_can_not_archive_project)
214 end
211 end
215 end
212 end
216 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
213 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
217 end
214 end
218
215
219 def unarchive
216 def unarchive
220 @project.unarchive if request.post? && !@project.active?
217 @project.unarchive if request.post? && !@project.active?
221 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
218 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
222 end
219 end
223
220
224 def close
221 def close
225 @project.close
222 @project.close
226 redirect_to project_path(@project)
223 redirect_to project_path(@project)
227 end
224 end
228
225
229 def reopen
226 def reopen
230 @project.reopen
227 @project.reopen
231 redirect_to project_path(@project)
228 redirect_to project_path(@project)
232 end
229 end
233
230
234 # Delete @project
231 # Delete @project
235 def destroy
232 def destroy
236 @project_to_destroy = @project
233 @project_to_destroy = @project
237 if api_request? || params[:confirm]
234 if api_request? || params[:confirm]
238 @project_to_destroy.destroy
235 @project_to_destroy.destroy
239 respond_to do |format|
236 respond_to do |format|
240 format.html { redirect_to :controller => 'admin', :action => 'projects' }
237 format.html { redirect_to :controller => 'admin', :action => 'projects' }
241 format.api { render_api_ok }
238 format.api { render_api_ok }
242 end
239 end
243 end
240 end
244 # hide project in layout
241 # hide project in layout
245 @project = nil
242 @project = nil
246 end
243 end
247
244
248 private
245 private
249
246
250 # Validates parent_id param according to user's permissions
247 # Validates parent_id param according to user's permissions
251 # TODO: move it to Project model in a validation that depends on User.current
248 # TODO: move it to Project model in a validation that depends on User.current
252 def validate_parent_id
249 def validate_parent_id
253 return true if User.current.admin?
250 return true if User.current.admin?
254 parent_id = params[:project] && params[:project][:parent_id]
251 parent_id = params[:project] && params[:project][:parent_id]
255 if parent_id || @project.new_record?
252 if parent_id || @project.new_record?
256 parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
253 parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
257 unless @project.allowed_parents.include?(parent)
254 unless @project.allowed_parents.include?(parent)
258 @project.errors.add :parent_id, :invalid
255 @project.errors.add :parent_id, :invalid
259 return false
256 return false
260 end
257 end
261 end
258 end
262 true
259 true
263 end
260 end
264 end
261 end
General Comments 0
You need to be logged in to leave comments. Login now