Mercurial > hg > soundsoftware-site
comparison app/controllers/projects_controller.rb @ 117:af80e5618e9b redmine-1.1
* Update to Redmine 1.1-stable branch (Redmine SVN rev 4707)
author | Chris Cannam |
---|---|
date | Thu, 13 Jan 2011 12:53:21 +0000 |
parents | 94944d00e43c |
children | 605adf7e1735 cbce1fd3b1b7 |
comparison
equal
deleted
inserted
replaced
39:150ceac17a8d | 117:af80e5618e9b |
---|---|
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_key_auth :index | 27 accept_key_auth :index, :show, :create, :update, :destroy |
28 | 28 |
29 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller| | 29 after_filter :only => [:create, :edit, :update, :archive, :unarchive, :destroy] do |controller| |
30 if controller.request.post? | 30 if controller.request.post? |
31 controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt' | 31 controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt' |
32 end | 32 end |
33 end | 33 end |
34 | |
35 # TODO: convert to PUT only | |
36 verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
37 | 34 |
38 helper :sort | 35 helper :sort |
39 include SortHelper | 36 include SortHelper |
40 helper :custom_fields | 37 helper :custom_fields |
41 include CustomFieldsHelper | 38 include CustomFieldsHelper |
50 def index | 47 def index |
51 respond_to do |format| | 48 respond_to do |format| |
52 format.html { | 49 format.html { |
53 @projects = Project.visible.find(:all, :order => 'lft') | 50 @projects = Project.visible.find(:all, :order => 'lft') |
54 } | 51 } |
55 format.xml { | 52 format.api { |
56 @projects = Project.visible.find(:all, :order => 'lft') | 53 @offset, @limit = api_offset_and_limit |
54 @project_count = Project.visible.count | |
55 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft') | |
57 } | 56 } |
58 format.atom { | 57 format.atom { |
59 projects = Project.visible.find(:all, :order => 'created_on DESC', | 58 projects = Project.visible.find(:all, :order => 'created_on DESC', |
60 :limit => Setting.feeds_limit.to_i) | 59 :limit => Setting.feeds_limit.to_i) |
61 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") | 60 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") |
65 | 64 |
66 def new | 65 def new |
67 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 66 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
68 @trackers = Tracker.all | 67 @trackers = Tracker.all |
69 @project = Project.new(params[:project]) | 68 @project = Project.new(params[:project]) |
70 | 69 end |
71 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? | 70 |
72 @project.trackers = Tracker.all | 71 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
73 @project.is_public = Setting.default_projects_public? | |
74 @project.enabled_module_names = Setting.default_projects_modules | |
75 end | |
76 | |
77 def create | 72 def create |
78 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 73 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
79 @trackers = Tracker.all | 74 @trackers = Tracker.all |
80 @project = Project.new(params[:project]) | 75 @project = Project.new |
81 | 76 @project.safe_attributes = params[:project] |
82 @project.enabled_module_names = params[:enabled_modules] | 77 |
83 if validate_parent_id && @project.save | 78 if validate_parent_id && @project.save |
84 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | 79 @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 | 80 # Add current user as a project member if he is not admin |
86 unless User.current.admin? | 81 unless User.current.admin? |
87 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first | 82 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first |
91 respond_to do |format| | 86 respond_to do |format| |
92 format.html { | 87 format.html { |
93 flash[:notice] = l(:notice_successful_create) | 88 flash[:notice] = l(:notice_successful_create) |
94 redirect_to :controller => 'projects', :action => 'settings', :id => @project | 89 redirect_to :controller => 'projects', :action => 'settings', :id => @project |
95 } | 90 } |
96 format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } | 91 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } |
97 end | 92 end |
98 else | 93 else |
99 respond_to do |format| | 94 respond_to do |format| |
100 format.html { render :action => 'new' } | 95 format.html { render :action => 'new' } |
101 format.xml { render :xml => @project.errors, :status => :unprocessable_entity } | 96 format.api { render_validation_errors(@project) } |
102 end | 97 end |
103 end | 98 end |
104 | 99 |
105 end | 100 end |
106 | 101 |
118 else | 113 else |
119 redirect_to :controller => 'admin', :action => 'projects' | 114 redirect_to :controller => 'admin', :action => 'projects' |
120 end | 115 end |
121 else | 116 else |
122 Mailer.with_deliveries(params[:notifications] == '1') do | 117 Mailer.with_deliveries(params[:notifications] == '1') do |
123 @project = Project.new(params[:project]) | 118 @project = Project.new |
119 @project.safe_attributes = params[:project] | |
124 @project.enabled_module_names = params[:enabled_modules] | 120 @project.enabled_module_names = params[:enabled_modules] |
125 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) | 121 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) |
126 @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') |
127 flash[:notice] = l(:notice_successful_create) | 123 flash[:notice] = l(:notice_successful_create) |
128 redirect_to :controller => 'projects', :action => 'settings' | 124 redirect_to :controller => 'projects', :action => 'settings', :id => @project |
129 elsif !@project.new_record? | 125 elsif !@project.new_record? |
130 # Project was created | 126 # Project was created |
131 # But some objects were not copied due to validation failures | 127 # But some objects were not copied due to validation failures |
132 # (eg. issues from disabled trackers) | 128 # (eg. issues from disabled trackers) |
133 # TODO: inform about that | 129 # TODO: inform about that |
134 redirect_to :controller => 'projects', :action => 'settings' | 130 redirect_to :controller => 'projects', :action => 'settings', :id => @project |
135 end | 131 end |
136 end | 132 end |
137 end | 133 end |
138 rescue ActiveRecord::RecordNotFound | 134 rescue ActiveRecord::RecordNotFound |
139 redirect_to :controller => 'admin', :action => 'projects' | 135 redirect_to :controller => 'admin', :action => 'projects' |
167 end | 163 end |
168 @key = User.current.rss_key | 164 @key = User.current.rss_key |
169 | 165 |
170 respond_to do |format| | 166 respond_to do |format| |
171 format.html | 167 format.html |
172 format.xml | 168 format.api |
173 end | 169 end |
174 end | 170 end |
175 | 171 |
176 def settings | 172 def settings |
177 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 173 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
183 end | 179 end |
184 | 180 |
185 def edit | 181 def edit |
186 end | 182 end |
187 | 183 |
184 # TODO: convert to PUT only | |
185 verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
188 def update | 186 def update |
189 @project.attributes = params[:project] | 187 @project.safe_attributes = params[:project] |
190 if validate_parent_id && @project.save | 188 if validate_parent_id && @project.save |
191 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | 189 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
192 respond_to do |format| | 190 respond_to do |format| |
193 format.html { | 191 format.html { |
194 flash[:notice] = l(:notice_successful_update) | 192 flash[:notice] = l(:notice_successful_update) |
195 redirect_to :action => 'settings', :id => @project | 193 redirect_to :action => 'settings', :id => @project |
196 } | 194 } |
197 format.xml { head :ok } | 195 format.api { head :ok } |
198 end | 196 end |
199 else | 197 else |
200 respond_to do |format| | 198 respond_to do |format| |
201 format.html { | 199 format.html { |
202 settings | 200 settings |
203 render :action => 'settings' | 201 render :action => 'settings' |
204 } | 202 } |
205 format.xml { render :xml => @project.errors, :status => :unprocessable_entity } | 203 format.api { render_validation_errors(@project) } |
206 end | 204 end |
207 end | 205 end |
208 end | 206 end |
209 | 207 |
208 verify :method => :post, :only => :modules, :render => {:nothing => true, :status => :method_not_allowed } | |
210 def modules | 209 def modules |
211 @project.enabled_module_names = params[:enabled_modules] | 210 @project.enabled_module_names = params[:enabled_module_names] |
212 flash[:notice] = l(:notice_successful_update) | 211 flash[:notice] = l(:notice_successful_update) |
213 redirect_to :action => 'settings', :id => @project, :tab => 'modules' | 212 redirect_to :action => 'settings', :id => @project, :tab => 'modules' |
214 end | 213 end |
215 | 214 |
216 def archive | 215 def archive |
231 def destroy | 230 def destroy |
232 @project_to_destroy = @project | 231 @project_to_destroy = @project |
233 if request.get? | 232 if request.get? |
234 # display confirmation view | 233 # display confirmation view |
235 else | 234 else |
236 if params[:format] == 'xml' || params[:confirm] | 235 if api_request? || params[:confirm] |
237 @project_to_destroy.destroy | 236 @project_to_destroy.destroy |
238 respond_to do |format| | 237 respond_to do |format| |
239 format.html { redirect_to :controller => 'admin', :action => 'projects' } | 238 format.html { redirect_to :controller => 'admin', :action => 'projects' } |
240 format.xml { head :ok } | 239 format.api { head :ok } |
241 end | 240 end |
242 end | 241 end |
243 end | 242 end |
244 # hide project in layout | 243 # hide project in layout |
245 @project = nil | 244 @project = nil |