@@ -68,11 +68,6 class ProjectsController < ApplicationController | |||||
68 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
68 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
69 | @trackers = Tracker.all |
|
69 | @trackers = Tracker.all | |
70 | @project = Project.new(params[:project]) |
|
70 | @project = Project.new(params[:project]) | |
71 |
|
||||
72 | @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? |
|
|||
73 | @project.trackers = Tracker.all |
|
|||
74 | @project.is_public = Setting.default_projects_public? |
|
|||
75 | @project.enabled_module_names = Setting.default_projects_modules |
|
|||
76 | end |
|
71 | end | |
77 |
|
72 | |||
78 | def create |
|
73 | def create | |
@@ -80,7 +75,7 class ProjectsController < ApplicationController | |||||
80 | @trackers = Tracker.all |
|
75 | @trackers = Tracker.all | |
81 | @project = Project.new(params[:project]) |
|
76 | @project = Project.new(params[:project]) | |
82 |
|
77 | |||
83 | @project.enabled_module_names = params[:enabled_modules] |
|
78 | @project.enabled_module_names = params[:enabled_modules] if params[:enabled_modules] | |
84 | if validate_parent_id && @project.save |
|
79 | if validate_parent_id && @project.save | |
85 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
|
80 | @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | |
86 | # Add current user as a project member if he is not admin |
|
81 | # Add current user as a project member if he is not admin |
@@ -84,6 +84,24 class Project < ActiveRecord::Base | |||||
84 | named_scope :all_public, { :conditions => { :is_public => true } } |
|
84 | named_scope :all_public, { :conditions => { :is_public => true } } | |
85 | named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } } |
|
85 | named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } } | |
86 |
|
86 | |||
|
87 | def initialize(attributes = nil) | |||
|
88 | super | |||
|
89 | ||||
|
90 | initialized = (attributes || {}).stringify_keys | |||
|
91 | if !initialized.key?('identifier') && Setting.sequential_project_identifiers? | |||
|
92 | self.identifier = Project.next_identifier | |||
|
93 | end | |||
|
94 | if !initialized.key?('is_public') | |||
|
95 | self.is_public = Setting.default_projects_public? | |||
|
96 | end | |||
|
97 | if !initialized.key?('enabled_module_names') | |||
|
98 | self.enabled_module_names = Setting.default_projects_modules | |||
|
99 | end | |||
|
100 | if !initialized.key?('trackers') && !initialized.key?('tracker_ids') | |||
|
101 | self.trackers = Tracker.all | |||
|
102 | end | |||
|
103 | end | |||
|
104 | ||||
87 | def identifier=(identifier) |
|
105 | def identifier=(identifier) | |
88 | super unless identifier_frozen? |
|
106 | super unless identifier_frozen? | |
89 | end |
|
107 | end | |
@@ -492,7 +510,7 class Project < ActiveRecord::Base | |||||
492 |
|
510 | |||
493 | def enabled_module_names=(module_names) |
|
511 | def enabled_module_names=(module_names) | |
494 | if module_names && module_names.is_a?(Array) |
|
512 | if module_names && module_names.is_a?(Array) | |
495 | module_names = module_names.collect(&:to_s) |
|
513 | module_names = module_names.collect(&:to_s).reject(&:blank?) | |
496 | # remove disabled modules |
|
514 | # remove disabled modules | |
497 | enabled_modules.each {|mod| mod.destroy unless module_names.include?(mod.name)} |
|
515 | enabled_modules.each {|mod| mod.destroy unless module_names.include?(mod.name)} | |
498 | # add new modules |
|
516 | # add new modules | |
@@ -501,6 +519,11 class Project < ActiveRecord::Base | |||||
501 | enabled_modules.clear |
|
519 | enabled_modules.clear | |
502 | end |
|
520 | end | |
503 | end |
|
521 | end | |
|
522 | ||||
|
523 | # Returns an array of the enabled modules names | |||
|
524 | def enabled_module_names | |||
|
525 | enabled_modules.collect(&:name) | |||
|
526 | end | |||
504 |
|
527 | |||
505 | # Returns an array of projects that are in this project's hierarchy |
|
528 | # Returns an array of projects that are in this project's hierarchy | |
506 | # |
|
529 | # |
@@ -10,6 +10,8 | |||||
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[]', '' %> | |||
|
14 | ||||
13 | </fieldset> |
|
15 | </fieldset> | |
14 |
|
16 | |||
15 | <%= submit_tag l(:button_save) %> |
|
17 | <%= submit_tag l(:button_save) %> |
@@ -103,6 +103,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
103 | context "POST /projects" do |
|
103 | context "POST /projects" do | |
104 | context "with valid parameters" do |
|
104 | context "with valid parameters" do | |
105 | setup do |
|
105 | setup do | |
|
106 | Setting.default_projects_modules = ['issue_tracking', 'repository'] | |||
106 | @parameters = {:project => {:name => 'API test', :identifier => 'api-test'}} |
|
107 | @parameters = {:project => {:name => 'API test', :identifier => 'api-test'}} | |
107 | end |
|
108 | end | |
108 |
|
109 | |||
@@ -121,6 +122,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
121 | project = Project.first(:order => 'id DESC') |
|
122 | project = Project.first(:order => 'id DESC') | |
122 | assert_equal 'API test', project.name |
|
123 | assert_equal 'API test', project.name | |
123 | assert_equal 'api-test', project.identifier |
|
124 | assert_equal 'api-test', project.identifier | |
|
125 | assert_equal ['issue_tracking', 'repository'], project.enabled_module_names | |||
124 |
|
126 | |||
125 | assert_response :created |
|
127 | assert_response :created | |
126 | assert_equal 'application/xml', @response.content_type |
|
128 | assert_equal 'application/xml', @response.content_type |
@@ -60,6 +60,35 class ProjectTest < ActiveSupport::TestCase | |||||
60 | assert_equal "eCookbook", @ecookbook.name |
|
60 | assert_equal "eCookbook", @ecookbook.name | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
|
63 | def test_default_attributes | |||
|
64 | with_settings :default_projects_public => '1' do | |||
|
65 | assert_equal true, Project.new.is_public | |||
|
66 | assert_equal false, Project.new(:is_public => false).is_public | |||
|
67 | end | |||
|
68 | ||||
|
69 | with_settings :default_projects_public => '0' do | |||
|
70 | assert_equal false, Project.new.is_public | |||
|
71 | assert_equal true, Project.new(:is_public => true).is_public | |||
|
72 | end | |||
|
73 | ||||
|
74 | with_settings :sequential_project_identifiers => '1' do | |||
|
75 | assert !Project.new.identifier.blank? | |||
|
76 | assert Project.new(:identifier => '').identifier.blank? | |||
|
77 | end | |||
|
78 | ||||
|
79 | with_settings :sequential_project_identifiers => '0' do | |||
|
80 | assert Project.new.identifier.blank? | |||
|
81 | assert !Project.new(:identifier => 'test').blank? | |||
|
82 | end | |||
|
83 | ||||
|
84 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | |||
|
85 | assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names | |||
|
86 | end | |||
|
87 | ||||
|
88 | assert_equal Tracker.all, Project.new.trackers | |||
|
89 | assert_equal Tracker.find(1, 3), Project.new(:tracker_ids => [1, 3]).trackers | |||
|
90 | end | |||
|
91 | ||||
63 | def test_update |
|
92 | def test_update | |
64 | assert_equal "eCookbook", @ecookbook.name |
|
93 | assert_equal "eCookbook", @ecookbook.name | |
65 | @ecookbook.name = "eCook" |
|
94 | @ecookbook.name = "eCook" |
General Comments 0
You need to be logged in to leave comments.
Login now