Mercurial > hg > soundsoftware-site
comparison .svn/pristine/9c/9c29f1b6dc547473ab1c34c645fabf4dd7aa8716.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 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 ProjectsController < ApplicationController | |
19 menu_item :overview | |
20 menu_item :roadmap, :only => :roadmap | |
21 menu_item :settings, :only => :settings | |
22 | |
23 before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ] | |
24 before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy] | |
25 before_filter :authorize_global, :only => [:new, :create] | |
26 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] | |
27 accept_rss_auth :index | |
28 accept_api_auth :index, :show, :create, :update, :destroy | |
29 | |
30 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller| | |
31 if controller.request.post? | |
32 controller.send :expire_action, :controller => 'welcome', :action => 'robots' | |
33 end | |
34 end | |
35 | |
36 helper :sort | |
37 include SortHelper | |
38 helper :custom_fields | |
39 include CustomFieldsHelper | |
40 helper :issues | |
41 helper :queries | |
42 include QueriesHelper | |
43 helper :repositories | |
44 include RepositoriesHelper | |
45 include ProjectsHelper | |
46 helper :members | |
47 | |
48 # Lists visible projects | |
49 def index | |
50 respond_to do |format| | |
51 format.html { | |
52 scope = Project | |
53 unless params[:closed] | |
54 scope = scope.active | |
55 end | |
56 @projects = scope.visible.order('lft').all | |
57 } | |
58 format.api { | |
59 @offset, @limit = api_offset_and_limit | |
60 @project_count = Project.visible.count | |
61 @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all | |
62 } | |
63 format.atom { | |
64 projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all | |
65 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") | |
66 } | |
67 end | |
68 end | |
69 | |
70 def new | |
71 @issue_custom_fields = IssueCustomField.sorted.all | |
72 @trackers = Tracker.sorted.all | |
73 @project = Project.new | |
74 @project.safe_attributes = params[:project] | |
75 end | |
76 | |
77 def create | |
78 @issue_custom_fields = IssueCustomField.sorted.all | |
79 @trackers = Tracker.sorted.all | |
80 @project = Project.new | |
81 @project.safe_attributes = params[:project] | |
82 | |
83 if validate_parent_id && @project.save | |
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 | |
86 unless User.current.admin? | |
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]) | |
89 @project.members << m | |
90 end | |
91 respond_to do |format| | |
92 format.html { | |
93 flash[:notice] = l(:notice_successful_create) | |
94 if params[:continue] | |
95 attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} | |
96 redirect_to new_project_path(attrs) | |
97 else | |
98 redirect_to settings_project_path(@project) | |
99 end | |
100 } | |
101 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } | |
102 end | |
103 else | |
104 respond_to do |format| | |
105 format.html { render :action => 'new' } | |
106 format.api { render_validation_errors(@project) } | |
107 end | |
108 end | |
109 end | |
110 | |
111 def copy | |
112 @issue_custom_fields = IssueCustomField.sorted.all | |
113 @trackers = Tracker.sorted.all | |
114 @source_project = Project.find(params[:id]) | |
115 if request.get? | |
116 @project = Project.copy_from(@source_project) | |
117 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? | |
118 else | |
119 Mailer.with_deliveries(params[:notifications] == '1') do | |
120 @project = Project.new | |
121 @project.safe_attributes = params[:project] | |
122 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') | |
124 flash[:notice] = l(:notice_successful_create) | |
125 redirect_to settings_project_path(@project) | |
126 elsif !@project.new_record? | |
127 # Project was created | |
128 # But some objects were not copied due to validation failures | |
129 # (eg. issues from disabled trackers) | |
130 # TODO: inform about that | |
131 redirect_to settings_project_path(@project) | |
132 end | |
133 end | |
134 end | |
135 rescue ActiveRecord::RecordNotFound | |
136 # source_project not found | |
137 render_404 | |
138 end | |
139 | |
140 # Show @project | |
141 def show | |
142 # try to redirect to the requested menu item | |
143 if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) | |
144 return | |
145 end | |
146 | |
147 @users_by_role = @project.users_by_role | |
148 @subprojects = @project.children.visible.all | |
149 @news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").all | |
150 @trackers = @project.rolled_up_trackers | |
151 | |
152 cond = @project.project_condition(Setting.display_subprojects_issues?) | |
153 | |
154 @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker) | |
155 @total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker) | |
156 | |
157 if User.current.allowed_to?(:view_time_entries, @project) | |
158 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f | |
159 end | |
160 | |
161 @key = User.current.rss_key | |
162 | |
163 respond_to do |format| | |
164 format.html | |
165 format.api | |
166 end | |
167 end | |
168 | |
169 def settings | |
170 @issue_custom_fields = IssueCustomField.sorted.all | |
171 @issue_category ||= IssueCategory.new | |
172 @member ||= @project.members.new | |
173 @trackers = Tracker.sorted.all | |
174 @wiki ||= @project.wiki | |
175 end | |
176 | |
177 def edit | |
178 end | |
179 | |
180 def update | |
181 @project.safe_attributes = params[:project] | |
182 if validate_parent_id && @project.save | |
183 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | |
184 respond_to do |format| | |
185 format.html { | |
186 flash[:notice] = l(:notice_successful_update) | |
187 redirect_to settings_project_path(@project) | |
188 } | |
189 format.api { render_api_ok } | |
190 end | |
191 else | |
192 respond_to do |format| | |
193 format.html { | |
194 settings | |
195 render :action => 'settings' | |
196 } | |
197 format.api { render_validation_errors(@project) } | |
198 end | |
199 end | |
200 end | |
201 | |
202 def modules | |
203 @project.enabled_module_names = params[:enabled_module_names] | |
204 flash[:notice] = l(:notice_successful_update) | |
205 redirect_to settings_project_path(@project, :tab => 'modules') | |
206 end | |
207 | |
208 def archive | |
209 if request.post? | |
210 unless @project.archive | |
211 flash[:error] = l(:error_can_not_archive_project) | |
212 end | |
213 end | |
214 redirect_to admin_projects_path(:status => params[:status]) | |
215 end | |
216 | |
217 def unarchive | |
218 @project.unarchive if request.post? && !@project.active? | |
219 redirect_to admin_projects_path(:status => params[:status]) | |
220 end | |
221 | |
222 def close | |
223 @project.close | |
224 redirect_to project_path(@project) | |
225 end | |
226 | |
227 def reopen | |
228 @project.reopen | |
229 redirect_to project_path(@project) | |
230 end | |
231 | |
232 # Delete @project | |
233 def destroy | |
234 @project_to_destroy = @project | |
235 if api_request? || params[:confirm] | |
236 @project_to_destroy.destroy | |
237 respond_to do |format| | |
238 format.html { redirect_to admin_projects_path } | |
239 format.api { render_api_ok } | |
240 end | |
241 end | |
242 # hide project in layout | |
243 @project = nil | |
244 end | |
245 | |
246 private | |
247 | |
248 # Validates parent_id param according to user's permissions | |
249 # TODO: move it to Project model in a validation that depends on User.current | |
250 def validate_parent_id | |
251 return true if User.current.admin? | |
252 parent_id = params[:project] && params[:project][:parent_id] | |
253 if parent_id || @project.new_record? | |
254 parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i) | |
255 unless @project.allowed_parents.include?(parent) | |
256 @project.errors.add :parent_id, :invalid | |
257 return false | |
258 end | |
259 end | |
260 true | |
261 end | |
262 end |