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