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