summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar √Čtienne Deparis 2017-06-15 21:06:14 +0200
committerGravatar √Čtienne Deparis 2017-06-15 21:06:14 +0200
commit523ac99589a69b15777346c3fbbe88ccf259fca8 (patch)
treec295d563af458e649410088b69459f3df4b43720
parented1415e0ec6a7b2ca534321f277d696c86deb3a4 (diff)
downloadcgit_menus-523ac99589a69b15777346c3fbbe88ccf259fca8.tar.gz
cgit_menus-523ac99589a69b15777346c3fbbe88ccf259fca8.tar.xz
cgit_menus-523ac99589a69b15777346c3fbbe88ccf259fca8.zip
Do not display Git tab if we are not in a cgit project
-rw-r--r--lib/cgit_menus_hook_listener.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/cgit_menus_hook_listener.rb b/lib/cgit_menus_hook_listener.rb
index 1a76480..cbd43c9 100644
--- a/lib/cgit_menus_hook_listener.rb
+++ b/lib/cgit_menus_hook_listener.rb
@@ -1,10 +1,16 @@
+require 'uri'
+
+# Add various menu items
class CgitMenusHookListener < Redmine::Hook::ViewListener
def view_layouts_base_body_top(context = {})
unless Redmine::MenuManager.map(:top_menu).exists?('Git repos'.to_sym)
Redmine::MenuManager.map(:top_menu).push('Git repos', Setting.plugin_cgit_menus['cgit_url'], :after => :home)
end
- return '' unless context[:project]
Redmine::MenuManager.map(:project_menu).delete(:git)
+ return '' if context[:project].blank? || Setting.plugin_cgit_menus['cgit_url'].blank?
+ project_host = URI.parse(context[:project].homepage).host
+ module_host = URI.parse(Setting.plugin_cgit_menus['cgit_url']).host
+ return '' unless project_host == module_host
Redmine::MenuManager.map(:project_menu).push(:git, "#{Setting.plugin_cgit_menus['cgit_url']}/#{context[:project].identifier}", :last => true)
'' # Deactivate ugly output
end