From 923351a67e896e2c2659c351e27b783085e9d8ca Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Thu, 7 Aug 2025 14:03:04 +0200 Subject: [PATCH] MT#63320 fix /api/vouchers search by code * base64 code provided in the query params is now correctly re-encoded as encrypted base64 string to use in search. Change-Id: Id9e45079b260bdc51465a781124f6fbb636cf2db (cherry picked from commit a7c45f170ca3b41dfe5f3ac9047e76b29cafacd0) --- lib/NGCP/Panel/Controller/API/Vouchers.pm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/NGCP/Panel/Controller/API/Vouchers.pm b/lib/NGCP/Panel/Controller/API/Vouchers.pm index ade14c49d1..7cbb03f0bd 100644 --- a/lib/NGCP/Panel/Controller/API/Vouchers.pm +++ b/lib/NGCP/Panel/Controller/API/Vouchers.pm @@ -8,8 +8,10 @@ use Data::HAL qw(); use Data::HAL::Link qw(); use HTTP::Headers qw(); use HTTP::Status qw(:constants); +use MIME::Base64; use NGCP::Panel::Utils::DateTime; +use NGCP::Panel::Utils::Voucher; sub allowed_methods{ return [qw/GET POST OPTIONS HEAD/]; @@ -42,7 +44,20 @@ sub query_params { }, second => sub {}, }, - }, ]; + }, + { + param => 'code', + description => 'Filter for a voucher with the base64 encoded code', + new_rs => sub { + my ($c,$q,$rs) = @_; + my $code = decode_base64($q); + my $enc_code = NGCP::Panel::Utils::Voucher::encrypt_code($c, $code); + return $rs->search_rs({ + code => $enc_code, + }); + }, + }, + ], } use parent qw/NGCP::Panel::Role::Entities NGCP::Panel::Role::API::Vouchers/;