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 ...@@ -18,7 +18,7 @@ module Users
self.class.where( self.class.where(
expiration_date: expiration_date, expiration_date: expiration_date,
last_digits: last_digits, last_digits: last_digits,
holder_name: holder_name network: network
).order(credit_card_validated_at: :desc).includes(:user) ).order(credit_card_validated_at: :desc).includes(:user)
end end
end end
......
...@@ -8,30 +8,35 @@ ...@@ -8,30 +8,35 @@
= link_to card_match_admin_user_path(@user) do = link_to card_match_admin_user_path(@user) do
= _('other card matches') = _('other card matches')
%ul.content-list %ul.content-list
- if credit_card_validation.nil?
%li#credit-card-status %li#credit-card-status
- if credit_card_validation.nil?
%span.light= _('Validated:') %span.light= _('Validated:')
%strong= _('No') %strong= _('No')
- else - else
%span.light= _('Validated at:')
%strong
= credit_card_validation.credit_card_validated_at.to_s(:medium)
- if credit_card_validation&.holder_name
%li %li
- if credit_card_validation.holder_name
%span.light= _('Holder name:') %span.light= _('Holder name:')
%strong %strong
= credit_card_validation.holder_name = credit_card_validation.holder_name
%li#credit-card-status - if credit_card_validation&.network
%span.light= _('Validated at:') %li
%span.light= _('Network:')
%strong %strong
= credit_card_validation.credit_card_validated_at.to_s(:medium) = credit_card_validation.network.camelcase
- if credit_card_validation&.last_digits
%li %li
- if credit_card_validation.last_digits
%span.light= _('Card number:') %span.light= _('Card number:')
%strong %strong
= credit_card_validation.last_digits.to_s.rjust(4, '0') = credit_card_validation.last_digits.to_s.rjust(4, '0')
- if credit_card_validation&.expiration_date
%li %li
- if credit_card_validation.expiration_date
%span.light= _('Expiration date:') %span.light= _('Expiration date:')
%strong %strong
= credit_card_validation.expiration_date = credit_card_validation.expiration_date
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
%thead %thead
%th= _('ID') %th= _('ID')
%th= _('User') %th= _('User')
%th= _('Card holder name')
%th.gl-text-right= _('Validated at') %th.gl-text-right= _('Validated at')
%th.gl-text-right= _('User created at') %th.gl-text-right= _('User created at')
%th.gl-text-right= _('Current sign-in ip') %th.gl-text-right= _('Current sign-in ip')
...@@ -31,7 +32,9 @@ ...@@ -31,7 +32,9 @@
%td %td
= link_to(user.username, admin_user_path(user)) = link_to(user.username, admin_user_path(user))
- if user == @user - if user == @user
= _('(target)') = _('(this user)')
%td
= credit_card_validation.holder_name
%td.gl-text-right %td.gl-text-right
= validated_at.to_s(:medium) = validated_at.to_s(:medium)
\/ \/
...@@ -41,7 +44,7 @@ ...@@ -41,7 +44,7 @@
- if user.current_sign_in_ip - if user.current_sign_in_ip
= 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' = 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' = paginate @similar_credit_card_validations, theme: 'gitlab'
.gl-float-right .gl-float-right
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
FactoryBot.modify do FactoryBot.modify do
factory :credit_card_validation do factory :credit_card_validation do
user 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 } expiration_date { 1.year.from_now.end_of_month }
last_digits { 10 } last_digits { 10 }
holder_name { 'John Smith' } 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 "" ...@@ -1128,12 +1128,15 @@ msgstr ""
msgid "(revoked)" msgid "(revoked)"
msgstr "" msgstr ""
msgid "(target)" msgid "(this user)"
msgstr "" msgstr ""
msgid "(we need your current password to confirm your changes)" msgid "(we need your current password to confirm your changes)"
msgstr "" msgstr ""
msgid "* All times are in UTC unless specified"
msgstr ""
msgid "+ %{amount} more" msgid "+ %{amount} more"
msgstr "" msgstr ""
...@@ -6331,6 +6334,9 @@ msgstr "" ...@@ -6331,6 +6334,9 @@ msgstr ""
msgid "Capacity threshold" msgid "Capacity threshold"
msgstr "" msgstr ""
msgid "Card holder name"
msgstr ""
msgid "Card number:" msgid "Card number:"
msgstr "" msgstr ""
...@@ -22563,6 +22569,9 @@ msgstr "" ...@@ -22563,6 +22569,9 @@ msgstr ""
msgid "Network" msgid "Network"
msgstr "" 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}" msgid "NetworkPolicies|%{ifLabelStart}if%{ifLabelEnd} %{ruleType} %{isLabelStart}is%{isLabelEnd} %{ruleDirection} %{ruleSelector} %{directionLabelStart}and is inbound from a%{directionLabelEnd} %{rule} %{portsLabelStart}on%{portsLabelEnd} %{ports}"
msgstr "" msgstr ""
......
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
FactoryBot.define do FactoryBot.define do
factory :credit_card_validation, class: 'Users::CreditCardValidation' do factory :credit_card_validation, class: 'Users::CreditCardValidation' do
user user
sequence(:credit_card_validated_at) { |n| Time.current + n }
credit_card_validated_at { Time.current } expiration_date { 1.year.from_now.end_of_month }
last_digits { 10 }
holder_name { 'John Smith' }
network { 'AmericanExpress' }
end end
end end
...@@ -10,16 +10,21 @@ RSpec.describe Users::CreditCardValidation do ...@@ -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) } it { is_expected.to validate_numericality_of(:last_digits).is_less_than_or_equal_to(9999) }
describe '.similar_records' do 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!(: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.merge(holder_name: 'Bob')) }
let!(:match2) { create(:credit_card_validation, card_details) } let!(:non_match1) { create(:credit_card_validation, card_details.merge(last_digits: 9)) }
let!(:other2) { create(:credit_card_validation, card_details.merge(holder_name: 'foo bar')) } 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]) expect(subject.similar_records).to eq([match2, match1, subject])
end end
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