From 9fb770ba503b3dfe1fe48794e1b7042c5e26d8d7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 6 Jan 2011 20:36:31 +0000 Subject: [PATCH] Moves enabled_module_names param to project attribute so that it can be set through the Project API. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4645 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/projects_controller.rb | 1 - app/models/project.rb | 5 ++- app/views/projects/new.html.erb | 4 +- test/fixtures/roles.yml | 1 + test/functional/projects_controller_test.rb | 10 ++++- test/integration/api_test/projects_test.rb | 47 ++++++++++++++++++++- 6 files changed, 61 insertions(+), 7 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 420801c0..1dffedc0 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -77,7 +77,6 @@ class ProjectsController < ApplicationController @project = Project.new @project.safe_attributes = params[:project] - @project.enabled_module_names = params[:enabled_modules] if params[:enabled_modules] if validate_parent_id && @project.save @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') # Add current user as a project member if he is not admin diff --git a/app/models/project.rb b/app/models/project.rb index 891db8b8..8315a48a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -66,7 +66,7 @@ class Project < ActiveRecord::Base :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o}}, :author => nil - attr_protected :status, :enabled_module_names + attr_protected :status validates_presence_of :name, :identifier validates_uniqueness_of :identifier @@ -533,6 +533,9 @@ class Project < ActiveRecord::Base 'tracker_ids', 'issue_custom_field_ids' + safe_attributes 'enabled_module_names', + :if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) } + # Returns an array of projects that are in this project's hierarchy # # Example: parents, children, siblings diff --git a/app/views/projects/new.html.erb b/app/views/projects/new.html.erb index aad9c2c2..1b990782 100644 --- a/app/views/projects/new.html.erb +++ b/app/views/projects/new.html.erb @@ -6,11 +6,11 @@
<%= l(:label_module_plural) %> <% Redmine::AccessControl.available_project_modules.each do |m| %> <% end %> -<%= hidden_field_tag 'enabled_modules[]', '' %> +<%= hidden_field_tag 'project[enabled_module_names][]', '' %>
diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml index f63203ae..979cc321 100644 --- a/test/fixtures/roles.yml +++ b/test/fixtures/roles.yml @@ -7,6 +7,7 @@ roles_001: --- - :add_project - :edit_project + - :select_project_modules - :manage_members - :manage_versions - :manage_categories diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index aaf6e308..d3a12f29 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -154,7 +154,8 @@ class ProjectsControllerTest < ActionController::TestCase :custom_field_values => { '3' => 'Beta' }, :tracker_ids => ['1', '3'], # an issue custom field that is not for all project - :issue_custom_field_ids => ['9'] + :issue_custom_field_ids => ['9'], + :enabled_module_names => ['issue_tracking', 'news', 'repository'] } assert_redirected_to '/projects/blog/settings' @@ -167,6 +168,7 @@ class ProjectsControllerTest < ActionController::TestCase assert_nil project.parent assert_equal 'Beta', project.custom_value_for(3).value assert_equal [1, 3], project.trackers.map(&:id).sort + assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort assert project.issue_custom_fields.include?(IssueCustomField.find(9)) end @@ -197,7 +199,9 @@ class ProjectsControllerTest < ActionController::TestCase :description => "weblog", :identifier => "blog", :is_public => 1, - :custom_field_values => { '3' => 'Beta' } + :custom_field_values => { '3' => 'Beta' }, + :tracker_ids => ['1', '3'], + :enabled_module_names => ['issue_tracking', 'news', 'repository'] } assert_redirected_to '/projects/blog/settings' @@ -206,6 +210,8 @@ class ProjectsControllerTest < ActionController::TestCase assert_kind_of Project, project assert_equal 'weblog', project.description assert_equal true, project.is_public? + assert_equal [1, 3], project.trackers.map(&:id).sort + assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort # User should be added as a project member assert User.find(9).member_of?(project) diff --git a/test/integration/api_test/projects_test.rb b/test/integration/api_test/projects_test.rb index e40d6584..6258aae8 100644 --- a/test/integration/api_test/projects_test.rb +++ b/test/integration/api_test/projects_test.rb @@ -122,12 +122,35 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest project = Project.first(:order => 'id DESC') assert_equal 'API test', project.name assert_equal 'api-test', project.identifier - assert_equal ['issue_tracking', 'repository'], project.enabled_module_names + assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort + assert_equal Tracker.all.size, project.trackers.size assert_response :created assert_equal 'application/xml', @response.content_type assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s} end + + should "accept enabled_module_names attribute" do + @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) + + assert_difference('Project.count') do + post '/projects.xml', @parameters, :authorization => credentials('admin') + end + + project = Project.first(:order => 'id DESC') + assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort + end + + should "accept tracker_ids attribute" do + @parameters[:project].merge!({:tracker_ids => [1, 3]}) + + assert_difference('Project.count') do + post '/projects.xml', @parameters, :authorization => credentials('admin') + end + + project = Project.first(:order => 'id DESC') + assert_equal [1, 3], project.trackers.map(&:id).sort + end end end @@ -171,6 +194,28 @@ class ApiTest::ProjectsTest < ActionController::IntegrationTest project = Project.find(2) assert_equal 'API update', project.name end + + should "accept enabled_module_names attribute" do + @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) + + assert_no_difference 'Project.count' do + put '/projects/2.xml', @parameters, :authorization => credentials('admin') + end + assert_response :ok + project = Project.find(2) + assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort + end + + should "accept tracker_ids attribute" do + @parameters[:project].merge!({:tracker_ids => [1, 3]}) + + assert_no_difference 'Project.count' do + put '/projects/2.xml', @parameters, :authorization => credentials('admin') + end + assert_response :ok + project = Project.find(2) + assert_equal [1, 3], project.trackers.map(&:id).sort + end end end