Module: Redmine::DefaultData::Loader

Includes:
I18n
Defined in:
lib/redmine/default_data/loader.rb

Class Method Summary collapse

Methods included from I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, included, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Class Method Details

.load(lang = nil, options = {}) ⇒ Object

Loads the default data Raises a RecordNotSaved exception if something goes wrong

Raises:


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/redmine/default_data/loader.rb', line 40

def load(lang=nil, options={})
  raise DataAlreadyLoaded.new("Some configuration data is already loaded.") unless no_data?
  set_language_if_valid(lang)
  workflow = !(options[:workflow] == false)

  Role.transaction do
    # Roles
    manager = Role.create! :name => l(:default_role_manager),
                           :issues_visibility => 'all',
                           :users_visibility => 'all',
                           :position => 1
    manager.permissions = manager.setable_permissions.collect {|p| p.name}
    manager.save!

    developer = Role.create!(
                             :name => l(:default_role_developer),
                             :position => 2,
                             :permissions => [:manage_versions,
                                              :manage_categories,
                                              :view_issues,
                                              :add_issues,
                                              :edit_issues,
                                              :view_private_notes,
                                              :set_notes_private,
                                              :manage_issue_relations,
                                              :manage_subtasks,
                                              :add_issue_notes,
                                              :save_queries,
                                              :view_gantt,
                                              :view_calendar,
                                              :log_time,
                                              :view_time_entries,
                                              :view_news,
                                              :comment_news,
                                              :view_documents,
                                              :view_wiki_pages,
                                              :view_wiki_edits,
                                              :edit_wiki_pages,
                                              :delete_wiki_pages,
                                              :view_messages,
                                              :add_messages,
                                              :edit_own_messages,
                                              :view_files,
                                              :manage_files,
                                              :browse_repository,
                                              :view_changesets,
                                              :commit_access,
                                              :manage_related_issues])
    reporter = Role.create!(
                           :name => l(:default_role_reporter),
                           :position => 3,
                           :permissions => [:view_issues,
                                            :add_issues,
                                            :add_issue_notes,
                                            :save_queries,
                                            :view_gantt,
                                            :view_calendar,
                                            :log_time,
                                            :view_time_entries,
                                            :view_news,
                                            :comment_news,
                                            :view_documents,
                                            :view_wiki_pages,
                                            :view_wiki_edits,
                                            :view_messages,
                                            :add_messages,
                                            :edit_own_messages,
                                            :view_files,
                                            :browse_repository,
                                            :view_changesets])

    Role.non_member.update_attribute :permissions, [:view_issues,
                                                    :add_issues,
                                                    :add_issue_notes,
                                                    :save_queries,
                                                    :view_gantt,
                                                    :view_calendar,
                                                    :view_time_entries,
                                                    :view_news,
                                                    :comment_news,
                                                    :view_documents,
                                                    :view_wiki_pages,
                                                    :view_wiki_edits,
                                                    :view_messages,
                                                    :add_messages,
                                                    :view_files,
                                                    :browse_repository,
                                                    :view_changesets]

    Role.anonymous.update_attribute :permissions, [:view_issues,
                                                   :view_gantt,
                                                   :view_calendar,
                                                   :view_time_entries,
                                                   :view_news,
                                                   :view_documents,
                                                   :view_wiki_pages,
                                                   :view_wiki_edits,
                                                   :view_messages,
                                                   :view_files,
                                                   :browse_repository,
                                                   :view_changesets]

    # Issue statuses
    new       = IssueStatus.create!(:name => l(:default_issue_status_new), :is_closed => false, :position => 1)
    in_progress  = IssueStatus.create!(:name => l(:default_issue_status_in_progress), :is_closed => false, :position => 2)
    resolved  = IssueStatus.create!(:name => l(:default_issue_status_resolved), :is_closed => false, :position => 3)
    feedback  = IssueStatus.create!(:name => l(:default_issue_status_feedback), :is_closed => false, :position => 4)
    closed    = IssueStatus.create!(:name => l(:default_issue_status_closed), :is_closed => true, :position => 5)
    rejected  = IssueStatus.create!(:name => l(:default_issue_status_rejected), :is_closed => true, :position => 6)

    # Trackers
    Tracker.create!(:name => l(:default_tracker_bug),     :default_status_id => new.id, :is_in_chlog => true,  :is_in_roadmap => false, :position => 1)
    Tracker.create!(:name => l(:default_tracker_feature), :default_status_id => new.id, :is_in_chlog => true,  :is_in_roadmap => true,  :position => 2)
    Tracker.create!(:name => l(:default_tracker_support), :default_status_id => new.id, :is_in_chlog => false, :is_in_roadmap => false, :position => 3)

    if workflow
      # Workflow
      Tracker.all.each { |t|
        IssueStatus.all.each { |os|
          IssueStatus.all.each { |ns|
            WorkflowTransition.create!(:tracker_id => t.id, :role_id => manager.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns
          }
        }
      }

      Tracker.all.each { |t|
        [new, in_progress, resolved, feedback].each { |os|
          [in_progress, resolved, feedback, closed].each { |ns|
            WorkflowTransition.create!(:tracker_id => t.id, :role_id => developer.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns
          }
        }
      }

      Tracker.all.each { |t|
        [new, in_progress, resolved, feedback].each { |os|
          [closed].each { |ns|
            WorkflowTransition.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns
          }
        }
        WorkflowTransition.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => resolved.id, :new_status_id => feedback.id)
      }
    end

    # Enumerations
    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)

    DocumentCategory.create!(:name => l(:default_doc_category_user), :position => 1)
    DocumentCategory.create!(:name => l(:default_doc_category_tech), :position => 2)

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

    # Issue queries
    IssueQuery.create!(
      :name => l(:label_assigned_to_me_issues),
      :filters =>
        {
          'status_id' => {:operator => 'o', :values => ['']},
          'assigned_to_id' => {:operator => '=', :values => ['me']},
          'project.status' => {:operator => '=', :values => ['1']}
        },
      :sort_criteria => [['priority', 'desc'], ['updated_on', 'desc']],
      :visibility => Query::VISIBILITY_PUBLIC
    )
    IssueQuery.create!(
      :name => l(:label_reported_issues),
      :filters =>
        {
          'status_id' => {:operator => 'o', :values => ['']},
          'author_id' => {:operator => '=', :values => ['me']},
          'project.status' => {:operator => '=', :values => ['1']}
        },
      :sort_criteria => [['updated_on', 'desc']],
      :visibility => Query::VISIBILITY_PUBLIC
    )
    IssueQuery.create!(
      :name => l(:label_updated_issues),
      :filters =>
        {
          'status_id' => {:operator => 'o', :values => ['']},
          'updated_by' => {:operator => '=', :values => ['me']},
          'project.status' => {:operator => '=', :values => ['1']}
        },
      :sort_criteria => [['updated_on', 'desc']],
      :visibility => Query::VISIBILITY_PUBLIC
    )
    IssueQuery.create!(
      :name => l(:label_watched_issues),
      :filters =>
        {
          'status_id' => {:operator => 'o', :values => ['']},
          'watcher_id' => {:operator => '=', :values => ['me']},
          'project.status' => {:operator => '=', :values => ['1']},
        },
      :sort_criteria => [['updated_on', 'desc']],
      :visibility => Query::VISIBILITY_PUBLIC
    )

    # Project queries
    ProjectQuery.create!(
      :name => l(:label_my_projects),
      :filters =>
        {
          'status' => {:operator => '=', :values => ['1']},
          'id' => {:operator => '=', :values => ['mine']}
        },
      :visibility => Query::VISIBILITY_PUBLIC
    )
    ProjectQuery.create!(
      :name => l(:label_my_bookmarks),
      :filters =>
        {
          'status' => {:operator => '=', :values => ['1']},
          'id' => {:operator => '=', :values => ['bookmarks']}
        },
      :visibility => Query::VISIBILITY_PUBLIC
    )

    # Time entry queries
    TimeEntryQuery.create!(
      :name => l(:label_spent_time),
      :filters =>
        {
          'spent_on' => {:operator => '*', :values => ['']},
          'user_id' => {:operator => '=', :values => ['me']}
        },
      :sort_criteria => [['spent_on', 'desc']],
      :options => {:totalable_names => [:hours]},
      :visibility => Query::VISIBILITY_PUBLIC
    )
  end
  true
end

.no_data?Boolean

Returns true if no data is already loaded in the database otherwise false

Returns:

  • (Boolean)

30
31
32
33
34
35
36
# File 'lib/redmine/default_data/loader.rb', line 30

def no_data?
  !Role.where(:builtin => 0).exists? &&
    !Tracker.exists? &&
    !IssueStatus.exists? &&
    !Enumeration.exists? &&
    !Query.exists?
end