Commit 768ff941 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'revert-7bc19ad8' into 'master'

Revert "Merge branch 'nelbacha-master-patch-50345' into 'master'" RUN AS-IF-FOSS

Closes #224443

See merge request gitlab-org/gitlab!35279
parents 59c21110 7267f57e
...@@ -7,14 +7,8 @@ module DeployTokensHelper ...@@ -7,14 +7,8 @@ module DeployTokensHelper
Rails.env.test? Rails.env.test?
end end
def container_registry_enabled?(subject) def container_registry_enabled?(project)
Gitlab.config.registry.enabled && Gitlab.config.registry.enabled &&
can?(current_user, :read_container_image, subject) can?(current_user, :read_container_image, project)
end
def packages_registry_enabled?(subject)
Gitlab.config.packages.enabled &&
subject.feature_available?(:packages) &&
can?(current_user, :read_package, subject)
end end
end end
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
= label_tag ("deploy_token_write_registry"), 'write_registry', class: 'label-bold form-check-label' = label_tag ("deploy_token_write_registry"), 'write_registry', class: 'label-bold form-check-label'
.text-secondary= s_('DeployTokens|Allows write access to the registry images') .text-secondary= s_('DeployTokens|Allows write access to the registry images')
- if packages_registry_enabled?(group_or_project)
%fieldset.form-group.form-check %fieldset.form-group.form-check
= f.check_box :read_package_registry, class: 'form-check-input' = f.check_box :read_package_registry, class: 'form-check-input'
= label_tag ("deploy_token_read_package_registry"), 'read_package_registry', class: 'label-bold form-check-label' = label_tag ("deploy_token_read_package_registry"), 'read_package_registry', class: 'label-bold form-check-label'
......
---
title: Conditionally render the packages scopes in deploy token settings
merge_request: 33042
author:
type: fixed
# frozen_string_literal: true
require 'spec_helper'
describe 'shared/deploy_tokens/_form.html.haml' do
using RSpec::Parameterized::TableSyntax
let_it_be(:user) { create(:user) }
let_it_be(:token) { build(:deploy_token) }
let_it_be(:project, refind: true) { create(:project, :private) }
let_it_be(:group, refind: true) { create(:group) }
RSpec.shared_examples "display deploy token settings" do |role, type, can|
let(:subject) { type == :project ? project : group }
if can
it "renders the packages scopes for user role #{role} in #{type}" do
render 'shared/deploy_tokens/form', token: token, group_or_project: subject
expect(rendered).to have_content('Allows read access to the package registry')
end
else
it "does not render the packages scopes for user role #{role} in #{type}" do
render 'shared/deploy_tokens/form', token: token, group_or_project: subject
expect(rendered).not_to have_content('Allows read access to the package registry')
end
end
end
where(:packages_enabled, :feature_enabled, :role, :subject, :can) do
true | true | :owner | :group | true
true | false | :owner | :group | false
false | true | :owner | :group | false
false | false | :owner | :group | false
true | true | :maintainer | :group | true
true | false | :maintainer | :group | false
false | true | :maintainer | :group | false
false | false | :maintainer | :group | false
true | true | :maintainer | :project | true
false | true | :maintainer | :project | false
true | false | :maintainer | :project | false
false | false | :maintainer | :project | false
end
with_them do
before do
subject.send("add_#{role}", user)
allow(view).to receive(:current_user).and_return(user)
stub_config(packages: { enabled: packages_enabled })
stub_licensed_features(packages: feature_enabled)
end
it_behaves_like 'display deploy token settings', params[:role], params[:subject], params[:can]
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