@@ -77,7 +77,6 class ProjectsController < ApplicationController | |||||
77 | @project = Project.new |
|
77 | @project = Project.new | |
78 | @project.safe_attributes = params[:project] |
|
78 | @project.safe_attributes = params[:project] | |
79 |
|
79 | |||
80 | @project.enabled_module_names = params[:enabled_modules] if params[:enabled_modules] |
|
|||
81 | if validate_parent_id && @project.save |
|
80 | if validate_parent_id && @project.save | |
82 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
|
81 | @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 |
|
82 | # Add current user as a project member if he is not admin |
@@ -66,7 +66,7 class Project < ActiveRecord::Base | |||||
66 | :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o}}, |
|
66 | :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o}}, | |
67 | :author => nil |
|
67 | :author => nil | |
68 |
|
68 | |||
69 |
attr_protected :status |
|
69 | attr_protected :status | |
70 |
|
70 | |||
71 | validates_presence_of :name, :identifier |
|
71 | validates_presence_of :name, :identifier | |
72 | validates_uniqueness_of :identifier |
|
72 | validates_uniqueness_of :identifier | |
@@ -533,6 +533,9 class Project < ActiveRecord::Base | |||||
533 | 'tracker_ids', |
|
533 | 'tracker_ids', | |
534 | 'issue_custom_field_ids' |
|
534 | 'issue_custom_field_ids' | |
535 |
|
535 | |||
|
536 | safe_attributes 'enabled_module_names', | |||
|
537 | :if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) } | |||
|
538 | ||||
536 | # Returns an array of projects that are in this project's hierarchy |
|
539 | # Returns an array of projects that are in this project's hierarchy | |
537 | # |
|
540 | # | |
538 | # Example: parents, children, siblings |
|
541 | # Example: parents, children, siblings |
@@ -6,11 +6,11 | |||||
6 | <fieldset class="box"><legend><%= l(:label_module_plural) %></legend> |
|
6 | <fieldset class="box"><legend><%= l(:label_module_plural) %></legend> | |
7 | <% Redmine::AccessControl.available_project_modules.each do |m| %> |
|
7 | <% Redmine::AccessControl.available_project_modules.each do |m| %> | |
8 | <label class="floating"> |
|
8 | <label class="floating"> | |
9 | <%= check_box_tag 'enabled_modules[]', m, @project.module_enabled?(m) %> |
|
9 | <%= check_box_tag 'project[enabled_module_names][]', m, @project.module_enabled?(m) %> | |
10 | <%= l_or_humanize(m, :prefix => "project_module_") %> |
|
10 | <%= l_or_humanize(m, :prefix => "project_module_") %> | |
11 | </label> |
|
11 | </label> | |
12 | <% end %> |
|
12 | <% end %> | |
13 | <%= hidden_field_tag 'enabled_modules[]', '' %> |
|
13 | <%= hidden_field_tag 'project[enabled_module_names][]', '' %> | |
14 |
|
14 | |||
15 | </fieldset> |
|
15 | </fieldset> | |
16 |
|
16 |
@@ -7,6 +7,7 roles_001: | |||||
7 | --- |
|
7 | --- | |
8 | - :add_project |
|
8 | - :add_project | |
9 | - :edit_project |
|
9 | - :edit_project | |
|
10 | - :select_project_modules | |||
10 | - :manage_members |
|
11 | - :manage_members | |
11 | - :manage_versions |
|
12 | - :manage_versions | |
12 | - :manage_categories |
|
13 | - :manage_categories |
@@ -154,7 +154,8 class ProjectsControllerTest < ActionController::TestCase | |||||
154 | :custom_field_values => { '3' => 'Beta' }, |
|
154 | :custom_field_values => { '3' => 'Beta' }, | |
155 | :tracker_ids => ['1', '3'], |
|
155 | :tracker_ids => ['1', '3'], | |
156 | # an issue custom field that is not for all project |
|
156 | # an issue custom field that is not for all project | |
157 | :issue_custom_field_ids => ['9'] |
|
157 | :issue_custom_field_ids => ['9'], | |
|
158 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] | |||
158 | } |
|
159 | } | |
159 | assert_redirected_to '/projects/blog/settings' |
|
160 | assert_redirected_to '/projects/blog/settings' | |
160 |
|
161 | |||
@@ -167,6 +168,7 class ProjectsControllerTest < ActionController::TestCase | |||||
167 | assert_nil project.parent |
|
168 | assert_nil project.parent | |
168 | assert_equal 'Beta', project.custom_value_for(3).value |
|
169 | assert_equal 'Beta', project.custom_value_for(3).value | |
169 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
170 | assert_equal [1, 3], project.trackers.map(&:id).sort | |
|
171 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | |||
170 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) |
|
172 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) | |
171 | end |
|
173 | end | |
172 |
|
174 | |||
@@ -197,7 +199,9 class ProjectsControllerTest < ActionController::TestCase | |||||
197 | :description => "weblog", |
|
199 | :description => "weblog", | |
198 | :identifier => "blog", |
|
200 | :identifier => "blog", | |
199 | :is_public => 1, |
|
201 | :is_public => 1, | |
200 | :custom_field_values => { '3' => 'Beta' } |
|
202 | :custom_field_values => { '3' => 'Beta' }, | |
|
203 | :tracker_ids => ['1', '3'], | |||
|
204 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] | |||
201 | } |
|
205 | } | |
202 |
|
206 | |||
203 | assert_redirected_to '/projects/blog/settings' |
|
207 | assert_redirected_to '/projects/blog/settings' | |
@@ -206,6 +210,8 class ProjectsControllerTest < ActionController::TestCase | |||||
206 | assert_kind_of Project, project |
|
210 | assert_kind_of Project, project | |
207 | assert_equal 'weblog', project.description |
|
211 | assert_equal 'weblog', project.description | |
208 | assert_equal true, project.is_public? |
|
212 | assert_equal true, project.is_public? | |
|
213 | assert_equal [1, 3], project.trackers.map(&:id).sort | |||
|
214 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | |||
209 |
|
215 | |||
210 | # User should be added as a project member |
|
216 | # User should be added as a project member | |
211 | assert User.find(9).member_of?(project) |
|
217 | assert User.find(9).member_of?(project) |
@@ -122,12 +122,35 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
122 | project = Project.first(:order => 'id DESC') |
|
122 | project = Project.first(:order => 'id DESC') | |
123 | assert_equal 'API test', project.name |
|
123 | assert_equal 'API test', project.name | |
124 | assert_equal 'api-test', project.identifier |
|
124 | assert_equal 'api-test', project.identifier | |
125 | assert_equal ['issue_tracking', 'repository'], project.enabled_module_names |
|
125 | assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort | |
|
126 | assert_equal Tracker.all.size, project.trackers.size | |||
126 |
|
127 | |||
127 | assert_response :created |
|
128 | assert_response :created | |
128 | assert_equal 'application/xml', @response.content_type |
|
129 | assert_equal 'application/xml', @response.content_type | |
129 | assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s} |
|
130 | assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s} | |
130 | end |
|
131 | end | |
|
132 | ||||
|
133 | should "accept enabled_module_names attribute" do | |||
|
134 | @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) | |||
|
135 | ||||
|
136 | assert_difference('Project.count') do | |||
|
137 | post '/projects.xml', @parameters, :authorization => credentials('admin') | |||
|
138 | end | |||
|
139 | ||||
|
140 | project = Project.first(:order => 'id DESC') | |||
|
141 | assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort | |||
|
142 | end | |||
|
143 | ||||
|
144 | should "accept tracker_ids attribute" do | |||
|
145 | @parameters[:project].merge!({:tracker_ids => [1, 3]}) | |||
|
146 | ||||
|
147 | assert_difference('Project.count') do | |||
|
148 | post '/projects.xml', @parameters, :authorization => credentials('admin') | |||
|
149 | end | |||
|
150 | ||||
|
151 | project = Project.first(:order => 'id DESC') | |||
|
152 | assert_equal [1, 3], project.trackers.map(&:id).sort | |||
|
153 | end | |||
131 | end |
|
154 | end | |
132 | end |
|
155 | end | |
133 |
|
156 | |||
@@ -171,6 +194,28 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
171 | project = Project.find(2) |
|
194 | project = Project.find(2) | |
172 | assert_equal 'API update', project.name |
|
195 | assert_equal 'API update', project.name | |
173 | end |
|
196 | end | |
|
197 | ||||
|
198 | should "accept enabled_module_names attribute" do | |||
|
199 | @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) | |||
|
200 | ||||
|
201 | assert_no_difference 'Project.count' do | |||
|
202 | put '/projects/2.xml', @parameters, :authorization => credentials('admin') | |||
|
203 | end | |||
|
204 | assert_response :ok | |||
|
205 | project = Project.find(2) | |||
|
206 | assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort | |||
|
207 | end | |||
|
208 | ||||
|
209 | should "accept tracker_ids attribute" do | |||
|
210 | @parameters[:project].merge!({:tracker_ids => [1, 3]}) | |||
|
211 | ||||
|
212 | assert_no_difference 'Project.count' do | |||
|
213 | put '/projects/2.xml', @parameters, :authorization => credentials('admin') | |||
|
214 | end | |||
|
215 | assert_response :ok | |||
|
216 | project = Project.find(2) | |||
|
217 | assert_equal [1, 3], project.trackers.map(&:id).sort | |||
|
218 | end | |||
174 | end |
|
219 | end | |
175 | end |
|
220 | end | |
176 |
|
221 |
General Comments 0
You need to be logged in to leave comments.
Login now