##// END OF EJS Templates
Fixes default data loader broken by r2777 (#3507)....
Jean-Philippe Lang -
r2692:72a396227ac5
parent child
Show More
@@ -1,176 +1,176
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 module Redmine
19 19 module DefaultData
20 20 class DataAlreadyLoaded < Exception; end
21 21
22 22 module Loader
23 23 include Redmine::I18n
24 24
25 25 class << self
26 26 # Returns true if no data is already loaded in the database
27 27 # otherwise false
28 28 def no_data?
29 29 !Role.find(:first, :conditions => {:builtin => 0}) &&
30 30 !Tracker.find(:first) &&
31 31 !IssueStatus.find(:first) &&
32 32 !Enumeration.find(:first)
33 33 end
34 34
35 35 # Loads the default data
36 36 # Raises a RecordNotSaved exception if something goes wrong
37 37 def load(lang=nil)
38 38 raise DataAlreadyLoaded.new("Some configuration data is already loaded.") unless no_data?
39 39 set_language_if_valid(lang)
40 40
41 41 Role.transaction do
42 42 # Roles
43 43 manager = Role.create! :name => l(:default_role_manager),
44 44 :position => 1
45 45 manager.permissions = manager.setable_permissions.collect {|p| p.name}
46 46 manager.save!
47 47
48 48 developper = Role.create! :name => l(:default_role_developper),
49 49 :position => 2,
50 50 :permissions => [:manage_versions,
51 51 :manage_categories,
52 52 :add_issues,
53 53 :edit_issues,
54 54 :manage_issue_relations,
55 55 :add_issue_notes,
56 56 :save_queries,
57 57 :view_gantt,
58 58 :view_calendar,
59 59 :log_time,
60 60 :view_time_entries,
61 61 :comment_news,
62 62 :view_documents,
63 63 :view_wiki_pages,
64 64 :view_wiki_edits,
65 65 :edit_wiki_pages,
66 66 :delete_wiki_pages,
67 67 :add_messages,
68 68 :edit_own_messages,
69 69 :view_files,
70 70 :manage_files,
71 71 :browse_repository,
72 72 :view_changesets,
73 73 :commit_access]
74 74
75 75 reporter = Role.create! :name => l(:default_role_reporter),
76 76 :position => 3,
77 77 :permissions => [:add_issues,
78 78 :add_issue_notes,
79 79 :save_queries,
80 80 :view_gantt,
81 81 :view_calendar,
82 82 :log_time,
83 83 :view_time_entries,
84 84 :comment_news,
85 85 :view_documents,
86 86 :view_wiki_pages,
87 87 :view_wiki_edits,
88 88 :add_messages,
89 89 :edit_own_messages,
90 90 :view_files,
91 91 :browse_repository,
92 92 :view_changesets]
93 93
94 94 Role.non_member.update_attribute :permissions, [:add_issues,
95 95 :add_issue_notes,
96 96 :save_queries,
97 97 :view_gantt,
98 98 :view_calendar,
99 99 :view_time_entries,
100 100 :comment_news,
101 101 :view_documents,
102 102 :view_wiki_pages,
103 103 :view_wiki_edits,
104 104 :add_messages,
105 105 :view_files,
106 106 :browse_repository,
107 107 :view_changesets]
108 108
109 109 Role.anonymous.update_attribute :permissions, [:view_gantt,
110 110 :view_calendar,
111 111 :view_time_entries,
112 112 :view_documents,
113 113 :view_wiki_pages,
114 114 :view_wiki_edits,
115 115 :view_files,
116 116 :browse_repository,
117 117 :view_changesets]
118 118
119 119 # Trackers
120 120 Tracker.create!(:name => l(:default_tracker_bug), :is_in_chlog => true, :is_in_roadmap => false, :position => 1)
121 121 Tracker.create!(:name => l(:default_tracker_feature), :is_in_chlog => true, :is_in_roadmap => true, :position => 2)
122 122 Tracker.create!(:name => l(:default_tracker_support), :is_in_chlog => false, :is_in_roadmap => false, :position => 3)
123 123
124 124 # Issue statuses
125 125 new = IssueStatus.create!(:name => l(:default_issue_status_new), :is_closed => false, :is_default => true, :position => 1)
126 126 assigned = IssueStatus.create!(:name => l(:default_issue_status_assigned), :is_closed => false, :is_default => false, :position => 2)
127 127 resolved = IssueStatus.create!(:name => l(:default_issue_status_resolved), :is_closed => false, :is_default => false, :position => 3)
128 128 feedback = IssueStatus.create!(:name => l(:default_issue_status_feedback), :is_closed => false, :is_default => false, :position => 4)
129 129 closed = IssueStatus.create!(:name => l(:default_issue_status_closed), :is_closed => true, :is_default => false, :position => 5)
130 130 rejected = IssueStatus.create!(:name => l(:default_issue_status_rejected), :is_closed => true, :is_default => false, :position => 6)
131 131
132 132 # Workflow
133 133 Tracker.find(:all).each { |t|
134 134 IssueStatus.find(:all).each { |os|
135 135 IssueStatus.find(:all).each { |ns|
136 136 Workflow.create!(:tracker_id => t.id, :role_id => manager.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns
137 137 }
138 138 }
139 139 }
140 140
141 141 Tracker.find(:all).each { |t|
142 142 [new, assigned, resolved, feedback].each { |os|
143 143 [assigned, resolved, feedback, closed].each { |ns|
144 144 Workflow.create!(:tracker_id => t.id, :role_id => developper.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns
145 145 }
146 146 }
147 147 }
148 148
149 149 Tracker.find(:all).each { |t|
150 150 [new, assigned, resolved, feedback].each { |os|
151 151 [closed].each { |ns|
152 152 Workflow.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns
153 153 }
154 154 }
155 155 Workflow.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => resolved.id, :new_status_id => feedback.id)
156 156 }
157 157
158 158 # Enumerations
159 Enumeration.create!(:opt => "DCAT", :name => l(:default_doc_category_user), :position => 1)
160 Enumeration.create!(:opt => "DCAT", :name => l(:default_doc_category_tech), :position => 2)
159 DocumentCategory.create!(:opt => "DCAT", :name => l(:default_doc_category_user), :position => 1)
160 DocumentCategory.create!(:opt => "DCAT", :name => l(:default_doc_category_tech), :position => 2)
161 161
162 Enumeration.create!(:opt => "IPRI", :name => l(:default_priority_low), :position => 1)
163 Enumeration.create!(:opt => "IPRI", :name => l(:default_priority_normal), :position => 2, :is_default => true)
164 Enumeration.create!(:opt => "IPRI", :name => l(:default_priority_high), :position => 3)
165 Enumeration.create!(:opt => "IPRI", :name => l(:default_priority_urgent), :position => 4)
166 Enumeration.create!(:opt => "IPRI", :name => l(:default_priority_immediate), :position => 5)
162 IssuePriority.create!(:opt => "IPRI", :name => l(:default_priority_low), :position => 1)
163 IssuePriority.create!(:opt => "IPRI", :name => l(:default_priority_normal), :position => 2, :is_default => true)
164 IssuePriority.create!(:opt => "IPRI", :name => l(:default_priority_high), :position => 3)
165 IssuePriority.create!(:opt => "IPRI", :name => l(:default_priority_urgent), :position => 4)
166 IssuePriority.create!(:opt => "IPRI", :name => l(:default_priority_immediate), :position => 5)
167 167
168 Enumeration.create!(:opt => "ACTI", :name => l(:default_activity_design), :position => 1)
169 Enumeration.create!(:opt => "ACTI", :name => l(:default_activity_development), :position => 2)
168 TimeEntryActivity.create!(:opt => "ACTI", :name => l(:default_activity_design), :position => 1)
169 TimeEntryActivity.create!(:opt => "ACTI", :name => l(:default_activity_development), :position => 2)
170 170 end
171 171 true
172 172 end
173 173 end
174 174 end
175 175 end
176 176 end
@@ -1,46 +1,49
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class DefaultDataTest < Test::Unit::TestCase
21 21 include Redmine::I18n
22 22 fixtures :roles
23 23
24 24 def test_no_data
25 25 assert !Redmine::DefaultData::Loader::no_data?
26 26 Role.delete_all("builtin = 0")
27 27 Tracker.delete_all
28 28 IssueStatus.delete_all
29 29 Enumeration.delete_all
30 30 assert Redmine::DefaultData::Loader::no_data?
31 31 end
32 32
33 33 def test_load
34 34 valid_languages.each do |lang|
35 35 begin
36 36 Role.delete_all("builtin = 0")
37 37 Tracker.delete_all
38 38 IssueStatus.delete_all
39 39 Enumeration.delete_all
40 40 assert Redmine::DefaultData::Loader::load(lang)
41 assert_not_nil DocumentCategory.first
42 assert_not_nil IssuePriority.first
43 assert_not_nil TimeEntryActivity.first
41 44 rescue ActiveRecord::RecordInvalid => e
42 45 assert false, ":#{lang} default data is invalid (#{e.message})."
43 46 end
44 47 end
45 48 end
46 49 end
General Comments 0
You need to be logged in to leave comments. Login now