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
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)
c, a, _ = path.split('#')
current_controller?(c) && current_action?(a)
......
......@@ -35,7 +35,6 @@
= link_to charts_namespace_project_graph_path(@project.namespace, @project, current_ref) do
#{ _('Charts') }
- if @project.feature_available?(:file_lock)
= nav_link(controller: [:path_locks]) do
= link_to namespace_project_path_locks_path(@project.namespace, @project) do
Locked Files
= nav_link(controller: [:path_locks]) do
= link_to_protected_feature namespace_project_path_locks_path(@project.namespace, @project), feature: :file_lock do
Locked Files
......@@ -13,7 +13,6 @@
= link_to 'Commits', commits_namespace_project_graph_path
= nav_link(action: :languages) do
= link_to 'Languages', languages_namespace_project_graph_path
- if @project.feature_available?(:builds, current_user)
= nav_link(action: :ci) do
= link_to ci_namespace_project_graph_path do
Continuous Integration
= nav_link(action: :ci) do
= link_to_protected_feature ci_namespace_project_graph_path, feature: :builds, user: current_user do
Continuous Integration
......@@ -27,8 +27,7 @@
%span
Environments
- if @project.feature_available?(:builds, current_user) && !@project.empty_repo?
= nav_link(path: 'pipelines#charts') do
= link_to charts_namespace_project_pipelines_path(@project.namespace, @project), title: 'Charts', class: 'shortcuts-pipelines-charts' do
%span
Charts
= nav_link(path: '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
Charts
......@@ -22,11 +22,10 @@
= link_to namespace_project_settings_repository_path(@project.namespace, @project), title: 'Repository' do
%span
Repository
- if @project.feature_available?(:builds, current_user)
= nav_link(controller: :ci_cd) do
= link_to namespace_project_settings_ci_cd_path(@project.namespace, @project), title: 'Pipelines' do
%span
Pipelines
= nav_link(controller: :ci_cd) do
= link_to_protected_feature namespace_project_settings_ci_cd_path(@project.namespace, @project), feature: :builds, user: current_user, title: 'Pipelines' do
%span
Pipelines
- if Gitlab.config.pages.enabled
= nav_link(controller: :pages) do
= link_to namespace_project_pages_path(@project.namespace, @project), title: 'Pages' do
......
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