Allow project-level configuration of posting private issues and notes

This commit is contained in:
Igor Antonov
2016-12-21 10:51:58 +03:00
parent bd88f92a66
commit cc6a036213

View File

@@ -6,30 +6,31 @@ class MattermostListener < Redmine::Hook::Listener
channels = channels_for_project issue.project
url = url_for_project issue.project
post_private_issues = post_private_issues_for_project(issue.project)
return unless channels.any? and url
return if issue.is_private? and Setting.plugin_redmine_mattermost[:post_private_issues] != '1'
return if issue.is_private? and post_private_issues != '1'
msg = "[#{escape issue.project}] #{escape issue.author} created <#{object_url issue}|#{escape issue}>#{mentions issue.description}"
attachment = {}
attachment[:text] = escape issue.description if issue.description
attachment[:fields] = [{
:title => I18n.t("field_status"),
:title => I18n.t(:field_status),
:value => escape(issue.status.to_s),
:short => true
}, {
:title => I18n.t("field_priority"),
:title => I18n.t(:field_priority),
:value => escape(issue.priority.to_s),
:short => true
}, {
:title => I18n.t("field_assigned_to"),
:title => I18n.t(:field_assigned_to),
:value => escape(issue.assigned_to.to_s),
:short => true
}]
attachment[:fields] << {
:title => I18n.t("field_watcher"),
:title => I18n.t(:field_watcher),
:value => escape(issue.watcher_users.join(', ')),
:short => true
} if Setting.plugin_redmine_mattermost[:display_watchers] == 'yes'
@@ -43,10 +44,12 @@ class MattermostListener < Redmine::Hook::Listener
channels = channels_for_project issue.project
url = url_for_project issue.project
post_private_issues = post_private_issues_for_project(issue.project)
post_private_notes = post_private_notes_for_project(issue.project)
return unless channels.any? and url and Setting.plugin_redmine_mattermost[:post_updates] == '1'
return if issue.is_private? and Setting.plugin_redmine_mattermost[:post_private_issues] != '1'
return if journal.private_notes? and Setting.plugin_redmine_mattermost[:post_private_notes] != '1'
return unless channels.any? and url and Setting.plugin_redmine_mattermost[:post_updates] == '1'
return if issue.is_private? and post_private_issues != '1'
return if journal.private_notes? and post_private_notes != '1'
msg = "[#{escape issue.project}] #{escape journal.user.to_s} updated <#{object_url issue}|#{escape issue}>#{mentions journal.notes}"
@@ -64,9 +67,10 @@ class MattermostListener < Redmine::Hook::Listener
channels = channels_for_project issue.project
url = url_for_project issue.project
post_private_issues = post_private_issues_for_project(issue.project)
return unless channels.any? and url and issue.save
return if issue.is_private? and Setting.plugin_redmine_mattermost[:post_private_issues] != '1'
return unless channels.any? and url and issue.save
return if issue.is_private? and post_private_issues != '1'
msg = "[#{escape issue.project}] #{escape journal.user.to_s} updated <#{object_url issue}|#{escape issue}>"
@@ -119,16 +123,16 @@ class MattermostListener < Redmine::Hook::Listener
url = url_for_project project
attachment = nil
if not page.content.comments.empty?
attachment = {}
attachment[:text] = "#{escape page.content.comments}"
end
unless page.content.comments.empty?
attachment = {}
attachment[:text] = "#{escape page.content.comments}"
end
speak comment, channels, attachment, url
end
def speak(msg, channels, attachment=nil, url=nil)
url = Setting.plugin_redmine_mattermost[:mattermost_url] if not url
url = Setting.plugin_redmine_mattermost[:mattermost_url] unless url
username = Setting.plugin_redmine_mattermost[:username]
icon = Setting.plugin_redmine_mattermost[:icon]
@@ -192,6 +196,28 @@ private
].find{|v| v.present?}
end
def post_private_issues_for_project(proj)
return nil if proj.blank?
cf = ProjectCustomField.find_by_name("Mattermost Post private issues")
return [
(proj.custom_value_for(cf).value rescue nil),
(post_private_issues_for_project proj.parent),
Setting.plugin_redmine_mattermost[:post_private_issues],
].find{|v| v.present?}
end
def post_private_notes_for_project(proj)
return nil if proj.blank?
cf = ProjectCustomField.find_by_name("Mattermost Post private notes")
return [
(proj.custom_value_for(cf).value rescue nil),
(post_private_notes_for_project proj.parent),
Setting.plugin_redmine_mattermost[:post_private_notes],
].find{|v| v.present?}
end
def channels_for_project(proj)
return nil if proj.blank?