@@ -20,13 +20,13 class ProjectsController < ApplicationController | |||
|
20 | 20 | menu_item :roadmap, :only => :roadmap |
|
21 | 21 | menu_item :settings, :only => :settings |
|
22 | 22 | |
|
23 | before_filter :find_project, :except => [ :index, :list, :add, :copy ] | |
|
24 | before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy] | |
|
25 | before_filter :authorize_global, :only => :add | |
|
23 | before_filter :find_project, :except => [ :index, :list, :add, :create, :copy ] | |
|
24 | before_filter :authorize, :except => [ :index, :list, :add, :create, :copy, :archive, :unarchive, :destroy] | |
|
25 | before_filter :authorize_global, :only => [:add, :create] | |
|
26 | 26 | before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] |
|
27 | 27 | accept_key_auth :index |
|
28 | 28 | |
|
29 |
after_filter :only => [: |
|
|
29 | after_filter :only => [:create, :edit, :archive, :unarchive, :destroy] do |controller| | |
|
30 | 30 | if controller.request.post? |
|
31 | 31 | controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt' |
|
32 | 32 | end |
@@ -65,35 +65,41 class ProjectsController < ApplicationController | |||
|
65 | 65 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
66 | 66 | @trackers = Tracker.all |
|
67 | 67 | @project = Project.new(params[:project]) |
|
68 | if request.get? | |
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
68 | ||
|
69 | @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? | |
|
70 | @project.trackers = Tracker.all | |
|
71 | @project.is_public = Setting.default_projects_public? | |
|
72 | @project.enabled_module_names = Setting.default_projects_modules | |
|
73 | end | |
|
74 | ||
|
75 | def create | |
|
76 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
|
77 | @trackers = Tracker.all | |
|
78 | @project = Project.new(params[:project]) | |
|
79 | ||
|
80 | @project.enabled_module_names = params[:enabled_modules] | |
|
81 | if validate_parent_id && @project.save | |
|
82 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | |
|
83 | # Add current user as a project member if he is not admin | |
|
84 | unless User.current.admin? | |
|
85 | r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first | |
|
86 | m = Member.new(:user => User.current, :roles => [r]) | |
|
87 | @project.members << m | |
|
88 | end | |
|
89 | respond_to do |format| | |
|
90 | format.html { | |
|
91 | flash[:notice] = l(:notice_successful_create) | |
|
92 | redirect_to :controller => 'projects', :action => 'settings', :id => @project | |
|
93 | } | |
|
94 | format.xml { head :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } | |
|
95 | end | |
|
73 | 96 | else |
|
74 | @project.enabled_module_names = params[:enabled_modules] | |
|
75 | if validate_parent_id && @project.save | |
|
76 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | |
|
77 | # Add current user as a project member if he is not admin | |
|
78 | unless User.current.admin? | |
|
79 | r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first | |
|
80 | m = Member.new(:user => User.current, :roles => [r]) | |
|
81 | @project.members << m | |
|
82 | end | |
|
83 | respond_to do |format| | |
|
84 | format.html { | |
|
85 | flash[:notice] = l(:notice_successful_create) | |
|
86 | redirect_to :controller => 'projects', :action => 'settings', :id => @project | |
|
87 | } | |
|
88 | format.xml { head :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } | |
|
89 | end | |
|
90 | else | |
|
91 | respond_to do |format| | |
|
92 | format.html | |
|
93 | format.xml { render :xml => @project.errors, :status => :unprocessable_entity } | |
|
94 | end | |
|
97 | respond_to do |format| | |
|
98 | format.html { render :action => 'add' } | |
|
99 | format.xml { render :xml => @project.errors, :status => :unprocessable_entity } | |
|
95 | 100 | end |
|
96 |
end |
|
|
101 | end | |
|
102 | ||
|
97 | 103 | end |
|
98 | 104 | |
|
99 | 105 | def copy |
@@ -195,9 +195,9 ActionController::Routing::Routes.draw do |map| | |||
|
195 | 195 | end |
|
196 | 196 | |
|
197 | 197 | projects.with_options :conditions => {:method => :post} do |project_actions| |
|
198 |
project_actions.connect 'projects/new', :action => ' |
|
|
199 |
project_actions.connect 'projects', :action => ' |
|
|
200 |
project_actions.connect 'projects.:format', :action => ' |
|
|
198 | project_actions.connect 'projects/new', :action => 'create' | |
|
199 | project_actions.connect 'projects', :action => 'create' | |
|
200 | project_actions.connect 'projects.:format', :action => 'create', :format => /xml/ | |
|
201 | 201 | project_actions.connect 'projects/:id/:action', :action => /edit|destroy|archive|unarchive/ |
|
202 | 202 | project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'new' |
|
203 | 203 | project_actions.connect 'projects/:id/activities/save', :controller => 'project_enumerations', :action => 'save' |
@@ -46,12 +46,12 end | |||
|
46 | 46 | Redmine::AccessControl.map do |map| |
|
47 | 47 | map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true |
|
48 | 48 | map.permission :search_project, {:search => :index}, :public => true |
|
49 | map.permission :add_project, {:projects => :add}, :require => :loggedin | |
|
49 | map.permission :add_project, {:projects => [:add, :create]}, :require => :loggedin | |
|
50 | 50 | map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member |
|
51 | 51 | map.permission :select_project_modules, {:projects => :modules}, :require => :member |
|
52 | 52 | map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member |
|
53 | 53 | map.permission :manage_versions, {:projects => :settings, :versions => [:new, :edit, :close_completed, :destroy]}, :require => :member |
|
54 | map.permission :add_subprojects, {:projects => :add}, :require => :member | |
|
54 | map.permission :add_subprojects, {:projects => [:add, :create]}, :require => :member | |
|
55 | 55 | |
|
56 | 56 | map.project_module :issue_tracking do |map| |
|
57 | 57 | # Issue categories |
@@ -98,9 +98,53 class ProjectsControllerTest < ActionController::TestCase | |||
|
98 | 98 | assert_response :success |
|
99 | 99 | assert_template 'add' |
|
100 | 100 | end |
|
101 | ||
|
102 | end | |
|
103 | ||
|
104 | context "by non-admin user with add_project permission" do | |
|
105 | setup do | |
|
106 | Role.non_member.add_permission! :add_project | |
|
107 | @request.session[:user_id] = 9 | |
|
108 | end | |
|
109 | ||
|
110 | should "accept get" do | |
|
111 | get :add | |
|
112 | assert_response :success | |
|
113 | assert_template 'add' | |
|
114 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'} | |
|
115 | end | |
|
116 | end | |
|
117 | ||
|
118 | context "by non-admin user with add_subprojects permission" do | |
|
119 | setup do | |
|
120 | Role.find(1).remove_permission! :add_project | |
|
121 | Role.find(1).add_permission! :add_subprojects | |
|
122 | @request.session[:user_id] = 2 | |
|
123 | end | |
|
124 | ||
|
125 | should "accept get" do | |
|
126 | get :add, :parent_id => 'ecookbook' | |
|
127 | assert_response :success | |
|
128 | assert_template 'add' | |
|
129 | # parent project selected | |
|
130 | assert_tag :select, :attributes => {:name => 'project[parent_id]'}, | |
|
131 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} | |
|
132 | # no empty value | |
|
133 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, | |
|
134 | :child => {:tag => 'option', :attributes => {:value => ''}} | |
|
135 | end | |
|
136 | end | |
|
137 | ||
|
138 | end | |
|
139 | ||
|
140 | context "POST :create" do | |
|
141 | context "by admin user" do | |
|
142 | setup do | |
|
143 | @request.session[:user_id] = 1 | |
|
144 | end | |
|
101 | 145 | |
|
102 |
should " |
|
|
103 |
post : |
|
|
146 | should "create a new project" do | |
|
147 | post :create, :project => { :name => "blog", | |
|
104 | 148 | :description => "weblog", |
|
105 | 149 | :identifier => "blog", |
|
106 | 150 | :is_public => 1, |
@@ -115,8 +159,8 class ProjectsControllerTest < ActionController::TestCase | |||
|
115 | 159 | assert_nil project.parent |
|
116 | 160 | end |
|
117 | 161 | |
|
118 | should "accept post with parent" do | |
|
119 |
post : |
|
|
162 | should "create a new subproject" do | |
|
163 | post :create, :project => { :name => "blog", | |
|
120 | 164 | :description => "weblog", |
|
121 | 165 | :identifier => "blog", |
|
122 | 166 | :is_public => 1, |
@@ -137,15 +181,8 class ProjectsControllerTest < ActionController::TestCase | |||
|
137 | 181 | @request.session[:user_id] = 9 |
|
138 | 182 | end |
|
139 | 183 | |
|
140 |
should "accept |
|
|
141 | get :add | |
|
142 | assert_response :success | |
|
143 | assert_template 'add' | |
|
144 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'} | |
|
145 | end | |
|
146 | ||
|
147 | should "accept post" do | |
|
148 | post :add, :project => { :name => "blog", | |
|
184 | should "accept create a Project" do | |
|
185 | post :create, :project => { :name => "blog", | |
|
149 | 186 | :description => "weblog", |
|
150 | 187 | :identifier => "blog", |
|
151 | 188 | :is_public => 1, |
@@ -166,7 +203,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
166 | 203 | |
|
167 | 204 | should "fail with parent_id" do |
|
168 | 205 | assert_no_difference 'Project.count' do |
|
169 |
post : |
|
|
206 | post :create, :project => { :name => "blog", | |
|
170 | 207 | :description => "weblog", |
|
171 | 208 | :identifier => "blog", |
|
172 | 209 | :is_public => 1, |
@@ -188,20 +225,8 class ProjectsControllerTest < ActionController::TestCase | |||
|
188 | 225 | @request.session[:user_id] = 2 |
|
189 | 226 | end |
|
190 | 227 | |
|
191 |
should " |
|
|
192 | get :add, :parent_id => 'ecookbook' | |
|
193 | assert_response :success | |
|
194 | assert_template 'add' | |
|
195 | # parent project selected | |
|
196 | assert_tag :select, :attributes => {:name => 'project[parent_id]'}, | |
|
197 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} | |
|
198 | # no empty value | |
|
199 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, | |
|
200 | :child => {:tag => 'option', :attributes => {:value => ''}} | |
|
201 | end | |
|
202 | ||
|
203 | should "accept post with parent_id" do | |
|
204 | post :add, :project => { :name => "blog", | |
|
228 | should "create a project with a parent_id" do | |
|
229 | post :create, :project => { :name => "blog", | |
|
205 | 230 | :description => "weblog", |
|
206 | 231 | :identifier => "blog", |
|
207 | 232 | :is_public => 1, |
@@ -214,7 +239,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
214 | 239 | |
|
215 | 240 | should "fail without parent_id" do |
|
216 | 241 | assert_no_difference 'Project.count' do |
|
217 |
post : |
|
|
242 | post :create, :project => { :name => "blog", | |
|
218 | 243 | :description => "weblog", |
|
219 | 244 | :identifier => "blog", |
|
220 | 245 | :is_public => 1, |
@@ -230,7 +255,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
230 | 255 | should "fail with unauthorized parent_id" do |
|
231 | 256 | assert !User.find(2).member_of?(Project.find(6)) |
|
232 | 257 | assert_no_difference 'Project.count' do |
|
233 |
post : |
|
|
258 | post :create, :project => { :name => "blog", | |
|
234 | 259 | :description => "weblog", |
|
235 | 260 | :identifier => "blog", |
|
236 | 261 | :is_public => 1, |
@@ -178,8 +178,8 class RoutingTest < ActionController::IntegrationTest | |||
|
178 | 178 | should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33' |
|
179 | 179 | should_route :get, "/projects/33/activity.atom", :controller => 'activities', :action => 'index', :id => '33', :format => 'atom' |
|
180 | 180 | |
|
181 |
should_route :post, "/projects/new", :controller => 'projects', :action => ' |
|
|
182 |
should_route :post, "/projects.xml", :controller => 'projects', :action => ' |
|
|
181 | should_route :post, "/projects/new", :controller => 'projects', :action => 'create' | |
|
182 | should_route :post, "/projects.xml", :controller => 'projects', :action => 'create', :format => 'xml' | |
|
183 | 183 | should_route :post, "/projects/4223/edit", :controller => 'projects', :action => 'edit', :id => '4223' |
|
184 | 184 | should_route :post, "/projects/64/destroy", :controller => 'projects', :action => 'destroy', :id => '64' |
|
185 | 185 | should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'new', :id => '33' |
General Comments 0
You need to be logged in to leave comments.
Login now