@@ -1,186 +1,189 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 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.where(:builtin => 0).exists? && |
|
30 | 30 | !Tracker.exists? && |
|
31 | 31 | !IssueStatus.exists? && |
|
32 | 32 | !Enumeration.exists? |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | # Loads the default data |
|
36 | 36 | # Raises a RecordNotSaved exception if something goes wrong |
|
37 | def load(lang=nil) | |
|
37 | def load(lang=nil, options={}) | |
|
38 | 38 | raise DataAlreadyLoaded.new("Some configuration data is already loaded.") unless no_data? |
|
39 | 39 | set_language_if_valid(lang) |
|
40 | workflow = !(options[:workflow] == false) | |
|
40 | 41 | |
|
41 | 42 | Role.transaction do |
|
42 | 43 | # Roles |
|
43 | 44 | manager = Role.create! :name => l(:default_role_manager), |
|
44 | 45 | :issues_visibility => 'all', |
|
45 | 46 | :users_visibility => 'all', |
|
46 | 47 | :position => 1 |
|
47 | 48 | manager.permissions = manager.setable_permissions.collect {|p| p.name} |
|
48 | 49 | manager.save! |
|
49 | 50 | |
|
50 | 51 | developer = Role.create! :name => l(:default_role_developer), |
|
51 | 52 | :position => 2, |
|
52 | 53 | :permissions => [:manage_versions, |
|
53 | 54 | :manage_categories, |
|
54 | 55 | :view_issues, |
|
55 | 56 | :add_issues, |
|
56 | 57 | :edit_issues, |
|
57 | 58 | :view_private_notes, |
|
58 | 59 | :set_notes_private, |
|
59 | 60 | :manage_issue_relations, |
|
60 | 61 | :manage_subtasks, |
|
61 | 62 | :add_issue_notes, |
|
62 | 63 | :save_queries, |
|
63 | 64 | :view_gantt, |
|
64 | 65 | :view_calendar, |
|
65 | 66 | :log_time, |
|
66 | 67 | :view_time_entries, |
|
67 | 68 | :comment_news, |
|
68 | 69 | :view_documents, |
|
69 | 70 | :view_wiki_pages, |
|
70 | 71 | :view_wiki_edits, |
|
71 | 72 | :edit_wiki_pages, |
|
72 | 73 | :delete_wiki_pages, |
|
73 | 74 | :add_messages, |
|
74 | 75 | :edit_own_messages, |
|
75 | 76 | :view_files, |
|
76 | 77 | :manage_files, |
|
77 | 78 | :browse_repository, |
|
78 | 79 | :view_changesets, |
|
79 | 80 | :commit_access, |
|
80 | 81 | :manage_related_issues] |
|
81 | 82 | |
|
82 | 83 | reporter = Role.create! :name => l(:default_role_reporter), |
|
83 | 84 | :position => 3, |
|
84 | 85 | :permissions => [:view_issues, |
|
85 | 86 | :add_issues, |
|
86 | 87 | :add_issue_notes, |
|
87 | 88 | :save_queries, |
|
88 | 89 | :view_gantt, |
|
89 | 90 | :view_calendar, |
|
90 | 91 | :log_time, |
|
91 | 92 | :view_time_entries, |
|
92 | 93 | :comment_news, |
|
93 | 94 | :view_documents, |
|
94 | 95 | :view_wiki_pages, |
|
95 | 96 | :view_wiki_edits, |
|
96 | 97 | :add_messages, |
|
97 | 98 | :edit_own_messages, |
|
98 | 99 | :view_files, |
|
99 | 100 | :browse_repository, |
|
100 | 101 | :view_changesets] |
|
101 | 102 | |
|
102 | 103 | Role.non_member.update_attribute :permissions, [:view_issues, |
|
103 | 104 | :add_issues, |
|
104 | 105 | :add_issue_notes, |
|
105 | 106 | :save_queries, |
|
106 | 107 | :view_gantt, |
|
107 | 108 | :view_calendar, |
|
108 | 109 | :view_time_entries, |
|
109 | 110 | :comment_news, |
|
110 | 111 | :view_documents, |
|
111 | 112 | :view_wiki_pages, |
|
112 | 113 | :view_wiki_edits, |
|
113 | 114 | :add_messages, |
|
114 | 115 | :view_files, |
|
115 | 116 | :browse_repository, |
|
116 | 117 | :view_changesets] |
|
117 | 118 | |
|
118 | 119 | Role.anonymous.update_attribute :permissions, [:view_issues, |
|
119 | 120 | :view_gantt, |
|
120 | 121 | :view_calendar, |
|
121 | 122 | :view_time_entries, |
|
122 | 123 | :view_documents, |
|
123 | 124 | :view_wiki_pages, |
|
124 | 125 | :view_wiki_edits, |
|
125 | 126 | :view_files, |
|
126 | 127 | :browse_repository, |
|
127 | 128 | :view_changesets] |
|
128 | 129 | |
|
129 | 130 | # Issue statuses |
|
130 | 131 | new = IssueStatus.create!(:name => l(:default_issue_status_new), :is_closed => false, :position => 1) |
|
131 | 132 | in_progress = IssueStatus.create!(:name => l(:default_issue_status_in_progress), :is_closed => false, :position => 2) |
|
132 | 133 | resolved = IssueStatus.create!(:name => l(:default_issue_status_resolved), :is_closed => false, :position => 3) |
|
133 | 134 | feedback = IssueStatus.create!(:name => l(:default_issue_status_feedback), :is_closed => false, :position => 4) |
|
134 | 135 | closed = IssueStatus.create!(:name => l(:default_issue_status_closed), :is_closed => true, :position => 5) |
|
135 | 136 | rejected = IssueStatus.create!(:name => l(:default_issue_status_rejected), :is_closed => true, :position => 6) |
|
136 | 137 | |
|
137 | 138 | # Trackers |
|
138 | 139 | Tracker.create!(:name => l(:default_tracker_bug), :default_status_id => new.id, :is_in_chlog => true, :is_in_roadmap => false, :position => 1) |
|
139 | 140 | Tracker.create!(:name => l(:default_tracker_feature), :default_status_id => new.id, :is_in_chlog => true, :is_in_roadmap => true, :position => 2) |
|
140 | 141 | Tracker.create!(:name => l(:default_tracker_support), :default_status_id => new.id, :is_in_chlog => false, :is_in_roadmap => false, :position => 3) |
|
141 | 142 | |
|
142 |
|
|
|
143 | Tracker.all.each { |t| | |
|
144 |
|
|
|
145 |
IssueStatus.all.each { | |
|
|
146 | WorkflowTransition.create!(:tracker_id => t.id, :role_id => manager.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | |
|
143 | if workflow | |
|
144 | # Workflow | |
|
145 | Tracker.all.each { |t| | |
|
146 | IssueStatus.all.each { |os| | |
|
147 | IssueStatus.all.each { |ns| | |
|
148 | WorkflowTransition.create!(:tracker_id => t.id, :role_id => manager.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | |
|
149 | } | |
|
147 | 150 | } |
|
148 | 151 | } |
|
149 | } | |
|
150 | 152 | |
|
151 | Tracker.all.each { |t| | |
|
152 | [new, in_progress, resolved, feedback].each { |os| | |
|
153 | [in_progress, resolved, feedback, closed].each { |ns| | |
|
154 | WorkflowTransition.create!(:tracker_id => t.id, :role_id => developer.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | |
|
153 | Tracker.all.each { |t| | |
|
154 | [new, in_progress, resolved, feedback].each { |os| | |
|
155 | [in_progress, resolved, feedback, closed].each { |ns| | |
|
156 | WorkflowTransition.create!(:tracker_id => t.id, :role_id => developer.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | |
|
157 | } | |
|
155 | 158 | } |
|
156 | 159 | } |
|
157 | } | |
|
158 | 160 | |
|
159 | Tracker.all.each { |t| | |
|
160 | [new, in_progress, resolved, feedback].each { |os| | |
|
161 | [closed].each { |ns| | |
|
162 | WorkflowTransition.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | |
|
161 | Tracker.all.each { |t| | |
|
162 | [new, in_progress, resolved, feedback].each { |os| | |
|
163 | [closed].each { |ns| | |
|
164 | WorkflowTransition.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | |
|
165 | } | |
|
163 | 166 | } |
|
167 | WorkflowTransition.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => resolved.id, :new_status_id => feedback.id) | |
|
164 | 168 | } |
|
165 | WorkflowTransition.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => resolved.id, :new_status_id => feedback.id) | |
|
166 | } | |
|
169 | end | |
|
167 | 170 | |
|
168 | 171 | # Enumerations |
|
169 | 172 | IssuePriority.create!(:name => l(:default_priority_low), :position => 1) |
|
170 | 173 | IssuePriority.create!(:name => l(:default_priority_normal), :position => 2, :is_default => true) |
|
171 | 174 | IssuePriority.create!(:name => l(:default_priority_high), :position => 3) |
|
172 | 175 | IssuePriority.create!(:name => l(:default_priority_urgent), :position => 4) |
|
173 | 176 | IssuePriority.create!(:name => l(:default_priority_immediate), :position => 5) |
|
174 | 177 | |
|
175 | 178 | DocumentCategory.create!(:name => l(:default_doc_category_user), :position => 1) |
|
176 | 179 | DocumentCategory.create!(:name => l(:default_doc_category_tech), :position => 2) |
|
177 | 180 | |
|
178 | 181 | TimeEntryActivity.create!(:name => l(:default_activity_design), :position => 1) |
|
179 | 182 | TimeEntryActivity.create!(:name => l(:default_activity_development), :position => 2) |
|
180 | 183 | end |
|
181 | 184 | true |
|
182 | 185 | end |
|
183 | 186 | end |
|
184 | 187 | end |
|
185 | 188 | end |
|
186 | 189 | end |
@@ -1,49 +1,60 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 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.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class DefaultDataTest < ActiveSupport::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 | Role.where("builtin = 0").delete_all | |
|
27 | Tracker.delete_all | |
|
28 | IssueStatus.delete_all | |
|
29 | Enumeration.delete_all | |
|
26 | clear_data | |
|
30 | 27 | assert Redmine::DefaultData::Loader::no_data? |
|
31 | 28 | end |
|
32 | 29 | |
|
33 | 30 | def test_load |
|
31 | clear_data | |
|
32 | assert Redmine::DefaultData::Loader::load('en') | |
|
33 | assert_not_nil DocumentCategory.first | |
|
34 | assert_not_nil IssuePriority.first | |
|
35 | assert_not_nil TimeEntryActivity.first | |
|
36 | assert_not_nil WorkflowTransition.first | |
|
37 | end | |
|
38 | ||
|
39 | def test_load_for_all_language | |
|
34 | 40 | valid_languages.each do |lang| |
|
41 | clear_data | |
|
35 | 42 | begin |
|
36 | Role.where("builtin = 0").delete_all | |
|
37 | Tracker.delete_all | |
|
38 | IssueStatus.delete_all | |
|
39 | Enumeration.delete_all | |
|
40 | assert Redmine::DefaultData::Loader::load(lang) | |
|
43 | assert Redmine::DefaultData::Loader::load(lang, :workflow => false) | |
|
41 | 44 | assert_not_nil DocumentCategory.first |
|
42 | 45 | assert_not_nil IssuePriority.first |
|
43 | 46 | assert_not_nil TimeEntryActivity.first |
|
44 | 47 | rescue ActiveRecord::RecordInvalid => e |
|
45 | 48 | assert false, ":#{lang} default data is invalid (#{e.message})." |
|
46 | 49 | end |
|
47 | 50 | end |
|
48 | 51 | end |
|
52 | ||
|
53 | def clear_data | |
|
54 | Role.where("builtin = 0").delete_all | |
|
55 | Tracker.delete_all | |
|
56 | IssueStatus.delete_all | |
|
57 | Enumeration.delete_all | |
|
58 | WorkflowRule.delete_all | |
|
59 | end | |
|
49 | 60 | end |
General Comments 0
You need to be logged in to leave comments.
Login now