Commit 508e926c authored by Ryan Cobb's avatar Ryan Cobb Committed by Reuben Pereira

Add credit card validation checkbox to admin users panel

The checkbox allows an admin to manually validate a user, so that
the user does not need to validate a credit card.

Or the admin can manually invalidate the user and force them to
verify their credit card.

Changelog: added
parent 78412844
......@@ -46,6 +46,7 @@ class Admin::UsersController < Admin::ApplicationController
end
def edit
user.credit_card_validation || user.build_credit_card_validation
user
end
......@@ -209,6 +210,13 @@ class Admin::UsersController < Admin::ApplicationController
user_params_with_pass.merge!(password_params)
end
cc_validation = params.dig(:user, :credit_card_validation_attributes, :credit_card_validated_at)
if cc_validation == "1" && !user.credit_card_validated_at
user_params_with_pass[:credit_card_validation_attributes] = { credit_card_validated_at: Time.zone.now }
elsif cc_validation == "0" && user.credit_card_validated_at
user.credit_card_validation.destroy
end
respond_to do |format|
result = Users::UpdateService.new(current_user, user_params_with_pass.merge(user: user)).execute do |user|
user.skip_reconfirmation!
......
......@@ -48,3 +48,16 @@
%row.hidden#warning_external_automatically_set.hidden
.badge.badge-warning.text-white
= s_('AdminUsers|Automatically marked as default internal user')
.form-group.row
= f.fields_for :credit_card_validation do |ff|
.col-sm-2.col-form-label.gl-pt-0
= ff.label s_("AdminUsers|Validate user account")
.col-sm-10.gl-display-flex.gl-align-items-baseline
= ff.check_box :credit_card_validated_at, checked: @user.credit_card_validated_at.present?
%div.gl-pl-2
%div.light
= s_('AdminUsers|User is validated and can use free CI minutes on shared runners.')
%div.text-muted
= s_('AdminUsers|A user can validate themselves by inputting a credit/debit card, or an admin can manually validate a user.')
......@@ -651,6 +651,75 @@ RSpec.describe Admin::UsersController do
expect { post :update, params: params }.to change { user.reload.note }.to(note)
end
end
context 'when updating validate user account' do
let(:params) do
{
id: user.to_param,
user: user_params
}
end
shared_examples 'no credit card validation param' do
let(:user_params) { { name: 'foo' } }
it 'does not change credit card validation' do
expect { post :update, params: params }.not_to change(Users::CreditCardValidation, :count)
end
end
context 'when user has a credit card validation' do
before do
user.create_credit_card_validation!(credit_card_validated_at: Time.zone.now)
end
context 'with unchecked credit card validation' do
let(:user_params) do
{ credit_card_validation_attributes: { credit_card_validated_at: '0' } }
end
it 'deletes credit_card_validation' do
expect { post :update, params: params }.to change { Users::CreditCardValidation.count }.by(-1)
end
end
context 'with checked credit card validation' do
let(:user_params) do
{ credit_card_validation_attributes: { credit_card_validated_at: '1' } }
end
it 'does not change credit_card_validated_at' do
expect { post :update, params: params }.not_to change { user.credit_card_validated_at }
end
end
it_behaves_like 'no credit card validation param'
end
context 'when user does not have a credit card validation' do
context 'with checked credit card validation' do
let(:user_params) do
{ credit_card_validation_attributes: { credit_card_validated_at: '1' } }
end
it 'creates new credit card validation' do
expect { post :update, params: params }.to change { Users::CreditCardValidation.count }.by 1
end
end
context 'with unchecked credit card validation' do
let(:user_params) do
{ credit_card_validation_attributes: { credit_card_validated_at: '0' } }
end
it 'does not blow up' do
expect { post :update, params: params }.not_to change(Users::CreditCardValidation, :count)
end
end
it_behaves_like 'no credit card validation param'
end
end
end
describe "DELETE #remove_email" 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