diff --git a/app/views/admin/users/_access_levels.html.haml b/app/views/admin/users/_access.html.haml similarity index 94% rename from app/views/admin/users/_access_levels.html.haml rename to app/views/admin/users/_access.html.haml index 5c80b3b4352ca6bf6baa4196a8be8eddb5851e9b..062f31d46b15d95bca433dd0bf93e4a205088099 100644 --- a/app/views/admin/users/_access_levels.html.haml +++ b/app/views/admin/users/_access.html.haml @@ -9,7 +9,8 @@ = f.number_field :projects_limit, min: 0, max: Gitlab::Database::MAX_INT_VALUE, class: 'form-control gl-form-input gl-form-input-sm' .form-group.gl-form-group{ role: 'group' } - = f.gitlab_ui_checkbox_component :can_create_group, s_('AdminUsers|Can create top level group') + - if @user.allow_user_to_create_group_and_project? + = f.gitlab_ui_checkbox_component :can_create_group, s_('AdminUsers|Can create top level group') = f.gitlab_ui_checkbox_component :private_profile, s_('AdminUsers|Private profile') %fieldset.form-group.gl-form-group diff --git a/app/views/admin/users/_form.html.haml b/app/views/admin/users/_form.html.haml index 22af1801fc5bb4afb880d5dd37c4224386eff85b..12c775d79e719fc3ac7a209bb2047e6b45c0b634 100644 --- a/app/views/admin/users/_form.html.haml +++ b/app/views/admin/users/_form.html.haml @@ -39,7 +39,7 @@ = f.label :password_confirmation, _('Password confirmation'), class: 'gl-display-block col-form-label' = f.password_field :password_confirmation, disabled: f.object.force_random_password, autocomplete: 'new-password', class: 'form-control gl-form-input gl-form-input-lg' - = render partial: 'access_levels', locals: { f: f } + = render partial: 'access', locals: { f: f } = render_if_exists 'admin/users/namespace_plan_fieldset', f: f diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 649ed00ea22c950e198a3d66768963796ccd1a68..8eb946d533d5175c023f1d5555b7ef4c3af3b75d 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -74,7 +74,7 @@ %li %span.light= _('Can create top level groups:') %strong - = @user.can_create_group ? _('Yes') : _('No') + = @user.allow_user_to_create_group_and_project? && @user.can_create_group ? _('Yes') : _('No') %li %span.light= _('Private profile:') %strong diff --git a/spec/views/admin/users/_form.html.haml_spec.rb b/spec/views/admin/users/_form.html.haml_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..9638e1130949170a0aa12e04c1ad5d88e2866796 --- /dev/null +++ b/spec/views/admin/users/_form.html.haml_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'admin/users/_form.html.haml', feature_category: :user_management do + let_it_be(:user) { build(:user, :guest) } + + before do + assign(:user, user) + end + + describe 'Access' do + describe 'user top level group creation setting' do + context 'when the user is not allowed to create a group' do + before do + allow(user).to receive(:allow_user_to_create_group_and_project?).and_return(false) + end + + it 'hides the checkbox' do + render + + expect(rendered).not_to have_field( + 'Can create top level group', + type: 'checkbox' + ) + end + end + + context 'when the user is allowed to create a group' do + before do + allow(user).to receive(:allow_user_to_create_group_and_project?).and_return(true) + end + + it 'renders the checkbox' do + render + + expect(rendered).to have_field( + 'Can create top level group', + type: 'checkbox' + ) + end + end + end + end +end