Commit 7a8a6040 authored by Rubén Dávila's avatar Rubén Dávila

BUGFIX: admins were unable to change the GL.com plan for a namespace

The GL.com plan is no longer stored with Namespace, now this attribute
is part of the new GitlabSubscription model.
parent d383f618
......@@ -21,7 +21,7 @@ module EE
super + [
:repository_size_limit,
:shared_runners_minutes_limit,
:plan_id
gitlab_subscription_attributes: [:hosted_plan_id]
].tap do |params_ee|
params_ee << :project_creation_level if @group&.feature_available?(:project_creation_level)
end
......
......@@ -20,7 +20,11 @@ module EE
def allowed_user_params
super + [
:note,
namespace_attributes: [:id, :shared_runners_minutes_limit, :plan_id]
namespace_attributes: [
:id,
:shared_runners_minutes_limit,
gitlab_subscription_attributes: [:hosted_plan_id]
]
]
end
end
......
......@@ -33,6 +33,8 @@ module EE
has_one :namespace_statistics
has_one :gitlab_subscription, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
accepts_nested_attributes_for :gitlab_subscription
scope :with_plan, -> { where.not(plan_id: nil) }
delegate :shared_runners_minutes, :shared_runners_seconds, :shared_runners_seconds_last_reset,
......
# frozen_string_literal: true
class GitlabSubscription < ActiveRecord::Base
default_value_for :start_date, Date.today
belongs_to :namespace
belongs_to :hosted_plan, class_name: 'Plan'
......
......@@ -4,6 +4,7 @@
.form-group.row
= f.label :plan, class: 'col-form-label col-sm-2'
.col-sm-10
= f.select :plan_id, Plan.pluck(:title, :id),
{ include_blank: 'No plan' },
class: 'form-control'
= f.fields_for :gitlab_subscription do |f|
= f.select :hosted_plan_id, Plan.pluck(:title, :id),
{ include_blank: 'No plan' },
class: 'form-control'
# frozen_string_literal: true
require 'spec_helper'
describe 'Changes GL.com plan for group' do
include WaitForRequests
let!(:silver_plan) { create(:silver_plan) }
let(:admin) { create(:admin) }
before do
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true }
sign_in(admin)
end
describe 'for group namespace' do
let(:group) { create(:group) }
before do
visit admin_group_path(group)
click_link 'Edit'
end
it 'changes the plan' do
find('#group_gitlab_subscription_attributes_hosted_plan_id').find(:xpath, 'option[2]').select_option
click_button('Save changes')
expect(page).to have_content('Plan: Silver')
end
end
describe 'for user namespace' do
let(:user) { create(:user) }
before do
visit admin_user_path(user)
click_link 'Edit'
end
it 'changes the plan' do
find('#user_namespace_attributes_gitlab_subscription_attributes_hosted_plan_id').find(:xpath, 'option[2]').select_option
click_button('Save changes')
expect(page).to have_content('Plan: Silver')
end
end
end
require 'spec_helper'
describe GitlabSubscription do
describe 'default values' do
it do
expect(subject.start_date).to eq(Date.today)
end
end
describe 'validations' do
it { is_expected.to validate_presence_of(:seats) }
it { is_expected.to validate_presence_of(:start_date) }
......
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