Commit 9fb770ba authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Moves enabled_module_names param to project attribute so that it can be set…

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
parent 7620142b
......@@ -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
......
......@@ -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
......
......@@ -6,11 +6,11 @@
<fieldset class="box"><legend><%= l(:label_module_plural) %></legend>
<% Redmine::AccessControl.available_project_modules.each do |m| %>
<label class="floating">
<%= check_box_tag 'enabled_modules[]', m, @project.module_enabled?(m) %>
<%= check_box_tag 'project[enabled_module_names][]', m, @project.module_enabled?(m) %>
<%= l_or_humanize(m, :prefix => "project_module_") %>
</label>
<% end %>
<%= hidden_field_tag 'enabled_modules[]', '' %>
<%= hidden_field_tag 'project[enabled_module_names][]', '' %>
</fieldset>
......
......@@ -7,6 +7,7 @@ roles_001:
---
- :add_project
- :edit_project
- :select_project_modules
- :manage_members
- :manage_versions
- :manage_categories
......
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment