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