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