Revision 912:5e80956cc792 lib/redmine/default_data

View differences:

lib/redmine/default_data/loader.rb
5 5
# modify it under the terms of the GNU General Public License
6 6
# as published by the Free Software Foundation; either version 2
7 7
# of the License, or (at your option) any later version.
8
# 
8
#
9 9
# This program is distributed in the hope that it will be useful,
10 10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 12
# GNU General Public License for more details.
13
# 
13
#
14 14
# You should have received a copy of the GNU General Public License
15 15
# along with this program; if not, write to the Free Software
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
......
21 21

  
22 22
    module Loader
23 23
      include Redmine::I18n
24
    
24

  
25 25
      class << self
26 26
        # Returns true if no data is already loaded in the database
27 27
        # otherwise false
......
31 31
            !IssueStatus.find(:first) &&
32 32
            !Enumeration.find(:first)
33 33
        end
34
        
34

  
35 35
        # Loads the default data
36 36
        # Raises a RecordNotSaved exception if something goes wrong
37 37
        def load(lang=nil)
38 38
          raise DataAlreadyLoaded.new("Some configuration data is already loaded.") unless no_data?
39 39
          set_language_if_valid(lang)
40
          
40

  
41 41
          Role.transaction do
42 42
            # Roles
43
            manager = Role.create! :name => l(:default_role_manager), 
43
            manager = Role.create! :name => l(:default_role_manager),
44 44
                                   :issues_visibility => 'all',
45 45
                                   :position => 1
46 46
            manager.permissions = manager.setable_permissions.collect {|p| p.name}
47 47
            manager.save!
48
            
49
            developer = Role.create!  :name => l(:default_role_developer), 
50
                                      :position => 2, 
51
                                      :permissions => [:manage_versions, 
48

  
49
            developer = Role.create!  :name => l(:default_role_developer),
50
                                      :position => 2,
51
                                      :permissions => [:manage_versions,
52 52
                                                      :manage_categories,
53 53
                                                      :view_issues,
54 54
                                                      :add_issues,
......
74 74
                                                      :browse_repository,
75 75
                                                      :view_changesets,
76 76
                                                      :commit_access]
77
            
77

  
78 78
            reporter = Role.create! :name => l(:default_role_reporter),
79 79
                                    :position => 3,
80 80
                                    :permissions => [:view_issues,
......
94 94
                                                    :view_files,
95 95
                                                    :browse_repository,
96 96
                                                    :view_changesets]
97
                        
97

  
98 98
            Role.non_member.update_attribute :permissions, [:view_issues,
99 99
                                                            :add_issues,
100 100
                                                            :add_issue_notes,
......
110 110
                                                            :view_files,
111 111
                                                            :browse_repository,
112 112
                                                            :view_changesets]
113
          
113

  
114 114
            Role.anonymous.update_attribute :permissions, [:view_issues,
115 115
                                                           :view_gantt,
116 116
                                                           :view_calendar,
......
121 121
                                                           :view_files,
122 122
                                                           :browse_repository,
123 123
                                                           :view_changesets]
124
                                                             
124

  
125 125
            # Trackers
126 126
            Tracker.create!(:name => l(:default_tracker_bug),     :is_in_chlog => true,  :is_in_roadmap => false, :position => 1)
127 127
            Tracker.create!(:name => l(:default_tracker_feature), :is_in_chlog => true,  :is_in_roadmap => true,  :position => 2)
128 128
            Tracker.create!(:name => l(:default_tracker_support), :is_in_chlog => false, :is_in_roadmap => false, :position => 3)
129
            
129

  
130 130
            # Issue statuses
131 131
            new       = IssueStatus.create!(:name => l(:default_issue_status_new), :is_closed => false, :is_default => true, :position => 1)
132 132
            in_progress  = IssueStatus.create!(:name => l(:default_issue_status_in_progress), :is_closed => false, :is_default => false, :position => 2)
......
134 134
            feedback  = IssueStatus.create!(:name => l(:default_issue_status_feedback), :is_closed => false, :is_default => false, :position => 4)
135 135
            closed    = IssueStatus.create!(:name => l(:default_issue_status_closed), :is_closed => true, :is_default => false, :position => 5)
136 136
            rejected  = IssueStatus.create!(:name => l(:default_issue_status_rejected), :is_closed => true, :is_default => false, :position => 6)
137
            
137

  
138 138
            # Workflow
139 139
            Tracker.find(:all).each { |t|
140 140
              IssueStatus.find(:all).each { |os|
141 141
                IssueStatus.find(:all).each { |ns|
142 142
                  Workflow.create!(:tracker_id => t.id, :role_id => manager.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns
143
                }        
144
              }      
143
                }
144
              }
145 145
            }
146
            
146

  
147 147
            Tracker.find(:all).each { |t|
148 148
              [new, in_progress, resolved, feedback].each { |os|
149 149
                [in_progress, resolved, feedback, closed].each { |ns|
150 150
                  Workflow.create!(:tracker_id => t.id, :role_id => developer.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns
151
                }        
152
              }      
151
                }
152
              }
153 153
            }
154
            
154

  
155 155
            Tracker.find(:all).each { |t|
156 156
              [new, in_progress, resolved, feedback].each { |os|
157 157
                [closed].each { |ns|
158 158
                  Workflow.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns
159
                }        
159
                }
160 160
              }
161 161
              Workflow.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => resolved.id, :new_status_id => feedback.id)
162 162
            }
163
          
163

  
164 164
            # Enumerations
165 165
            DocumentCategory.create!(:name => l(:default_doc_category_user), :position => 1)
166 166
            DocumentCategory.create!(:name => l(:default_doc_category_tech), :position => 2)
167
          
167

  
168 168
            IssuePriority.create!(:name => l(:default_priority_low), :position => 1)
169 169
            IssuePriority.create!(:name => l(:default_priority_normal), :position => 2, :is_default => true)
170 170
            IssuePriority.create!(:name => l(:default_priority_high), :position => 3)
171 171
            IssuePriority.create!(:name => l(:default_priority_urgent), :position => 4)
172 172
            IssuePriority.create!(:name => l(:default_priority_immediate), :position => 5)
173
          
173

  
174 174
            TimeEntryActivity.create!(:name => l(:default_activity_design), :position => 1)
175 175
            TimeEntryActivity.create!(:name => l(:default_activity_development), :position => 2)
176 176
          end

Also available in: Unified diff