borrow code from redmine's mailer.rb in order to proper detect sub-uri conditions (refs #4)

This commit is contained in:
Thanos Kyritsis
2016-02-13 14:26:02 +02:00
parent e519b6a74d
commit 0dd8f50592

View File

@@ -71,15 +71,30 @@ class MattermostListener < Redmine::Hook::Listener
repository = changeset.repository
revision_url = Rails.application.routes.url_for(
:controller => 'repositories',
:action => 'revision',
:id => repository.project,
:repository_id => repository.identifier_param,
:rev => changeset.revision,
:host => Setting.host_name,
:protocol => Setting.protocol
)
if Setting.host_name.to_s =~ /\A(https?\:\/\/)?(.+?)(\:(\d+))?(\/.+)?\z/i
host, port, prefix = $2, $4, $5
revision_url = Rails.application.routes.url_for(
:controller => 'repositories',
:action => 'revision',
:id => repository.project,
:repository_id => repository.identifier_param,
:rev => changeset.revision,
:host => host,
:protocol => Setting.protocol,
:port => port,
:script_name => prefix
)
else
revision_url = Rails.application.routes.url_for(
:controller => 'repositories',
:action => 'revision',
:id => repository.project,
:repository_id => repository.identifier_param,
:rev => changeset.revision,
:host => Setting.host_name,
:protocol => Setting.protocol
)
end
attachment = {}
attachment[:text] = ll(Setting.default_language, :text_status_changed_by_changeset, "<#{revision_url}|#{escape changeset.comments}>")
@@ -127,7 +142,12 @@ private
end
def object_url(obj)
Rails.application.routes.url_for(obj.event_url({:host => Setting.host_name, :protocol => Setting.protocol}))
if Setting.host_name.to_s =~ /\A(https?\:\/\/)?(.+?)(\:(\d+))?(\/.+)?\z/i
host, port, prefix = $2, $4, $5
Rails.application.routes.url_for(obj.event_url({:host => host, :protocol => Setting.protocol, :port => port, :script_name => prefix}))
else
Rails.application.routes.url_for(obj.event_url({:host => Setting.host_name, :protocol => Setting.protocol}))
end
end
def url_for_project(proj)