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