summaryrefslogtreecommitdiffstats
path: root/lib/redmine.rb
blob: 9ecca63c325aa9197758541e0d3a16d9d86ec0ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# frozen_string_literal: true

# Redmine - project management software
# Copyright (C) 2006-2019  Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

require 'redmine/core_ext'

begin
  require 'mini_magick' unless Object.const_defined?(:MiniMagick)
rescue LoadError
  # MiniMagick is not available
end
begin
  require 'redcarpet' unless Object.const_defined?(:Redcarpet)
rescue LoadError
  # Redcarpet is not available
end

require 'redmine/acts/positioned'

require 'redmine/scm/base'
require 'redmine/access_control'
require 'redmine/access_keys'
require 'redmine/activity'
require 'redmine/activity/fetcher'
require 'redmine/ciphering'
require 'redmine/codeset_util'
require 'redmine/field_format'
require 'redmine/info'
require 'redmine/menu_manager'
require 'redmine/notifiable'
require 'redmine/platform'
require 'redmine/project_jump_box'
require 'redmine/mime_type'
require 'redmine/search'
require 'redmine/syntax_highlighting'
require 'redmine/thumbnail'
require 'redmine/unified_diff'
require 'redmine/utils'
require 'redmine/version'
require 'redmine/wiki_formatting'

require 'redmine/default_data/loader'
require 'redmine/helpers/calendar'
require 'redmine/helpers/diff'
require 'redmine/helpers/gantt'
require 'redmine/helpers/time_report'
require 'redmine/views/other_formats_builder'
require 'redmine/views/labelled_form_builder'
require 'redmine/views/builders'

require 'redmine/themes'
require 'redmine/hook'
require 'redmine/hook/listener'
require 'redmine/hook/view_listener'
require 'redmine/plugin'

Redmine::Scm::Base.add "Subversion"
Redmine::Scm::Base.add "Mercurial"
Redmine::Scm::Base.add "Cvs"
Redmine::Scm::Base.add "Bazaar"
Redmine::Scm::Base.add "Git"
Redmine::Scm::Base.add "Filesystem"

# Permissions
Redmine::AccessControl.map do |map|
  map.permission :view_project, {:projects => [:show, :bookmark], :activities => [:index]}, :public => true, :read => true
  map.permission :search_project, {:search => :index}, :public => true, :read => true
  map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
  map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
  map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true
  map.permission :select_project_modules, {:projects => :modules}, :require => :member
  map.permission :view_members, {:members => [:index, :show]}, :public => true, :read => true
  map.permission :manage_members, {:projects => :settings, :members => [:index, :show, :new, :create, :edit, :update, :destroy, :autocomplete]}, :require => :member
  map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member
  map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
  # Queries
  map.permission :manage_public_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :member
  map.permission :save_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin

  map.project_module :issue_tracking do |map|
    # Issues
    map.permission :view_issues, {:issues => [:index, :show, :issue_tab],
                                  :auto_complete => [:issues],
                                  :context_menus => [:issues],
                                  :versions => [:index, :show, :status_by],
                                  :journals => [:index, :diff],
                                  :queries => :index,
                                  :reports => [:issue_report, :issue_report_details]},
                   :read => true
    map.permission :add_issues, {:issues => [:new, :create], :attachments => :upload}
    map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update], :journals => [:new], :attachments => :upload}
    map.permission :edit_own_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update], :journals => [:new], :attachments => :upload}
    map.permission :copy_issues, {:issues => [:new, :create, :bulk_edit, :bulk_update], :attachments => :upload}
    map.permission :manage_issue_relations, {:issue_relations => [:index, :show, :create, :destroy]}
    map.permission :manage_subtasks, {}
    map.permission :set_issues_private, {}
    map.permission :set_own_issues_private, {}, :require => :loggedin
    map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload}
    map.permission :edit_issue_notes, {:journals => [:edit, :update]}, :require => :loggedin
    map.permission :edit_own_issue_notes, {:journals => [:edit, :update]}, :require => :loggedin
    map.permission :view_private_notes, {}, :read => true, :require => :member
    map.permission :set_notes_private, {}, :require => :member
    map.permission :delete_issues, {:issues => :destroy}, :require => :member
    # Watchers
    map.permission :view_issue_watchers, {}, :read => true
    map.permission :add_issue_watchers, {:watchers => [:new, :create, :append, :autocomplete_for_user]}
    map.permission :delete_issue_watchers, {:watchers => :destroy}
    map.permission :import_issues, {}
    # Issue categories
    map.permission :manage_categories, {:projects => :settings, :issue_categories => [:index, :show, :new, :create, :edit, :update, :destroy]}, :require => :member
  end

  map.project_module :time_tracking do |map|
    map.permission :view_time_entries, {:timelog => [:index, :report, :show]}, :read => true
    map.permission :log_time, {:timelog => [:new, :create]}, :require => :loggedin
    map.permission :edit_time_entries, {:timelog => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member
    map.permission :edit_own_time_entries, {:timelog => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin
    map.permission :manage_project_activities, {:projects => :settings, :project_enumerations => [:update, :destroy]}, :require => :member
    map.permission :log_time_for_other_users, :require => :member
    map.permission :import_time_entries, {}
  end

  map.project_module :news do |map|
    map.permission :view_news, {:news => [:index, :show]}, :read => true
    map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy], :attachments => :upload}, :require => :member
    map.permission :comment_news, {:comments => :create}
  end

  map.project_module :documents do |map|
    map.permission :view_documents, {:documents => [:index, :show, :download]}, :read => true
    map.permission :add_documents, {:documents => [:new, :create, :add_attachment], :attachments => :upload}, :require => :loggedin
    map.permission :edit_documents, {:documents => [:edit, :update, :add_attachment], :attachments => :upload}, :require => :loggedin
    map.permission :delete_documents, {:documents => [:destroy]}, :require => :loggedin
  end

  map.project_module :files do |map|
    map.permission :view_files, {:files => :index, :versions => :download}, :read => true
    map.permission :manage_files, {:files => [:new, :create], :attachments => :upload}, :require => :loggedin
  end

  map.project_module :wiki do |map|
    map.permission :view_wiki_pages, {:wiki => [:index, :show, :special, :date_index]}, :read => true
    map.permission :view_wiki_edits, {:wiki => [:history, :diff, :annotate]}, :read => true
    map.permission :export_wiki_pages, {:wiki => [:export]}, :read => true
    map.permission :edit_wiki_pages, :wiki => [:new, :edit, :update, :preview, :add_attachment], :attachments => :upload
    map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
    map.permission :delete_wiki_pages, {:wiki => [:destroy, :destroy_version]}, :require => :member
    map.permission :delete_wiki_pages_attachments, {}
    map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member
    map.permission :manage_wiki, {:wikis => [:edit, :destroy], :wiki => :rename}, :require => :member
  end

  map.project_module :repository do |map|
    map.permission :view_changesets, {:repositories => [:show, :revisions, :revision]}, :read => true
    map.permission :browse_repository, {:repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph]}, :read => true
    map.permission :commit_access, {}
    map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}
    map.permission :manage_repository, {:projects => :settings, :repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member
  end

  map.project_module :boards do |map|
    map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :read => true
    map.permission :add_messages, {:messages => [:new, :reply, :quote], :attachments => :upload}
    map.permission :edit_messages, {:messages => :edit, :attachments => :upload}, :require => :member
    map.permission :edit_own_messages, {:messages => :edit, :attachments => :upload}, :require => :loggedin
    map.permission :delete_messages, {:messages => :destroy}, :require => :member
    map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin
    map.permission :manage_boards, {:projects => :settings, :boards => [:new, :create, :edit, :update, :destroy]}, :require => :member
  end

  map.project_module :calendar do |map|
    map.permission :view_calendar, {:calendars => [:show, :update]}, :read => true
  end

  map.project_module :gantt do |map|
    map.permission :view_gantt, {:gantts => [:show, :update]}, :read => true
  end
end

Redmine::MenuManager.map :top_menu do |menu|
  menu.push :home, :home_path
  menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? }
  menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural
  menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true
  menu.push :help, Redmine::Info.help_url, :last => true
end

Redmine::MenuManager.map :account_menu do |menu|
  menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
  menu.push :register, :register_path, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
  menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
  menu.push :logout, :signout_path, :html => {:method => 'post'}, :if => Proc.new { User.current.logged? }
end

Redmine::MenuManager.map :application_menu do |menu|
  menu.push :projects, {:controller => 'projects', :action => 'index'},
            :permission => nil,
            :caption => :label_project_plural
  menu.push :activity, {:controller => 'activities', :action => 'index'}
  menu.push :issues,   {:controller => 'issues', :action => 'index'},
            :if => Proc.new {
                     User.current.allowed_to?(:view_issues, nil, :global => true) &&
                       EnabledModule.exists?(:project => Project.visible, :name => :issue_tracking)
                   },
            :caption => :label_issue_plural
  menu.push :time_entries, {:controller => 'timelog', :action => 'index'},
            :if => Proc.new {
                     User.current.allowed_to?(:view_time_entries, nil, :global => true) &&
                       EnabledModule.exists?(:project => Project.visible, :name => :time_tracking)
                   },
            :caption => :label_spent_time
  menu.push :gantt, { :controller => 'gantts', :action => 'show' },
            :caption => :label_gantt,
            :if => Proc.new {
                     User.current.allowed_to?(:view_gantt, nil, :global => true) &&
                       EnabledModule.exists?(:project => Project.visible, :name => :gantt)
                   }
  menu.push :calendar, { :controller => 'calendars', :action => 'show' },
            :caption => :label_calendar,
            :if => Proc.new {
                     User.current.allowed_to?(:view_calendar, nil, :global => true) &&
                       EnabledModule.exists?(:project => Project.visible, :name => :calendar)
                   }
  menu.push :news, {:controller => 'news', :action => 'index'},
            :if => Proc.new {
                     User.current.allowed_to?(:view_news, nil, :global => true) &&
                       EnabledModule.exists?(:project => Project.visible, :name => :news)
                   },
            :caption => :label_news_plural
end

Redmine::MenuManager.map :admin_menu do |menu|
  menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural,
            :html => {:class => 'icon icon-projects'}
  menu.push :users, {:controller => 'users'}, :caption => :label_user_plural,
            :html => {:class => 'icon icon-user'}
  menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural,
            :html => {:class => 'icon icon-group'}
  menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions,
            :html => {:class => 'icon icon-roles'}
  menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural,
            :html => {:class => 'icon icon-issue'}
  menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural,
            :html => {:class => 'icon icon-issue-edit'}
  menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow,
            :html => {:class => 'icon icon-workflows'}
  menu.push :custom_fields, {:controller => 'custom_fields'},  :caption => :label_custom_field_plural,
            :html => {:class => 'icon icon-custom-fields'}
  menu.push :enumerations, {:controller => 'enumerations'},
            :html => {:class => 'icon icon-list'}
  menu.push :settings, {:controller => 'settings'},
            :html => {:class => 'icon icon-settings'}
  menu.push :ldap_authentication, {:controller => 'auth_sources', :action => 'index'},
            :html => {:class => 'icon icon-server-authentication'}
  menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true,
            :html => {:class => 'icon icon-plugins'}
  menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true,
            :html => {:class => 'icon icon-help'}
end

Redmine::MenuManager.map :project_menu do |menu|
  menu.push :new_object, nil, :caption => ' + ',
            :if => Proc.new { |p| Setting.new_item_menu_tab == '2' },
            :html => { :id => 'new-object', :onclick => 'toggleNewObjectDropdown(); return false;' }
  menu.push :new_issue_sub,
            { :controller => 'issues', :action => 'new', :copy_from => nil },
            :param => :project_id, :caption => :label_issue_new,
            :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) },
            :if => Proc.new { |p| Issue.allowed_target_trackers(p).any? },
            :permission => :add_issues,
            :parent => :new_object
  menu.push :new_issue_category, {:controller => 'issue_categories', :action => 'new'},
            :param => :project_id, :caption => :label_issue_category_new,
            :parent => :new_object
  menu.push :new_version, {:controller => 'versions', :action => 'new'}, :param => :project_id, :caption => :label_version_new,
            :parent => :new_object
  menu.push :new_timelog, {:controller => 'timelog', :action => 'new'}, :param => :project_id, :caption => :button_log_time,
            :parent => :new_object
  menu.push :new_news, {:controller => 'news', :action => 'new'}, :param => :project_id, :caption => :label_news_new,
            :parent => :new_object
  menu.push :new_document, {:controller => 'documents', :action => 'new'}, :param => :project_id, :caption => :label_document_new,
            :parent => :new_object
  menu.push :new_wiki_page, {:controller => 'wiki', :action => 'new'}, :param => :project_id, :caption => :label_wiki_page_new,
            :parent => :new_object
  menu.push :new_file, {:controller => 'files', :action => 'new'}, :param => :project_id, :caption => :label_attachment_new,
            :parent => :new_object

  menu.push :overview, { :controller => 'projects', :action => 'show' }
  menu.push :activity, { :controller => 'activities', :action => 'index' }
  menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id,
            :if => Proc.new { |p| p.shared_versions.any? }
  menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
  menu.push :new_issue, { :controller => 'issues', :action => 'new', :copy_from => nil }, :param => :project_id, :caption => :label_issue_new,
            :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) },
            :if => Proc.new { |p| Setting.new_item_menu_tab == '1' && Issue.allowed_target_trackers(p).any? },
            :permission => :add_issues
  menu.push :time_entries, { :controller => 'timelog', :action => 'index' }, :param => :project_id, :caption => :label_spent_time
  menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt
  menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
  menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
  menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
  menu.push :wiki, { :controller => 'wiki', :action => 'show', :id => nil }, :param => :project_id,
            :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
  menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
            :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
  menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id
  menu.push :repository, { :controller => 'repositories', :action => 'show', :repository_id => nil, :path => nil, :rev => nil },
            :if => Proc.new { |p| p.repository && !p.repository.new_record? }
  menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
end

Redmine::Activity.map do |activity|
  activity.register :issues, :class_name => %w(Issue Journal)
  activity.register :changesets
  activity.register :news
  activity.register :documents, :class_name => %w(Document Attachment)
  activity.register :files, :class_name => 'Attachment'
  activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false
  activity.register :messages, :default => false
  activity.register :time_entries, :default => false
end

Redmine::Search.map do |search|
  search.register :issues
  search.register :news
  search.register :documents
  search.register :changesets
  search.register :wiki_pages
  search.register :messages
  search.register :projects
end

Redmine::WikiFormatting.map do |format|
  format.register :textile
  format.register :markdown if Object.const_defined?(:Redcarpet)
end

ActionView::Template.register_template_handler :rsb, Redmine::Views::ApiTemplateHandler