-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathredmine_dmsf.rb
297 lines (255 loc) · 10.4 KB
/
redmine_dmsf.rb
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
# frozen_string_literal: true
# Redmine plugin for Document Management System "Features"
#
#
# 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.
# Main module
module RedmineDmsf
# Settings
class << self
def dmsf_max_file_download
Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i
end
def dmsf_max_email_filesize
Setting.plugin_redmine_dmsf['dmsf_max_email_filesize'].to_i
end
def dmsf_storage_directory
if Setting.plugin_redmine_dmsf['dmsf_storage_directory'].present?
Setting.plugin_redmine_dmsf['dmsf_storage_directory'].strip
else
'files/dmsf'
end
end
def dmsf_index_database
if Setting.plugin_redmine_dmsf['dmsf_index_database'].present?
Setting.plugin_redmine_dmsf['dmsf_index_database'].strip
else
File.expand_path('dmsf_index', Rails.root)
end
end
def dmsf_stemming_lang
if Setting.plugin_redmine_dmsf['dmsf_stemming_lang'].present?
Setting.plugin_redmine_dmsf['dmsf_stemming_lang'].strip
else
'english'
end
end
def dmsf_stemming_strategy
if Setting.plugin_redmine_dmsf['dmsf_stemming_strategy'].present?
Setting.plugin_redmine_dmsf['dmsf_stemming_strategy'].strip
else
'STEM_NONE'
end
end
def dmsf_webdav?
value = Setting.plugin_redmine_dmsf['dmsf_webdav']
value.to_i.positive? || value == 'true'
end
def dmsf_display_notified_recipients?
value = Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
value.to_i.positive? || value == 'true'
end
def dmsf_global_title_format
if Setting.plugin_redmine_dmsf['dmsf_global_title_format'].present?
Setting.plugin_redmine_dmsf['dmsf_global_title_format'].strip
else
''
end
end
def dmsf_columns
Setting.plugin_redmine_dmsf['dmsf_columns'].presence || DmsfFolder::DEFAULT_COLUMNS
end
def dmsf_webdav_ignore
if Setting.plugin_redmine_dmsf['dmsf_webdav_ignore'].present?
Setting.plugin_redmine_dmsf['dmsf_webdav_ignore'].strip
else
'^(\._|\.DS_Store$|Thumbs.db$)'
end
end
def dmsf_webdav_disable_versioning
if Setting.plugin_redmine_dmsf['dmsf_webdav_disable_versioning'].present?
Setting.plugin_redmine_dmsf['dmsf_webdav_disable_versioning'].strip
else
'^\~\$|\.tmp$'
end
end
def dmsf_keep_documents_locked?
value = Setting.plugin_redmine_dmsf['dmsf_keep_documents_locked']
value.to_i.positive? || value == 'true'
end
def dmsf_act_as_attachable?
value = Setting.plugin_redmine_dmsf['dmsf_act_as_attachable?']
value.to_i.positive? || value == 'true'
end
def dmsf_documents_email_from
if Setting.plugin_redmine_dmsf['dmsf_documents_email_from'].present?
Setting.plugin_redmine_dmsf['dmsf_documents_email_from'].strip
else
"#{User.current.name} <#{User.current.mail}>"
end
end
def dmsf_documents_email_reply_to
if Setting.plugin_redmine_dmsf['dmsf_documents_email_reply_to'].present?
Setting.plugin_redmine_dmsf['dmsf_documents_email_reply_to'].strip
else
''
end
end
def dmsf_documents_email_links_only?
value = Setting.plugin_redmine_dmsf['dmsf_documents_email_links_only']
value.to_i.positive? || value == 'true'
end
def dmsf_enable_cjk_ngrams?
value = Setting.plugin_redmine_dmsf['dmsf_enable_cjk_ngrams']
value.to_i.positive? || value == 'true'
end
def dmsf_webdav_use_project_names?
value = Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names']
value.to_i.positive? || value == 'true'
end
def dmsf_webdav_ignore_1b_file_for_authentication?
value = Setting.plugin_redmine_dmsf['dmsf_webdav_ignore_1b_file_for_authentication']
value.to_i.positive? || value == 'true'
end
def dmsf_projects_as_subfolders?
value = Setting.plugin_redmine_dmsf['dmsf_projects_as_subfolders']
value.to_i.positive? || value == 'true'
end
def only_approval_zero_minor_version?
value = Setting.plugin_redmine_dmsf['only_approval_zero_minor_version']
value.to_i.positive? || value == 'true'
end
def dmsf_max_notification_receivers_info
Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i
end
def office_bin
if Setting.plugin_redmine_dmsf['office_bin'].present?
Setting.plugin_redmine_dmsf['office_bin'].strip
else
''
end
end
def dmsf_global_menu_disabled?
value = Setting.plugin_redmine_dmsf['dmsf_global_menu_disabled']
value.to_i.positive? || value == 'true'
end
def dmsf_default_query
Setting.plugin_redmine_dmsf['dmsf_default_query'].to_i
end
def empty_minor_version_by_default?
value = Setting.plugin_redmine_dmsf['empty_minor_version_by_default']
value.to_i.positive? || value == 'true'
end
def remove_original_documents_module?
value = Setting.plugin_redmine_dmsf['remove_original_documents_module']
value.to_i.positive? || value == 'true'
end
def dmsf_webdav_authentication
if Setting.plugin_redmine_dmsf['dmsf_webdav_authentication'].present?
Setting.plugin_redmine_dmsf['dmsf_webdav_authentication'].strip
else
'Basic'
end
end
end
end
# DMSF libraries
def after_easy_init(&block)
if defined?(EasyExtensions)
Rails.application.config.after_initialize(&block)
else
yield
end
end
# Validators
after_easy_init do
require "#{File.dirname(__FILE__)}/../app/validators/dmsf_file_name_validator"
require "#{File.dirname(__FILE__)}/../app/validators/dmsf_max_file_size_validator"
require "#{File.dirname(__FILE__)}/../app/validators/dmsf_workflow_name_validator"
require "#{File.dirname(__FILE__)}/../app/validators/dmsf_url_validator"
require "#{File.dirname(__FILE__)}/../app/validators/dmsf_folder_parent_validator"
end
# Patches
unless defined?(EasyPatchManager)
require "#{File.dirname(__FILE__)}/../patches/formatting_helper_patch"
require "#{File.dirname(__FILE__)}/../patches/projects_helper_patch"
require "#{File.dirname(__FILE__)}/../patches/project_patch"
require "#{File.dirname(__FILE__)}/../patches/user_preference_patch"
require "#{File.dirname(__FILE__)}/../patches/user_patch"
require "#{File.dirname(__FILE__)}/../patches/issue_patch"
require "#{File.dirname(__FILE__)}/../patches/role_patch"
require "#{File.dirname(__FILE__)}/../patches/queries_controller_patch"
require "#{File.dirname(__FILE__)}/../patches/pdf_patch"
require "#{File.dirname(__FILE__)}/../patches/access_control_patch"
require "#{File.dirname(__FILE__)}/../patches/search_patch"
require "#{File.dirname(__FILE__)}/../patches/custom_field_patch"
# A workaround for obsolete 'alias_method' usage in RedmineUp's plugins
if RedmineDmsf::Plugin.an_obsolete_plugin_present?
require "#{File.dirname(__FILE__)}/../patches/notifiable_ru_patch"
else
require "#{File.dirname(__FILE__)}/../patches/notifiable_patch"
end
end
# A workaround for obsolete 'alias_method' usage in RedmineUp's plugins
after_easy_init do
require "#{File.dirname(__FILE__)}/redmine_dmsf/plugin"
end
# Load up classes that make up our WebDAV solution ontop of Dav4rack
after_easy_init do
require "#{File.dirname(__FILE__)}/dav4rack"
require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/custom_middleware"
require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/base_resource"
require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/dmsf_resource"
require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/index_resource"
require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/project_resource"
require "#{File.dirname(__FILE__)}/redmine_dmsf/webdav/resource_proxy"
end
# Errors
after_easy_init do
require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_access_error"
require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_email_max_file_size_error"
require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_file_not_found_error"
require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_lock_error"
require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_zip_max_files_error"
end
# Hooks
def require_hooks
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/controllers/account_controller_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/controllers/issues_controller_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/controllers/search_controller_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/view_projects_form_hook"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/base_view_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/custom_field_view_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/issue_view_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/mailer_view_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/my_account_view_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/search_view_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/issues_helper_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/search_helper_hooks"
require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/project_helper_hooks"
end
after_easy_init do
require_hooks
end
# Macros
after_easy_init do
require "#{File.dirname(__FILE__)}/redmine_dmsf/macros"
end
# Field formats
after_easy_init do
require "#{File.dirname(__FILE__)}/redmine_dmsf/field_formats/dmsf_file_revision_format"
end
require "#{File.dirname(__FILE__)}/easy_page_module" unless defined?(EasyExtensions)