-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCheck the comment length.xml
69 lines (60 loc) · 3.49 KB
/
Check the comment length.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<custom-workflow>
<after-destroy></after-destroy>
<after-save></after-save>
<author>voronyuk.m@3soft.ru</author>
<before-destroy></before-destroy>
<before-save>
@maxlength = 10000
@signal_label = case I18n.locale.to_s
when 'ru'
"[Этот текст будет удален автоматически при следующем нажатии Создать. Не удаляйте его вручную! (Проверка длины комментария, см. предупреждение выше).]\r"
else
"[This label will be removed during the next submitting. Do not delete or modify it manually! (Check the comment length, see warning above).]\r"
end
need_warning = false
# need to check if notes property is nil or not because when we modify tasks from the issues list it is.
if !@current_journal.nil? && !@current_journal.notes.nil? && @current_journal.notes.length > @maxlength
owner_email = @issue.custom_field_value( CustomField.find_by_name('owner-email') )
user_is_supportclient = false
roles = @current_journal.user.roles_for_project(@issue.project)
# user is a supportclient only if the author has assigned some role with
# permission treat_user_as_supportclient enabled
if roles.any? {|role| role.allowed_to?(:treat_user_as_supportclient) }
user_is_supportclient = true
end
if !@current_journal.notes.include?(@signal_label) && !@current_journal.notes.empty? && !user_is_supportclient && @current_journal.user_id.to_s != '2' && !@issue.instance_variable_defined?(:@updated_by_email)
need_warning = true
@current_journal.notes = @signal_label + @current_journal.notes
else
need_warning = false
@current_journal.notes.sub!(@signal_label, '')
@notes_length = @current_journal.notes.length
@qty_truncated_symbols = @notes_length - @maxlength
@current_journal.notes = @current_journal.notes[0, @maxlength-1] + case I18n.locale.to_s
when 'ru'
"... [оставшиеся #{@qty_truncated_symbols} символа были усечены]"
else
"... [other #{@qty_truncated_symbols} symbols was truncated]"
end
end
end
if need_warning
@warning_message = case I18n.locale.to_s
when 'ru'
"Предупреждение: Ваш комментарий длиннее #@maxlength символов (#{@current_journal.notes.length} символа). Пожалуйста, сократите его, иначе он будет усечен до #@maxlength символа автоматически."
else
"Warning: your note is longer than #@maxlength symbols (#{@current_journal.notes.length} symbols). Please make them shorter, else it will be truncated to #@maxlength symbols automatically. (debug info: locale = " + I18n.locale.to_s + ")"
end
raise WorkflowError, @warning_message
end
</before-save>
<created-at type="datetime">2020-09-04T06:42:27Z</created-at>
<description>if the comment is too long (e.g. >>10000 symbols), the web server may break the connection by timeout.</description>
<name>Check the comment length</name>
<observable>issue</observable>
<exported-at>2020-09-09T12:43:02Z</exported-at>
<plugin-version>0.1.6</plugin-version>
<ruby-version>2.0.0-p648</ruby-version>
<rails-version>3.2.17</rails-version>
</custom-workflow>