annotate .svn/pristine/4d/4d9d3fdde67f50593ece400431e5e5bc47ab9808.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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