Parent project support for icon and username has been added

This commit is contained in:
Alexander Meindl
2017-05-25 11:58:40 +02:00
parent 22ccab7e72
commit 87869706a6
9 changed files with 41 additions and 26 deletions

View File

@@ -63,8 +63,7 @@ Under the configuration options, set the Messenger API URL to the URL for an
Incoming WebHook integration in your Messenger account and also set the Messenger
Channel to the channel's handle (be careful, this is not the channel's display name
visible to users, you can find each channel's handle by navigating inside the channel
and clicking the down-arrow and selecting view info). See also the next two sections
for advanced and custom routing options.
and clicking the down-arrow and selecting view info).
## Uninstall

View File

@@ -4,9 +4,8 @@ require 'net/http'
class Messenger
include Redmine::I18n
def self.speak(msg, channels, attachment = nil, url = nil)
def self.speak(msg, channels, url, options)
url = RedmineMessenger.settings[:messenger_url] unless url
icon = RedmineMessenger.settings[:messenger_icon]
return if url.blank?
return if channels.blank?
@@ -16,11 +15,11 @@ class Messenger
link_names: 1
}
if RedmineMessenger.settings[:messenger_username].present?
params[:username] = RedmineMessenger.settings[:messenger_username]
end
params[:attachments] = [attachment] if attachment && attachment.any?
username = Messenger.textfield_for_project(options[:project], :messenger_username)
params[:username] = username if username.present?
params[:attachments] = [options[:attachment]] if options[:attachment] && options[:attachment].any?
icon = Messenger.textfield_for_project(options[:project], :messenger_icon)
if icon.present?
if icon.start_with? ':'
params[:icon_emoji] = icon
@@ -77,6 +76,24 @@ class Messenger
nil
end
def self.textfield_for_project(proj, config)
return if proj.blank?
# project based
pm = MessengerSetting.find_by(project_id: proj.id)
return pm.send(config) if !pm.nil? && pm.send(config).present?
default_textfield(proj, config)
end
def self.default_textfield(proj, config)
# parent project based
parent_field = textfield_for_project(proj.parent, config)
return parent_field if parent_field.present?
if RedmineMessenger.settings[config].present?
return RedmineMessenger.settings[config]
end
''
end
def self.channels_for_project(proj)
return [] if proj.blank?
# project based
@@ -85,6 +102,10 @@ class Messenger
return [] if pm.messenger_channel == '-'
return pm.messenger_channel.split(',').map(&:strip).uniq
end
default_project_channels(proj)
end
def self.default_project_channels(proj)
# parent project based
parent_channel = channels_for_project(proj.parent)
return parent_channel if parent_channel.present?
@@ -107,12 +128,7 @@ class Messenger
return true if pm.send(config) == 2
# 0 = use system based settings
end
# parent project based
parent_setting = setting_for_project(proj.parent, config)
return parent_setting if @setting_found == 1
# system based
return true if RedmineMessenger.settings[config].present? && RedmineMessenger.settings[config] == '1'
false
default_project_setting(proj, config)
end
def self.default_project_setting(proj, config)

View File

@@ -1,4 +1,4 @@
<p>
<%= f.text_field mf, size: size, label: l("label_settings_#{mf}") %>
<em class="info"><%= l(:label_messenger_project_text_field_info) %> (<%= l(:label_default) %>: <%= RedmineMessenger.settings[mf] %>)</em>
<em class="info"><%= l(:label_messenger_project_text_field_info) %> (<%= l(:label_default) %>: <%= Messenger.default_textfield(@project, mf) %>)</em>
</p>

View File

@@ -48,7 +48,7 @@ module RedmineMessenger
attachment[:text] = ll(Setting.default_language, :text_status_changed_by_changeset, "<#{revision_url}|#{ERB::Util.html_escape(changeset.comments)}>")
attachment[:fields] = journal.details.map { |d| Messenger.detail_to_field d }
Messenger.speak msg, channels, attachment, url
Messenger.speak(msg, channels, url, attachment: attachment, project: project)
end
end
end

View File

@@ -24,7 +24,7 @@ module RedmineMessenger
project_url: "<#{Messenger.object_url project}|#{ERB::Util.html_escape(project)}>",
url: "<#{Messenger.object_url self}|#{name}>",
user: User.current),
channels, nil, url)
channels, url, project: project)
end
def send_messenger_update
@@ -39,7 +39,7 @@ module RedmineMessenger
project_url: "<#{Messenger.object_url project}|#{ERB::Util.html_escape(project)}>",
url: "<#{Messenger.object_url self}|#{name}>",
user: User.current),
channels, nil, url)
channels, url, project: project)
end
end
end

View File

@@ -24,7 +24,7 @@ module RedmineMessenger
project_url: "<#{Messenger.object_url project}|#{ERB::Util.html_escape(project)}>",
url: "<#{Messenger.object_url self}|#{name}>",
user: User.current),
channels, nil, url)
channels, url, project: project)
end
def send_messenger_update
@@ -39,7 +39,7 @@ module RedmineMessenger
project_url: "<#{Messenger.object_url project}|#{ERB::Util.html_escape(project)}>",
url: "<#{Messenger.object_url self}|#{name}>",
user: User.current),
channels, nil, url)
channels, url, project: project)
end
end
end

View File

@@ -51,7 +51,7 @@ module RedmineMessenger
project_url: "<#{Messenger.object_url project}|#{ERB::Util.html_escape(project)}>",
url: "<#{Messenger.object_url(self)}|#{ERB::Util.html_escape(self)}>#{Messenger.mentions description if RedmineMessenger.settings[:auto_mentions] == '1'}",
user: author),
channels, attachment, url)
channels, url, attachment: attachment, project: project)
end
def send_messenger_update
@@ -77,7 +77,7 @@ module RedmineMessenger
project_url: "<#{Messenger.object_url project}|#{ERB::Util.html_escape(project)}>",
url: "<#{Messenger.object_url self}|#{ERB::Util.html_escape(self)}>#{Messenger.mentions(current_journal.notes) if Messenger.setting_for_project(project, :auto_mentions)}",
user: current_journal.user),
channels, attachment, url)
channels, url, attachment: attachment, project: project)
end
end
end

View File

@@ -24,7 +24,7 @@ module RedmineMessenger
project_url: "<#{Messenger.object_url project}|#{ERB::Util.html_escape(project)}>",
url: "<#{Messenger.object_url self}|#{name}>",
user: User.current),
channels, nil, url)
channels, url, project: project)
end
def send_messenger_update
@@ -39,7 +39,7 @@ module RedmineMessenger
project_url: "<#{Messenger.object_url project}|#{ERB::Util.html_escape(project)}>",
url: "<#{Messenger.object_url self}|#{name}>",
user: User.current),
channels, nil, url)
channels, url, project: project)
end
end
end

View File

@@ -24,7 +24,7 @@ module RedmineMessenger
project_url: "<#{Messenger.object_url project}|#{ERB::Util.html_escape(project)}>",
url: "<#{Messenger.object_url self}|#{title}>",
user: User.current),
channels, nil, url)
channels, url, project: project)
end
def send_messenger_update
@@ -46,7 +46,7 @@ module RedmineMessenger
project_url: "<#{Messenger.object_url project}|#{ERB::Util.html_escape(project)}>",
url: "<#{Messenger.object_url self}|#{title}>",
user: content.author),
channels, attachment, url)
channels, url, project: project, attachment: attachment)
end
end
end