Commit 52d0c0ed authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '52446-hide-ado-project-banner-for-ci-file-or-ci-disabled' into 'master'

Hide Auto DevOps banner for projects with CI file or CI disabled

Closes #52446

See merge request gitlab-org/gitlab-ce!24067
parents c53ba44c 28783f89
...@@ -204,12 +204,10 @@ module ProjectsHelper ...@@ -204,12 +204,10 @@ module ProjectsHelper
current_user.require_extra_setup_for_git_auth? current_user.require_extra_setup_for_git_auth?
end end
def show_auto_devops_implicitly_enabled_banner?(project) def show_auto_devops_implicitly_enabled_banner?(project, user)
cookie_key = "hide_auto_devops_implicitly_enabled_banner_#{project.id}" return false unless user_can_see_auto_devops_implicitly_enabled_banner?(project, user)
project.has_auto_devops_implicitly_enabled? && cookies["hide_auto_devops_implicitly_enabled_banner_#{project.id}".to_sym].blank?
cookies[cookie_key.to_sym].blank? &&
(project.owner == current_user || project.team.maintainer?(current_user))
end end
def link_to_set_password def link_to_set_password
...@@ -579,4 +577,11 @@ module ProjectsHelper ...@@ -579,4 +577,11 @@ module ProjectsHelper
gcp gcp
] ]
end end
def user_can_see_auto_devops_implicitly_enabled_banner?(project, user)
Ability.allowed?(user, :admin_project, project) &&
project.has_auto_devops_implicitly_enabled? &&
project.builds_enabled? &&
!project.repository.gitlab_ci_yml
end
end end
- if show_auto_devops_implicitly_enabled_banner?(project) - if show_auto_devops_implicitly_enabled_banner?(project, current_user)
.auto-devops-implicitly-enabled-banner.alert.alert-warning .auto-devops-implicitly-enabled-banner.alert.alert-warning
- more_information_link = link_to _('More information'), help_page_path('topics/autodevops/index.md'), target: '_blank', class: 'alert-link' - more_information_link = link_to _('More information'), help_page_path('topics/autodevops/index.md'), target: '_blank', class: 'alert-link'
- auto_devops_message = s_("AutoDevOps|The Auto DevOps pipeline has been enabled and will be used if no alternative CI configuration file is found. %{more_information_link}") % { more_information_link: more_information_link } - auto_devops_message = s_("AutoDevOps|The Auto DevOps pipeline has been enabled and will be used if no alternative CI configuration file is found. %{more_information_link}") % { more_information_link: more_information_link }
......
---
title: Don't show Auto DevOps enabled banner for projects with CI file or CI disabled
merge_request: 24067
author:
type: other
...@@ -629,4 +629,103 @@ describe ProjectsHelper do ...@@ -629,4 +629,103 @@ describe ProjectsHelper do
end end
end end
end end
describe '#show_auto_devops_implicitly_enabled_banner?' do
using RSpec::Parameterized::TableSyntax
let(:user) { create(:user) }
let(:feature_visibilities) do
{
enabled: ProjectFeature::ENABLED,
disabled: ProjectFeature::DISABLED
}
end
where(:global_setting, :project_setting, :builds_visibility, :gitlab_ci_yml, :user_access, :result) do
# With ADO implicitly enabled scenarios
true | nil | :disabled | true | :developer | false
true | nil | :disabled | true | :maintainer | false
true | nil | :disabled | true | :owner | false
true | nil | :disabled | false | :developer | false
true | nil | :disabled | false | :maintainer | false
true | nil | :disabled | false | :owner | false
true | nil | :enabled | true | :developer | false
true | nil | :enabled | true | :maintainer | false
true | nil | :enabled | true | :owner | false
true | nil | :enabled | false | :developer | false
true | nil | :enabled | false | :maintainer | true
true | nil | :enabled | false | :owner | true
# With ADO enabled scenarios
true | true | :disabled | true | :developer | false
true | true | :disabled | true | :maintainer | false
true | true | :disabled | true | :owner | false
true | true | :disabled | false | :developer | false
true | true | :disabled | false | :maintainer | false
true | true | :disabled | false | :owner | false
true | true | :enabled | true | :developer | false
true | true | :enabled | true | :maintainer | false
true | true | :enabled | true | :owner | false
true | true | :enabled | false | :developer | false
true | true | :enabled | false | :maintainer | false
true | true | :enabled | false | :owner | false
# With ADO disabled scenarios
true | false | :disabled | true | :developer | false
true | false | :disabled | true | :maintainer | false
true | false | :disabled | true | :owner | false
true | false | :disabled | false | :developer | false
true | false | :disabled | false | :maintainer | false
true | false | :disabled | false | :owner | false
true | false | :enabled | true | :developer | false
true | false | :enabled | true | :maintainer | false
true | false | :enabled | true | :owner | false
true | false | :enabled | false | :developer | false
true | false | :enabled | false | :maintainer | false
true | false | :enabled | false | :owner | false
end
def grant_user_access(project, user, access)
case access
when :developer, :maintainer
project.add_user(user, access)
when :owner
project.namespace.update(owner: user)
end
end
with_them do
let(:project) do
if project_setting.nil?
create(:project, :repository)
else
create(:project, :repository, :auto_devops)
end
end
before do
stub_application_setting(auto_devops_enabled: global_setting)
allow_any_instance_of(Repository).to receive(:gitlab_ci_yml).and_return(gitlab_ci_yml)
grant_user_access(project, user, user_access)
project.project_feature.update_attribute(:builds_access_level, feature_visibilities[builds_visibility])
project.auto_devops.update_attribute(:enabled, project_setting) unless project_setting.nil?
end
subject { helper.show_auto_devops_implicitly_enabled_banner?(project, user) }
it { is_expected.to eq(result) }
end
end
end end
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