Commit 7947ae8f authored by Mark Chao's avatar Mark Chao

Merge branch '342682-ui' into 'master'

Card match to exclude holder name, but include network name

See merge request gitlab-org/gitlab!72574
parents ee43d3a6 a9d489ca
......@@ -18,7 +18,7 @@ module Users
self.class.where(
expiration_date: expiration_date,
last_digits: last_digits,
holder_name: holder_name
network: network
).order(credit_card_validated_at: :desc).includes(:user)
end
end
......
......@@ -8,30 +8,35 @@
= link_to card_match_admin_user_path(@user) do
= _('other card matches')
%ul.content-list
- if credit_card_validation.nil?
%li#credit-card-status
%li#credit-card-status
- if credit_card_validation.nil?
%span.light= _('Validated:')
%strong= _('No')
- else
%li
- if credit_card_validation.holder_name
%span.light= _('Holder name:')
%strong
= credit_card_validation.holder_name
%li#credit-card-status
- else
%span.light= _('Validated at:')
%strong
= credit_card_validation.credit_card_validated_at.to_s(:medium)
- if credit_card_validation&.holder_name
%li
%span.light= _('Holder name:')
%strong
= credit_card_validation.holder_name
- if credit_card_validation&.network
%li
- if credit_card_validation.last_digits
%span.light= _('Card number:')
%strong
= credit_card_validation.last_digits.to_s.rjust(4, '0')
%span.light= _('Network:')
%strong
= credit_card_validation.network.camelcase
- if credit_card_validation&.last_digits
%li
- if credit_card_validation.expiration_date
%span.light= _('Expiration date:')
%strong
= credit_card_validation.expiration_date
%span.light= _('Card number:')
%strong
= credit_card_validation.last_digits.to_s.rjust(4, '0')
- if credit_card_validation&.expiration_date
%li
%span.light= _('Expiration date:')
%strong
= credit_card_validation.expiration_date
......@@ -19,6 +19,7 @@
%thead
%th= _('ID')
%th= _('User')
%th= _('Card holder name')
%th.gl-text-right= _('Validated at')
%th.gl-text-right= _('User created at')
%th.gl-text-right= _('Current sign-in ip')
......@@ -31,7 +32,9 @@
%td
= link_to(user.username, admin_user_path(user))
- if user == @user
= _('(target)')
= _('(this user)')
%td
= credit_card_validation.holder_name
%td.gl-text-right
= validated_at.to_s(:medium)
\/
......@@ -41,7 +44,7 @@
- if user.current_sign_in_ip
= user.current_sign_in_ip
= link_to sprite_icon('earth'), "https://api.hostip.info/country.php?ip=#{user.current_sign_in_ip}", target: '_blank', rel: 'noreferrer'
* All times are in UTC unless specified
= _('* All times are in UTC unless specified')
= paginate @similar_credit_card_validations, theme: 'gitlab'
.gl-float-right
......
......@@ -3,7 +3,7 @@
FactoryBot.modify do
factory :credit_card_validation do
user
credit_card_validated_at { Time.current }
sequence(:credit_card_validated_at) { |n| Time.current + n }
expiration_date { 1.year.from_now.end_of_month }
last_digits { 10 }
holder_name { 'John Smith' }
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'admin/users/_credit_card_info.html.haml', :saas do
include ApplicationHelper
let_it_be(:user, reload: true) { create(:user) }
def render
super(
partial: 'admin/users/credit_card_info.html.haml',
locals: { user: user }
)
end
it 'shows not validated' do
render
expect(rendered).to match /\bNo\b/
expect(rendered.scan(/<li\b/m).size).to eq(1)
end
context 'when user is validated' do
let!(:credit_card_validation) do
create(
:credit_card_validation,
user: user,
network: 'AmericanExpress',
last_digits: 2
)
end
it 'shows card data' do
render
expect(rendered.scan(/<li\b/m).size).to eq(5)
expect(rendered).to match /\b0002\b/
expect(rendered).to match /\bAmericanExpress\b/
expect(rendered).to include(credit_card_validation.holder_name)
expect(rendered).not_to match /\bNo\b/
end
context 'when network is missing' do
let!(:credit_card_validation) do
create(:credit_card_validation, user: user, network: nil)
end
it 'does not show network' do
render
expect(rendered).not_to match /\bAmericanExpress\b/
expect(rendered.scan(/<li\b/m).size).to eq(4)
end
end
end
end
......@@ -1128,12 +1128,15 @@ msgstr ""
msgid "(revoked)"
msgstr ""
msgid "(target)"
msgid "(this user)"
msgstr ""
msgid "(we need your current password to confirm your changes)"
msgstr ""
msgid "* All times are in UTC unless specified"
msgstr ""
msgid "+ %{amount} more"
msgstr ""
......@@ -6331,6 +6334,9 @@ msgstr ""
msgid "Capacity threshold"
msgstr ""
msgid "Card holder name"
msgstr ""
msgid "Card number:"
msgstr ""
......@@ -22563,6 +22569,9 @@ msgstr ""
msgid "Network"
msgstr ""
msgid "Network:"
msgstr ""
msgid "NetworkPolicies|%{ifLabelStart}if%{ifLabelEnd} %{ruleType} %{isLabelStart}is%{isLabelEnd} %{ruleDirection} %{ruleSelector} %{directionLabelStart}and is inbound from a%{directionLabelEnd} %{rule} %{portsLabelStart}on%{portsLabelEnd} %{ports}"
msgstr ""
......
......@@ -3,7 +3,10 @@
FactoryBot.define do
factory :credit_card_validation, class: 'Users::CreditCardValidation' do
user
credit_card_validated_at { Time.current }
sequence(:credit_card_validated_at) { |n| Time.current + n }
expiration_date { 1.year.from_now.end_of_month }
last_digits { 10 }
holder_name { 'John Smith' }
network { 'AmericanExpress' }
end
end
......@@ -10,16 +10,21 @@ RSpec.describe Users::CreditCardValidation do
it { is_expected.to validate_numericality_of(:last_digits).is_less_than_or_equal_to(9999) }
describe '.similar_records' do
let(:card_details) { subject.attributes.slice(:expiration_date, :last_digits, :holder_name) }
let(:card_details) do
subject.attributes.with_indifferent_access.slice(:expiration_date, :last_digits, :network, :holder_name)
end
subject(:credit_card_validation) { create(:credit_card_validation) }
subject!(:credit_card_validation) { create(:credit_card_validation, holder_name: 'Alice') }
let!(:match1) { create(:credit_card_validation, card_details) }
let!(:other1) { create(:credit_card_validation, card_details.merge(last_digits: 9)) }
let!(:match2) { create(:credit_card_validation, card_details) }
let!(:other2) { create(:credit_card_validation, card_details.merge(holder_name: 'foo bar')) }
let!(:match2) { create(:credit_card_validation, card_details.merge(holder_name: 'Bob')) }
let!(:non_match1) { create(:credit_card_validation, card_details.merge(last_digits: 9)) }
let!(:non_match2) { create(:credit_card_validation, card_details.merge(network: 'unknown')) }
let!(:non_match3) do
create(:credit_card_validation, card_details.dup.tap { |h| h[:expiration_date] += 1.year })
end
it 'returns records with matching credit card, ordered by credit_card_validated_at' do
it 'returns matches with the same last_digits, expiration and network, ordered by credit_card_validated_at' do
expect(subject.similar_records).to eq([match2, match1, subject])
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