Commit a487c951 authored by Ruben Davila's avatar Ruben Davila

Add helper for rendering link to protected features

parent 54881838
...@@ -89,6 +89,19 @@ module TabHelper ...@@ -89,6 +89,19 @@ module TabHelper
end end
end end
def link_to_protected_feature(url, *args, &block)
link_text = capture(&block)
options = args.extract_options!
feature_key = options.delete(:feature)
user = options.delete(:user)
if @project.feature_available?(feature_key, user)
link_to(link_text, url, options)
else
link_to(link_text, '#', options)
end
end
def current_path?(path) def current_path?(path)
c, a, _ = path.split('#') c, a, _ = path.split('#')
current_controller?(c) && current_action?(a) current_controller?(c) && current_action?(a)
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
= link_to charts_namespace_project_graph_path(@project.namespace, @project, current_ref) do = link_to charts_namespace_project_graph_path(@project.namespace, @project, current_ref) do
#{ _('Charts') } #{ _('Charts') }
- if @project.feature_available?(:file_lock)
= nav_link(controller: [:path_locks]) do = nav_link(controller: [:path_locks]) do
= link_to namespace_project_path_locks_path(@project.namespace, @project) do = link_to_protected_feature namespace_project_path_locks_path(@project.namespace, @project), feature: :file_lock do
Locked Files Locked Files
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
= link_to 'Commits', commits_namespace_project_graph_path = link_to 'Commits', commits_namespace_project_graph_path
= nav_link(action: :languages) do = nav_link(action: :languages) do
= link_to 'Languages', languages_namespace_project_graph_path = link_to 'Languages', languages_namespace_project_graph_path
- if @project.feature_available?(:builds, current_user)
= nav_link(action: :ci) do = nav_link(action: :ci) do
= link_to ci_namespace_project_graph_path do = link_to_protected_feature ci_namespace_project_graph_path, feature: :builds, user: current_user do
Continuous Integration Continuous Integration
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
%span %span
Environments Environments
- if @project.feature_available?(:builds, current_user) && !@project.empty_repo?
= nav_link(path: 'pipelines#charts') do = nav_link(path: 'pipelines#charts') do
= link_to charts_namespace_project_pipelines_path(@project.namespace, @project), title: 'Charts', class: 'shortcuts-pipelines-charts' do = link_to_protected_feature charts_namespace_project_pipelines_path(@project.namespace, @project), feature: :builds, user: current_user, title: 'Charts', class: 'shortcuts-pipelines-charts' do
%span %span
Charts Charts
...@@ -22,9 +22,8 @@ ...@@ -22,9 +22,8 @@
= link_to namespace_project_settings_repository_path(@project.namespace, @project), title: 'Repository' do = link_to namespace_project_settings_repository_path(@project.namespace, @project), title: 'Repository' do
%span %span
Repository Repository
- if @project.feature_available?(:builds, current_user)
= nav_link(controller: :ci_cd) do = nav_link(controller: :ci_cd) do
= link_to namespace_project_settings_ci_cd_path(@project.namespace, @project), title: 'Pipelines' do = link_to_protected_feature namespace_project_settings_ci_cd_path(@project.namespace, @project), feature: :builds, user: current_user, title: 'Pipelines' do
%span %span
Pipelines Pipelines
- if Gitlab.config.pages.enabled - if Gitlab.config.pages.enabled
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment