| 
									
										
										
										
											2011-04-15 13:23:13 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							|  |  |  | # Copyright (C) 2006-2011  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2008-01-04 18:27:05 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2008-01-04 18:27:05 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2008-01-04 18:27:05 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Redmine | 
					
						
							|  |  |  |   module DefaultData | 
					
						
							|  |  |  |     class DataAlreadyLoaded < Exception; end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     module Loader | 
					
						
							| 
									
										
										
										
											2009-02-21 11:04:50 +00:00
										 |  |  |       include Redmine::I18n | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-04 18:27:05 +00:00
										 |  |  |       class << self | 
					
						
							|  |  |  |         # Returns true if no data is already loaded in the database | 
					
						
							|  |  |  |         # otherwise false | 
					
						
							|  |  |  |         def no_data? | 
					
						
							|  |  |  |           !Role.find(:first, :conditions => {:builtin => 0}) && | 
					
						
							|  |  |  |             !Tracker.find(:first) && | 
					
						
							|  |  |  |             !IssueStatus.find(:first) && | 
					
						
							|  |  |  |             !Enumeration.find(:first) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-04 18:27:05 +00:00
										 |  |  |         # Loads the default data | 
					
						
							|  |  |  |         # Raises a RecordNotSaved exception if something goes wrong | 
					
						
							|  |  |  |         def load(lang=nil) | 
					
						
							|  |  |  |           raise DataAlreadyLoaded.new("Some configuration data is already loaded.") unless no_data? | 
					
						
							|  |  |  |           set_language_if_valid(lang) | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |           Role.transaction do | 
					
						
							|  |  |  |             # Roles | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  |             manager = Role.create! :name => l(:default_role_manager), | 
					
						
							| 
									
										
										
										
											2011-04-15 13:23:13 +00:00
										 |  |  |                                    :issues_visibility => 'all', | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                                    :position => 1
 | 
					
						
							|  |  |  |             manager.permissions = manager.setable_permissions.collect {|p| p.name} | 
					
						
							|  |  |  |             manager.save! | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             developer = Role.create!  :name => l(:default_role_developer), | 
					
						
							|  |  |  |                                       :position => 2, | 
					
						
							|  |  |  |                                       :permissions => [:manage_versions, | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                                                       :manage_categories, | 
					
						
							| 
									
										
										
										
											2009-11-14 12:08:47 +00:00
										 |  |  |                                                       :view_issues, | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                                                       :add_issues, | 
					
						
							|  |  |  |                                                       :edit_issues, | 
					
						
							|  |  |  |                                                       :manage_issue_relations, | 
					
						
							| 
									
										
										
										
											2010-03-13 14:56:49 +00:00
										 |  |  |                                                       :manage_subtasks, | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                                                       :add_issue_notes, | 
					
						
							|  |  |  |                                                       :save_queries, | 
					
						
							|  |  |  |                                                       :view_gantt, | 
					
						
							|  |  |  |                                                       :view_calendar, | 
					
						
							|  |  |  |                                                       :log_time, | 
					
						
							|  |  |  |                                                       :view_time_entries, | 
					
						
							|  |  |  |                                                       :comment_news, | 
					
						
							|  |  |  |                                                       :view_documents, | 
					
						
							|  |  |  |                                                       :view_wiki_pages, | 
					
						
							| 
									
										
										
										
											2008-09-14 10:54:19 +00:00
										 |  |  |                                                       :view_wiki_edits, | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                                                       :edit_wiki_pages, | 
					
						
							|  |  |  |                                                       :delete_wiki_pages, | 
					
						
							|  |  |  |                                                       :add_messages, | 
					
						
							| 
									
										
										
										
											2008-11-11 15:07:55 +00:00
										 |  |  |                                                       :edit_own_messages, | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                                                       :view_files, | 
					
						
							|  |  |  |                                                       :manage_files, | 
					
						
							|  |  |  |                                                       :browse_repository, | 
					
						
							| 
									
										
										
										
											2008-09-13 16:31:11 +00:00
										 |  |  |                                                       :view_changesets, | 
					
						
							|  |  |  |                                                       :commit_access] | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |             reporter = Role.create! :name => l(:default_role_reporter), | 
					
						
							|  |  |  |                                     :position => 3, | 
					
						
							| 
									
										
										
										
											2009-11-14 12:08:47 +00:00
										 |  |  |                                     :permissions => [:view_issues, | 
					
						
							|  |  |  |                                                     :add_issues, | 
					
						
							| 
									
										
										
										
											2008-01-04 18:27:05 +00:00
										 |  |  |                                                     :add_issue_notes, | 
					
						
							|  |  |  |                                                     :save_queries, | 
					
						
							|  |  |  |                                                     :view_gantt, | 
					
						
							|  |  |  |                                                     :view_calendar, | 
					
						
							|  |  |  |                                                     :log_time, | 
					
						
							|  |  |  |                                                     :view_time_entries, | 
					
						
							|  |  |  |                                                     :comment_news, | 
					
						
							|  |  |  |                                                     :view_documents, | 
					
						
							|  |  |  |                                                     :view_wiki_pages, | 
					
						
							| 
									
										
										
										
											2008-09-14 10:54:19 +00:00
										 |  |  |                                                     :view_wiki_edits, | 
					
						
							| 
									
										
										
										
											2008-01-04 18:27:05 +00:00
										 |  |  |                                                     :add_messages, | 
					
						
							| 
									
										
										
										
											2008-11-11 15:07:55 +00:00
										 |  |  |                                                     :edit_own_messages, | 
					
						
							| 
									
										
										
										
											2008-01-04 18:27:05 +00:00
										 |  |  |                                                     :view_files, | 
					
						
							|  |  |  |                                                     :browse_repository, | 
					
						
							|  |  |  |                                                     :view_changesets] | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-14 12:08:47 +00:00
										 |  |  |             Role.non_member.update_attribute :permissions, [:view_issues, | 
					
						
							|  |  |  |                                                             :add_issues, | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                                                             :add_issue_notes, | 
					
						
							|  |  |  |                                                             :save_queries, | 
					
						
							|  |  |  |                                                             :view_gantt, | 
					
						
							|  |  |  |                                                             :view_calendar, | 
					
						
							|  |  |  |                                                             :view_time_entries, | 
					
						
							|  |  |  |                                                             :comment_news, | 
					
						
							|  |  |  |                                                             :view_documents, | 
					
						
							|  |  |  |                                                             :view_wiki_pages, | 
					
						
							| 
									
										
										
										
											2008-09-14 10:54:19 +00:00
										 |  |  |                                                             :view_wiki_edits, | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                                                             :add_messages, | 
					
						
							|  |  |  |                                                             :view_files, | 
					
						
							|  |  |  |                                                             :browse_repository, | 
					
						
							|  |  |  |                                                             :view_changesets] | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-14 12:08:47 +00:00
										 |  |  |             Role.anonymous.update_attribute :permissions, [:view_issues, | 
					
						
							|  |  |  |                                                            :view_gantt, | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                                                            :view_calendar, | 
					
						
							|  |  |  |                                                            :view_time_entries, | 
					
						
							|  |  |  |                                                            :view_documents, | 
					
						
							|  |  |  |                                                            :view_wiki_pages, | 
					
						
							| 
									
										
										
										
											2008-09-14 10:54:19 +00:00
										 |  |  |                                                            :view_wiki_edits, | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                                                            :view_files, | 
					
						
							|  |  |  |                                                            :browse_repository, | 
					
						
							|  |  |  |                                                            :view_changesets] | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |             # Trackers | 
					
						
							|  |  |  |             Tracker.create!(:name => l(:default_tracker_bug),     :is_in_chlog => true,  :is_in_roadmap => false, :position => 1) | 
					
						
							|  |  |  |             Tracker.create!(:name => l(:default_tracker_feature), :is_in_chlog => true,  :is_in_roadmap => true,  :position => 2) | 
					
						
							|  |  |  |             Tracker.create!(:name => l(:default_tracker_support), :is_in_chlog => false, :is_in_roadmap => false, :position => 3) | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |             # Issue statuses | 
					
						
							|  |  |  |             new       = IssueStatus.create!(:name => l(:default_issue_status_new), :is_closed => false, :is_default => true, :position => 1) | 
					
						
							| 
									
										
										
										
											2009-10-20 05:06:14 +00:00
										 |  |  |             in_progress  = IssueStatus.create!(:name => l(:default_issue_status_in_progress), :is_closed => false, :is_default => false, :position => 2) | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |             resolved  = IssueStatus.create!(:name => l(:default_issue_status_resolved), :is_closed => false, :is_default => false, :position => 3) | 
					
						
							|  |  |  |             feedback  = IssueStatus.create!(:name => l(:default_issue_status_feedback), :is_closed => false, :is_default => false, :position => 4) | 
					
						
							|  |  |  |             closed    = IssueStatus.create!(:name => l(:default_issue_status_closed), :is_closed => true, :is_default => false, :position => 5) | 
					
						
							|  |  |  |             rejected  = IssueStatus.create!(:name => l(:default_issue_status_rejected), :is_closed => true, :is_default => false, :position => 6) | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |             # Workflow | 
					
						
							|  |  |  |             Tracker.find(:all).each { |t| | 
					
						
							|  |  |  |               IssueStatus.find(:all).each { |os| | 
					
						
							|  |  |  |                 IssueStatus.find(:all).each { |ns| | 
					
						
							|  |  |  |                   Workflow.create!(:tracker_id => t.id, :role_id => manager.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |             Tracker.find(:all).each { |t| | 
					
						
							| 
									
										
										
										
											2009-10-20 05:06:14 +00:00
										 |  |  |               [new, in_progress, resolved, feedback].each { |os| | 
					
						
							|  |  |  |                 [in_progress, resolved, feedback, closed].each { |ns| | 
					
						
							| 
									
										
										
										
											2010-06-30 01:55:44 +00:00
										 |  |  |                   Workflow.create!(:tracker_id => t.id, :role_id => developer.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |             Tracker.find(:all).each { |t| | 
					
						
							| 
									
										
										
										
											2009-10-20 05:06:14 +00:00
										 |  |  |               [new, in_progress, resolved, feedback].each { |os| | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |                 [closed].each { |ns| | 
					
						
							|  |  |  |                   Workflow.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |               } | 
					
						
							|  |  |  |               Workflow.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => resolved.id, :new_status_id => feedback.id) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |             # Enumerations | 
					
						
							| 
									
										
										
										
											2009-12-25 17:13:58 +00:00
										 |  |  |             DocumentCategory.create!(:name => l(:default_doc_category_user), :position => 1) | 
					
						
							|  |  |  |             DocumentCategory.create!(:name => l(:default_doc_category_tech), :position => 2) | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-25 17:13:58 +00:00
										 |  |  |             IssuePriority.create!(:name => l(:default_priority_low), :position => 1) | 
					
						
							|  |  |  |             IssuePriority.create!(:name => l(:default_priority_normal), :position => 2, :is_default => true) | 
					
						
							|  |  |  |             IssuePriority.create!(:name => l(:default_priority_high), :position => 3) | 
					
						
							|  |  |  |             IssuePriority.create!(:name => l(:default_priority_urgent), :position => 4) | 
					
						
							|  |  |  |             IssuePriority.create!(:name => l(:default_priority_immediate), :position => 5) | 
					
						
							| 
									
										
										
										
											2011-09-01 02:05:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-25 17:13:58 +00:00
										 |  |  |             TimeEntryActivity.create!(:name => l(:default_activity_design), :position => 1) | 
					
						
							|  |  |  |             TimeEntryActivity.create!(:name => l(:default_activity_development), :position => 2) | 
					
						
							| 
									
										
										
										
											2008-01-05 11:33:49 +00:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2008-01-04 18:27:05 +00:00
										 |  |  |           true | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |