From aacf44c6052d928b8b7bc165e681c234c2540c13 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Thu, 16 Nov 2023 12:23:19 +0100 Subject: [PATCH] MT#58762 harmonize restapi wildcard filters - all standard LIKE search are migrated - will avoid LIKE unless a pattern (* wildcard) is used as a search term. this encourage db index usage, will be faster - supports wildcard escape sequence \\* - harmonize swagger UI descriptions of filters Change-Id: Iea155871c9be6c284e6970a562d4e6af73fedc4b (cherry picked from commit 308a9740597c56e91de73fd02e3d30e81d3d6756) --- lib/NGCP/Panel/Controller/API/Admins.pm | 4 +- .../Panel/Controller/API/BalanceIntervals.pm | 11 ++--- .../Panel/Controller/API/BillingNetworks.pm | 8 +--- .../Panel/Controller/API/BillingProfiles.pm | 16 +------- lib/NGCP/Panel/Controller/API/BillingZones.pm | 8 +--- .../Panel/Controller/API/CFBNumberSets.pm | 8 +--- .../Panel/Controller/API/CFDestinationSets.pm | 8 +--- lib/NGCP/Panel/Controller/API/CFSourceSets.pm | 8 +--- lib/NGCP/Panel/Controller/API/CFTimeSets.pm | 8 +--- lib/NGCP/Panel/Controller/API/Contracts.pm | 8 +--- .../Panel/Controller/API/CustomerBalances.pm | 8 +--- .../Panel/Controller/API/CustomerContacts.pm | 10 +---- .../Panel/Controller/API/CustomerLocations.pm | 10 +---- lib/NGCP/Panel/Controller/API/Customers.pm | 8 +--- lib/NGCP/Panel/Controller/API/Domains.pm | 10 +---- .../Panel/Controller/API/EmailTemplates.pm | 8 +--- .../API/EmergencyMappingContainers.pm | 10 +---- .../Panel/Controller/API/EmergencyMappings.pm | 10 +---- lib/NGCP/Panel/Controller/API/Events.pm | 8 +--- .../Panel/Controller/API/FaxserverSettings.pm | 2 +- .../Panel/Controller/API/HeaderRuleSets.pm | 8 ++-- lib/NGCP/Panel/Controller/API/HeaderRules.pm | 16 ++------ .../Panel/Controller/API/InvoiceTemplates.pm | 8 +--- lib/NGCP/Panel/Controller/API/Invoices.pm | 4 +- lib/NGCP/Panel/Controller/API/LnpCarriers.pm | 20 ++-------- lib/NGCP/Panel/Controller/API/LnpNumbers.pm | 10 +---- lib/NGCP/Panel/Controller/API/NcosLevels.pm | 8 +--- lib/NGCP/Panel/Controller/API/Numbers.pm | 6 +-- .../Panel/Controller/API/PbxDeviceModels.pm | 4 +- .../Panel/Controller/API/PbxDeviceProfiles.pm | 20 ++-------- lib/NGCP/Panel/Controller/API/PbxDevices.pm | 20 +++++----- .../Panel/Controller/API/PeeringGroups.pm | 18 ++------- .../Controller/API/PeeringInboundRules.pm | 10 +---- lib/NGCP/Panel/Controller/API/PeeringRules.pm | 8 +--- .../Panel/Controller/API/PeeringServers.pm | 24 ++--------- .../Panel/Controller/API/PhonebookEntries.pm | 8 ++-- .../Panel/Controller/API/ProfilePackages.pm | 16 +++----- lib/NGCP/Panel/Controller/API/Resellers.pm | 10 +---- .../Panel/Controller/API/RewriteRuleSets.pm | 8 ++-- lib/NGCP/Panel/Controller/API/RewriteRules.pm | 4 +- lib/NGCP/Panel/Controller/API/SoundGroups.pm | 2 +- lib/NGCP/Panel/Controller/API/SoundSets.pm | 4 +- .../Controller/API/SubscriberProfileSets.pm | 8 +--- .../Controller/API/SubscriberProfiles.pm | 8 +--- lib/NGCP/Panel/Controller/API/Subscribers.pm | 40 ++++++++----------- .../Panel/Controller/API/SystemContacts.pm | 10 +---- lib/NGCP/Panel/Controller/API/TimeSets.pm | 4 +- .../Controller/API/VoicemailGreetings.pm | 3 +- lib/NGCP/Panel/Controller/API/Voicemails.pm | 5 ++- lib/NGCP/Panel/Role/API.pm | 8 ++++ lib/NGCP/Panel/Utils/Generic.pm | 12 ++++-- share/templates/api/root/collection.tt | 4 ++ 52 files changed, 144 insertions(+), 365 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/Admins.pm b/lib/NGCP/Panel/Controller/API/Admins.pm index 43493c294f..5dab687a11 100644 --- a/lib/NGCP/Panel/Controller/API/Admins.pm +++ b/lib/NGCP/Panel/Controller/API/Admins.pm @@ -29,8 +29,8 @@ sub query_params { }, { param => 'login', - description => 'Filter for admins with a specific login (wildcards possible)', - query_type => 'string_like', + description => 'Filter for admins with a specific login', # (wildcards possible)', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/BalanceIntervals.pm b/lib/NGCP/Panel/Controller/API/BalanceIntervals.pm index 7a24d2f3ea..aade2846c7 100644 --- a/lib/NGCP/Panel/Controller/API/BalanceIntervals.pm +++ b/lib/NGCP/Panel/Controller/API/BalanceIntervals.pm @@ -61,14 +61,9 @@ sub query_params { { param => 'external_id', description => 'Filter for contracts with a specific external id', - query => { - first => sub { - my $q = shift; - { 'me.external_id' => { like => $q } }; - }, - second => sub {}, - }, - }, ]; + query_type => 'wildcard', + }, + ]; } use parent qw/NGCP::Panel::Role::Entities NGCP::Panel::Role::API::BalanceIntervals/; diff --git a/lib/NGCP/Panel/Controller/API/BillingNetworks.pm b/lib/NGCP/Panel/Controller/API/BillingNetworks.pm index 3aa3eada13..27638da6ca 100644 --- a/lib/NGCP/Panel/Controller/API/BillingNetworks.pm +++ b/lib/NGCP/Panel/Controller/API/BillingNetworks.pm @@ -48,13 +48,7 @@ sub query_params { { param => 'name', description => 'Filter for billing networks matching a name pattern', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/BillingProfiles.pm b/lib/NGCP/Panel/Controller/API/BillingProfiles.pm index d25dd7566f..c29650c89f 100644 --- a/lib/NGCP/Panel/Controller/API/BillingProfiles.pm +++ b/lib/NGCP/Panel/Controller/API/BillingProfiles.pm @@ -36,24 +36,12 @@ sub query_params { { param => 'handle', description => 'Filter for billing profiles with a specific handle', - query => { - first => sub { - my $q = shift; - { handle => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'name', description => 'Filter for billing profiles with a specific name', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/BillingZones.pm b/lib/NGCP/Panel/Controller/API/BillingZones.pm index bbcb8885e9..651a7904c6 100644 --- a/lib/NGCP/Panel/Controller/API/BillingZones.pm +++ b/lib/NGCP/Panel/Controller/API/BillingZones.pm @@ -34,13 +34,7 @@ sub query_params { { param => 'zone', description => 'Filter for zone name', - query => { - first => sub { - my $q = shift; - { zone => { like => '%'.$q.'%' } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/CFBNumberSets.pm b/lib/NGCP/Panel/Controller/API/CFBNumberSets.pm index 94e3b56279..a818e448c8 100644 --- a/lib/NGCP/Panel/Controller/API/CFBNumberSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFBNumberSets.pm @@ -37,13 +37,7 @@ sub query_params { { param => 'name', description => 'Filter for items matching a B-Number Set name pattern', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm b/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm index 0b0ab17030..fd1e560767 100644 --- a/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm @@ -38,13 +38,7 @@ sub query_params { { param => 'name', description => 'Filter for contacts matching a destination set name pattern', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/CFSourceSets.pm b/lib/NGCP/Panel/Controller/API/CFSourceSets.pm index d62af18be5..eb527e5a15 100644 --- a/lib/NGCP/Panel/Controller/API/CFSourceSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFSourceSets.pm @@ -37,13 +37,7 @@ sub query_params { { param => 'name', description => 'Filter for items matching a source set name pattern', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/CFTimeSets.pm b/lib/NGCP/Panel/Controller/API/CFTimeSets.pm index f8da8bf85a..a10001c33f 100644 --- a/lib/NGCP/Panel/Controller/API/CFTimeSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFTimeSets.pm @@ -37,13 +37,7 @@ sub query_params { { param => 'name', description => 'Filter for contacts matching a timeset name pattern', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/Contracts.pm b/lib/NGCP/Panel/Controller/API/Contracts.pm index 2074419c5e..da47990e4e 100644 --- a/lib/NGCP/Panel/Controller/API/Contracts.pm +++ b/lib/NGCP/Panel/Controller/API/Contracts.pm @@ -49,13 +49,7 @@ sub query_params { { param => 'external_id', description => 'Filter for contracts with a specific external id', - query => { - first => sub { - my $q = shift; - { 'me.external_id' => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'type', diff --git a/lib/NGCP/Panel/Controller/API/CustomerBalances.pm b/lib/NGCP/Panel/Controller/API/CustomerBalances.pm index 1a726eff00..30eb861d06 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerBalances.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerBalances.pm @@ -60,13 +60,7 @@ sub query_params { { param => 'external_id', description => 'Filter for contracts with a specific external id', - query => { - first => sub { - my $q = shift; - { 'me.external_id' => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'domain', diff --git a/lib/NGCP/Panel/Controller/API/CustomerContacts.pm b/lib/NGCP/Panel/Controller/API/CustomerContacts.pm index 79bbc43e3d..aadf069d46 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerContacts.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerContacts.pm @@ -23,14 +23,8 @@ sub query_params { return [ { param => 'email', - description => 'Filter for contacts matching an email pattern', - query => { - first => sub { - my $q = shift; - { email => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for contacts for the email address', + query_type => 'wildcard', }, { param => 'reseller_id', diff --git a/lib/NGCP/Panel/Controller/API/CustomerLocations.pm b/lib/NGCP/Panel/Controller/API/CustomerLocations.pm index 0e53ffdc37..7df8780e89 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerLocations.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerLocations.pm @@ -35,14 +35,8 @@ sub query_params { }, { param => 'name', - description => 'Filter for customer locations matching a name pattern', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for customer locations by name', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/Customers.pm b/lib/NGCP/Panel/Controller/API/Customers.pm index d10ea1e878..e73293252b 100644 --- a/lib/NGCP/Panel/Controller/API/Customers.pm +++ b/lib/NGCP/Panel/Controller/API/Customers.pm @@ -74,13 +74,7 @@ sub query_params { { param => 'external_id', description => 'Filter for customer with specific external_id', - query => { - first => sub { - my $q = shift; - { 'me.external_id' => { like => $q } }; - }, - second => sub { }, - }, + query_type => 'wildcard', }, { param => 'contact_id', diff --git a/lib/NGCP/Panel/Controller/API/Domains.pm b/lib/NGCP/Panel/Controller/API/Domains.pm index 6086a6daa1..db51ef6b75 100644 --- a/lib/NGCP/Panel/Controller/API/Domains.pm +++ b/lib/NGCP/Panel/Controller/API/Domains.pm @@ -28,14 +28,8 @@ sub query_params { }, { param => 'domain', - description => 'Filter for domains matching the given pattern', - query => { - first => sub { - my $q = shift; - { domain => { like => $q } }; - }, - second => sub { }, - }, + description => 'Filter for for a domain name', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/EmailTemplates.pm b/lib/NGCP/Panel/Controller/API/EmailTemplates.pm index 39a8717074..8c5391ac26 100644 --- a/lib/NGCP/Panel/Controller/API/EmailTemplates.pm +++ b/lib/NGCP/Panel/Controller/API/EmailTemplates.pm @@ -34,13 +34,7 @@ sub query_params { { param => 'name', description => 'Filter for email templates with a specific name', - query => { - first => sub { - my $q = shift; - { 'me.name' => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/EmergencyMappingContainers.pm b/lib/NGCP/Panel/Controller/API/EmergencyMappingContainers.pm index 78339a485a..f1137a1e61 100644 --- a/lib/NGCP/Panel/Controller/API/EmergencyMappingContainers.pm +++ b/lib/NGCP/Panel/Controller/API/EmergencyMappingContainers.pm @@ -23,14 +23,8 @@ sub query_params { return [ { param => 'name', - description => 'Filter for emergency mapping containers with a specific name (wildcards possible)', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for emergency mapping containers with a specific name', + query_type => 'wildcard', }, { param => 'reseller_id', diff --git a/lib/NGCP/Panel/Controller/API/EmergencyMappings.pm b/lib/NGCP/Panel/Controller/API/EmergencyMappings.pm index 5e473140a2..82a437df27 100644 --- a/lib/NGCP/Panel/Controller/API/EmergencyMappings.pm +++ b/lib/NGCP/Panel/Controller/API/EmergencyMappings.pm @@ -51,14 +51,8 @@ sub query_params { }, { param => 'code', - description => 'Filter for mappings with a specific code (wildcards possible)', - query => { - first => sub { - my $q = shift; - { code => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for mappings with a specific code', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/Events.pm b/lib/NGCP/Panel/Controller/API/Events.pm index 2d255aeb33..72916035d4 100644 --- a/lib/NGCP/Panel/Controller/API/Events.pm +++ b/lib/NGCP/Panel/Controller/API/Events.pm @@ -46,13 +46,7 @@ sub query_params { { param => 'type', description => 'Filter for events of a specific type.', - query => { - first => sub { - my $q = shift; - { type => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'timestamp_from', diff --git a/lib/NGCP/Panel/Controller/API/FaxserverSettings.pm b/lib/NGCP/Panel/Controller/API/FaxserverSettings.pm index bb5ba7a3c5..8c0967b6ec 100644 --- a/lib/NGCP/Panel/Controller/API/FaxserverSettings.pm +++ b/lib/NGCP/Panel/Controller/API/FaxserverSettings.pm @@ -24,7 +24,7 @@ sub query_params { description => 'Filter for items (subscribers) where name or password field match given pattern', query => { first => sub { - my $q = shift; + my ($q,$is_pattern) = escape_search_string_pattern(shift); return { '-or' => [ { 'voip_fax_preference.name' => { like => $q } }, { 'voip_fax_preference.password' => { like => $q } }, diff --git a/lib/NGCP/Panel/Controller/API/HeaderRuleSets.pm b/lib/NGCP/Panel/Controller/API/HeaderRuleSets.pm index 8fdd637c68..69fb916a8a 100644 --- a/lib/NGCP/Panel/Controller/API/HeaderRuleSets.pm +++ b/lib/NGCP/Panel/Controller/API/HeaderRuleSets.pm @@ -35,13 +35,13 @@ sub query_params { }, { param => 'name', - description => 'Filter for header rule sets with a specific name (wildcard pattern allowed)', - query_type => 'string_like', + description => 'Filter for header rule sets with a specific name', + query_type => 'wildcard', }, { param => 'description', - description => 'Filter header rule sets for a certain description (wildcard pattern allowed).', - query_type => 'string_like', + description => 'Filter header rule sets for a certain description', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/HeaderRules.pm b/lib/NGCP/Panel/Controller/API/HeaderRules.pm index 184a699f1a..aa8f79e7d6 100644 --- a/lib/NGCP/Panel/Controller/API/HeaderRules.pm +++ b/lib/NGCP/Panel/Controller/API/HeaderRules.pm @@ -24,21 +24,13 @@ sub query_params { return [ { param => 'name', - description => 'Filter for header rules with a specific name (wildcard pattern allowed)', - query => { - first => sub { - +{ 'me.name' => { like => shift } }; - } - }, + description => 'Filter for header rules with a specific name', + query_type => 'wildcard', }, { param => 'description', - description => 'Filter rules for a certain description (wildcards possible).', - query => { - first => sub { - +{ 'me.description' => { like => shift } }; - } - }, + description => 'Filter rules for a certain description', + query_type => 'wildcard', }, { param => 'set_id', diff --git a/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm b/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm index ab7b94084a..1057585aaa 100644 --- a/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm +++ b/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm @@ -34,13 +34,7 @@ sub query_params { { param => 'name', description => 'Filter for invoice templates with a specific name', - query => { - first => sub { - my $q = shift; - { 'me.name' => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/Invoices.pm b/lib/NGCP/Panel/Controller/API/Invoices.pm index ce8e9051e5..fd3ab27be3 100644 --- a/lib/NGCP/Panel/Controller/API/Invoices.pm +++ b/lib/NGCP/Panel/Controller/API/Invoices.pm @@ -66,8 +66,8 @@ sub query_params { }, { param => 'serial', - description => 'Filter for invoices matching a serial (patterns allowed)', - query_type => 'string_like', + description => 'Filter for invoices matching a serial', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/LnpCarriers.pm b/lib/NGCP/Panel/Controller/API/LnpCarriers.pm index 1ce872de55..832b97dfd3 100644 --- a/lib/NGCP/Panel/Controller/API/LnpCarriers.pm +++ b/lib/NGCP/Panel/Controller/API/LnpCarriers.pm @@ -23,25 +23,13 @@ sub query_params { return [ { param => 'prefix', - description => 'Filter for LNP carriers with a specific prefix (wildcards possible)', - query => { - first => sub { - my $q = shift; - { prefix => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for LNP carriers with a specific prefix', + query_type => 'wildcard', }, { param => 'name', - description => 'Filter for LNP carriers with a specific name (wildcards possible)', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for LNP carriers with a specific name', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/LnpNumbers.pm b/lib/NGCP/Panel/Controller/API/LnpNumbers.pm index 6a250da990..cfdfa132e5 100644 --- a/lib/NGCP/Panel/Controller/API/LnpNumbers.pm +++ b/lib/NGCP/Panel/Controller/API/LnpNumbers.pm @@ -37,14 +37,8 @@ sub query_params { }, { param => 'number', - description => 'Filter for LNP numbers with a specific number (wildcards possible)', - query => { - first => sub { - my $q = shift; - { 'me.number' => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for LNP numbers with a specific number', + query_type => 'wildcard', }, { param => 'actual', diff --git a/lib/NGCP/Panel/Controller/API/NcosLevels.pm b/lib/NGCP/Panel/Controller/API/NcosLevels.pm index 98c0081d0d..74bdee2a74 100644 --- a/lib/NGCP/Panel/Controller/API/NcosLevels.pm +++ b/lib/NGCP/Panel/Controller/API/NcosLevels.pm @@ -34,13 +34,7 @@ sub query_params { { param => 'level', description => 'Filter for levels matching the given pattern', - query => { - first => sub { - my $q = shift; - { level => { like => $q } }; - }, - second => sub { }, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/Numbers.pm b/lib/NGCP/Panel/Controller/API/Numbers.pm index 1bd4bfece8..611cb416bf 100644 --- a/lib/NGCP/Panel/Controller/API/Numbers.pm +++ b/lib/NGCP/Panel/Controller/API/Numbers.pm @@ -60,17 +60,17 @@ sub query_params { { param => 'ac', description => 'Filter for ac field of the number.', - query_type => 'string_like', + query_type => 'wildcard', }, { param => 'cc', description => 'Filter for cc field c the number.', - query_type => 'string_like', + query_type => 'wildcard', }, { param => 'sn', description => 'Filter for sn field c the number.', - query_type => 'string_like', + query_type => 'wildcard', }, { param => 'type', diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceModels.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceModels.pm index b2bdad8ab5..9ef686c1fc 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceModels.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceModels.pm @@ -42,8 +42,8 @@ sub query_params { }, { param => 'model', - description => 'Filter for models matching a model name pattern', - query_type => 'string_like', + description => 'Filter for models by name', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm index 43aaeece22..baaf0a21bc 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm @@ -22,25 +22,13 @@ sub query_params { return [ { param => 'name', - description => 'Filter for profiles matching a name pattern', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for profiles by name', + query_type => 'wildcard', }, { param => 'config_id', - description => 'Filter for profiles matching a config_id', - query => { - first => sub { - my $q = shift; - { 'config_id' => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for profiles by config_id', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/PbxDevices.pm b/lib/NGCP/Panel/Controller/API/PbxDevices.pm index 274f201bee..31f36d1603 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDevices.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDevices.pm @@ -44,21 +44,21 @@ sub query_params { }, { param => 'identifier', - description => 'Search for PBX devices matching an identifier/MAC pattern (wildcards possible)', - query_type => 'string_like', + description => 'Search for PBX devices matching an identifier/MAC pattern', + query_type => 'wildcard', }, { param => 'station_name', - description => 'Search for PBX devices matching a station_name pattern (wildcards possible)', - query_type => 'string_like', + description => 'Search for PBX devices matching a station_name pattern', + query_type => 'wildcard', }, { param => 'pbx_extension', - description => 'Search for PBX devices matching a subscriber\'s extension pattern (wildcards possible)', + description => 'Search for PBX devices matching a subscriber\'s extension pattern', query => { first => sub { - my $q = shift; - { 'provisioning_voip_subscriber.pbx_extension' => { like => "$q%" } }; + my ($q,$is_pattern) = escape_search_string_pattern(shift); + { 'provisioning_voip_subscriber.pbx_extension' => { like => $q } }; }, second => sub { @@ -68,13 +68,13 @@ sub query_params { }, { param => 'display_name', - description => 'Search for PBX devices matching a subscriber\'s display name pattern (wildcards possible)', + description => 'Search for PBX devices matching a subscriber\'s display name pattern', query => { first => sub { - my $q = shift; + my ($q,$is_pattern) = escape_search_string_pattern(shift); { 'attribute.attribute' => 'display_name', - 'voip_usr_preferences.value' => { like => "$q%" } + 'voip_usr_preferences.value' => { like => $q } }; }, diff --git a/lib/NGCP/Panel/Controller/API/PeeringGroups.pm b/lib/NGCP/Panel/Controller/API/PeeringGroups.pm index beb3d0c47e..54bc43829a 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringGroups.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringGroups.pm @@ -23,26 +23,14 @@ sub api_description { sub query_params { return [ { - param => 'name', + param => 'model', description => 'Filter for peering group name', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'description', description => 'Filter for peering group description', - query => { - first => sub { - my $q = shift; - { description => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/PeeringInboundRules.pm b/lib/NGCP/Panel/Controller/API/PeeringInboundRules.pm index ba79367eed..7c0cdc1ef3 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringInboundRules.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringInboundRules.pm @@ -34,14 +34,8 @@ sub query_params { }, { param => 'field', - description => 'Filter for peering rules field (wildcards possible)', - query => { - first => sub { - my $q = shift; - { field => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for peering rules field', + query_type => 'wildcard', }, { param => 'enabled', diff --git a/lib/NGCP/Panel/Controller/API/PeeringRules.pm b/lib/NGCP/Panel/Controller/API/PeeringRules.pm index f175741ca4..7b1bb1df84 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringRules.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringRules.pm @@ -39,13 +39,7 @@ sub query_params { { param => 'description', description => 'Filter for peering rules description', - query => { - first => sub { - my $q = shift; - { description => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'enabled', diff --git a/lib/NGCP/Panel/Controller/API/PeeringServers.pm b/lib/NGCP/Panel/Controller/API/PeeringServers.pm index a83f71fd7b..5f1c98adfa 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringServers.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringServers.pm @@ -35,35 +35,17 @@ sub query_params { { param => 'name', description => 'Filter for peering server name', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'host', description => 'Filter for peering server host', - query => { - first => sub { - my $q = shift; - { host => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'ip', description => 'Filter for peering server ip', - query => { - first => sub { - my $q = shift; - { host => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'enabled', diff --git a/lib/NGCP/Panel/Controller/API/PhonebookEntries.pm b/lib/NGCP/Panel/Controller/API/PhonebookEntries.pm index db73ff19b9..db826e2a9c 100644 --- a/lib/NGCP/Panel/Controller/API/PhonebookEntries.pm +++ b/lib/NGCP/Panel/Controller/API/PhonebookEntries.pm @@ -55,13 +55,13 @@ sub query_params { }, { param => 'number', - description => 'Filter for Phonebook numbers with a specific number (wildcards possible)', - query_type => 'string_like', + description => 'Filter for Phonebook numbers with a specific number', + query_type => 'wildcard', }, { param => 'name', - description => 'Filter for Phonebook numbers with a specific name (wildcards possible)', - query_type => 'string_like', + description => 'Filter for Phonebook numbers with a specific name', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/ProfilePackages.pm b/lib/NGCP/Panel/Controller/API/ProfilePackages.pm index 115488303c..df24a1b570 100644 --- a/lib/NGCP/Panel/Controller/API/ProfilePackages.pm +++ b/lib/NGCP/Panel/Controller/API/ProfilePackages.pm @@ -36,20 +36,14 @@ sub query_params { { param => 'name', description => 'Filter for profile packages with a specific name', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'profile_name', - description => 'Filter for profile packages containing a billing profile with specific name', + description => 'Filter for profile packages containing a billing profile with specific name pattern', query => { first => sub { - my $q = shift; + my ($q,$is_pattern) = escape_search_string_pattern(shift); { 'billing_profile.name' => { like => $q } }; }, second => sub { @@ -60,10 +54,10 @@ sub query_params { }, { param => 'network_name', - description => 'Filter for profile packages containing a billing network with specific name', + description => 'Filter for profile packages containing a billing network with specific name pattern', query => { first => sub { - my $q = shift; + my ($q,$is_pattern) = escape_search_string_pattern(shift); { 'billing_network.name' => { like => $q } }; }, second => sub { diff --git a/lib/NGCP/Panel/Controller/API/Resellers.pm b/lib/NGCP/Panel/Controller/API/Resellers.pm index 2c73f13a93..2082dfa783 100644 --- a/lib/NGCP/Panel/Controller/API/Resellers.pm +++ b/lib/NGCP/Panel/Controller/API/Resellers.pm @@ -24,14 +24,8 @@ sub query_params { return [ { param => 'name', - description => 'Filter for resellers matching the given name pattern', - query => { - first => sub { - my $q = shift; - { name => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for resellers by name', + query_type => 'wildcard', }, { param => 'status', diff --git a/lib/NGCP/Panel/Controller/API/RewriteRuleSets.pm b/lib/NGCP/Panel/Controller/API/RewriteRuleSets.pm index d47d2f72c2..260aa51eca 100644 --- a/lib/NGCP/Panel/Controller/API/RewriteRuleSets.pm +++ b/lib/NGCP/Panel/Controller/API/RewriteRuleSets.pm @@ -29,13 +29,13 @@ sub query_params { }, { param => 'description', - description => 'Filter rulesets for a certain description (wildcards possible).', - query_type => 'string_like', + description => 'Filter rulesets for a certain description', + query_type => 'wildcard', }, { param => 'name', - description => 'Filter rulesets for a certain name (wildcards possible).', - query_type => 'string_like', + description => 'Filter rulesets for a certain name', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/RewriteRules.pm b/lib/NGCP/Panel/Controller/API/RewriteRules.pm index a8435d3ec2..207648e1cb 100644 --- a/lib/NGCP/Panel/Controller/API/RewriteRules.pm +++ b/lib/NGCP/Panel/Controller/API/RewriteRules.pm @@ -23,8 +23,8 @@ sub query_params { return [ { param => 'description', - description => 'Filter rules for a certain description (wildcards possible).', - query_type => 'string_like', + description => 'Filter rules for a certain description', + query_type => 'wildcard', }, { param => 'set_id', diff --git a/lib/NGCP/Panel/Controller/API/SoundGroups.pm b/lib/NGCP/Panel/Controller/API/SoundGroups.pm index 8bde218eae..6eabcf5c18 100644 --- a/lib/NGCP/Panel/Controller/API/SoundGroups.pm +++ b/lib/NGCP/Panel/Controller/API/SoundGroups.pm @@ -24,7 +24,7 @@ sub query_params { { param => 'name', description => 'Filter for sound groups with a specific name', - query_type => 'string_like', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/SoundSets.pm b/lib/NGCP/Panel/Controller/API/SoundSets.pm index b109027ebf..a5d9752f73 100644 --- a/lib/NGCP/Panel/Controller/API/SoundSets.pm +++ b/lib/NGCP/Panel/Controller/API/SoundSets.pm @@ -38,8 +38,8 @@ sub query_params { }, { param => 'name', - description => 'Filter for sound sets with a specific name (wildcard pattern allowed)', - query_type => 'string_like', + description => 'Filter for sound sets with a specific name', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/SubscriberProfileSets.pm b/lib/NGCP/Panel/Controller/API/SubscriberProfileSets.pm index c5c8171d16..899614d58e 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberProfileSets.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberProfileSets.pm @@ -34,13 +34,7 @@ sub query_params { { param => 'name', description => 'Filter for profile sets with a specific name', - query => { - first => sub { - my $q = shift; - { 'me.name' => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/SubscriberProfiles.pm b/lib/NGCP/Panel/Controller/API/SubscriberProfiles.pm index 28a1bdbdf8..81d0440eeb 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberProfiles.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberProfiles.pm @@ -34,13 +34,7 @@ sub query_params { { param => 'name', description => 'Filter for profile with a specific name', - query => { - first => sub { - my $q = shift; - { 'me.name' => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/Subscribers.pm b/lib/NGCP/Panel/Controller/API/Subscribers.pm index 3e41e99ca5..a9d457569f 100644 --- a/lib/NGCP/Panel/Controller/API/Subscribers.pm +++ b/lib/NGCP/Panel/Controller/API/Subscribers.pm @@ -57,13 +57,7 @@ sub query_params { { param => 'username', description => 'Search for specific SIP username', - query => { - first => sub { - my $q = shift; - return { 'me.username' => { like => $q } }; - }, - second => sub {}, - }, + query_type => 'wildcard', }, { param => 'webusername', @@ -80,10 +74,10 @@ sub query_params { }, { param => 'domain', - description => 'Filter for subscribers in specific domain', + description => 'Filter for subscribers in specific domain pattern', query => { first => sub { - my $q = shift; + my ($q,$is_pattern) = escape_search_string_pattern(shift); return { 'domain.domain' => { like => $q } }; }, second => sub { @@ -107,10 +101,10 @@ sub query_params { }, { param => 'customer_external_id', - description => 'Filter for subscribers of a specific customer external_id.', + description => 'Filter for subscribers of a specific customer external_id pattern', query => { first => sub { - my $q = shift; + my ($q,$is_pattern) = escape_search_string_pattern(shift); return { 'contract.external_id' => { like => $q } }; }, second => sub { @@ -120,10 +114,10 @@ sub query_params { }, { param => 'subscriber_external_id', - description => 'Filter for subscribers by subscriber\'s external_id.', + description => 'Filter for subscribers by subscriber\'s external_id pattern', query => { first => sub { - my $q = shift; + my ($q,$is_pattern) = escape_search_string_pattern(shift); return { 'me.external_id' => { like => $q } }; }, second => sub { @@ -184,12 +178,12 @@ sub query_params { }, { param => 'alias', - description => 'Filter for subscribers who has specified alias.', + description => 'Filter for subscribers who has specified alias pattern', query => { first => sub { - my $q = shift; + my ($q,$is_pattern) = escape_search_string_pattern(shift); { - 'voip_dbaliases.username' => { like => '%'.$q.'%' }, + 'voip_dbaliases.username' => { like => $q }, }; }, second => sub { @@ -226,11 +220,11 @@ sub query_params { }, { param => 'primary_number', - description => 'Filter for subscribers of contracts with a specific primary number', + description => 'Filter for subscribers of contracts with a specific primary number pattern', query => { first => sub { - my $q = shift; - { \['concat(primary_number.cc, primary_number.ac, primary_number.sn) like ?', "%$q%"] }; + my ($q,$is_pattern) = escape_search_string_pattern(shift); + { \['concat(primary_number.cc, primary_number.ac, primary_number.sn) like ?', $q ] }; }, second => sub { @@ -243,8 +237,8 @@ sub query_params { description => 'Filter for subscribers of contracts with a specific PBX extension', query => { first => sub { - my $q = shift; - { 'provisioning_voip_subscriber.pbx_extension' => { like => "%$q%" } }; + my ($q,$is_pattern) = escape_search_string_pattern(shift); + { 'provisioning_voip_subscriber.pbx_extension' => { like => $q } }; }, second => sub { @@ -257,10 +251,10 @@ sub query_params { description => 'Filter for subscribers of contracts with a specific display name', query => { first => sub { - my $q = shift; + my ($q,$is_pattern) = escape_search_string_pattern(shift); { 'attribute.attribute' => 'display_name', - 'voip_usr_preferences.value' => { like => "%$q%" } + 'voip_usr_preferences.value' => { like => $q } }; }, diff --git a/lib/NGCP/Panel/Controller/API/SystemContacts.pm b/lib/NGCP/Panel/Controller/API/SystemContacts.pm index acbb893674..fb4af9ca56 100644 --- a/lib/NGCP/Panel/Controller/API/SystemContacts.pm +++ b/lib/NGCP/Panel/Controller/API/SystemContacts.pm @@ -23,14 +23,8 @@ sub query_params { return [ { param => 'email', - description => 'Filter for contacts matching an email pattern', - query => { - first => sub { - my $q = shift; - { email => { like => $q } }; - }, - second => sub {}, - }, + description => 'Filter for contacts by email address', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/TimeSets.pm b/lib/NGCP/Panel/Controller/API/TimeSets.pm index 6a303e3da8..78c02f01d4 100644 --- a/lib/NGCP/Panel/Controller/API/TimeSets.pm +++ b/lib/NGCP/Panel/Controller/API/TimeSets.pm @@ -37,8 +37,8 @@ sub query_params { }, { param => 'name', - description => 'Filter for items matching a Time Set name pattern', - query_type => 'string_like', + description => 'Filter for items by Time Set name', + query_type => 'wildcard', }, ]; } diff --git a/lib/NGCP/Panel/Controller/API/VoicemailGreetings.pm b/lib/NGCP/Panel/Controller/API/VoicemailGreetings.pm index 7ee701f9bc..f1c977542c 100644 --- a/lib/NGCP/Panel/Controller/API/VoicemailGreetings.pm +++ b/lib/NGCP/Panel/Controller/API/VoicemailGreetings.pm @@ -62,8 +62,9 @@ sub query_params { query => { first => sub { my $q = shift; + ($q, my $is_pattern) = escape_search_string_pattern('/var/spool/asterisk/voicemail/*/' . $q); return { - 'me.dir' => { like => '/var/spool/asterisk/voicemail/%/'.$q }, + 'me.dir' => { like => $q }, }; }, second => sub {}, diff --git a/lib/NGCP/Panel/Controller/API/Voicemails.pm b/lib/NGCP/Panel/Controller/API/Voicemails.pm index d2ce134e21..a5adc80710 100644 --- a/lib/NGCP/Panel/Controller/API/Voicemails.pm +++ b/lib/NGCP/Panel/Controller/API/Voicemails.pm @@ -40,14 +40,15 @@ sub query_params { second => sub { }, }, }, - { + YYYY{ param => 'folder', description => 'Filter for voicemails in a specific folder (one of INBOX, Old, Friends, Family, Cust1 to Cust4)', query => { first => sub { my $q = shift; + ($q, my $is_pattern) = escape_search_string_pattern('*/' . $q); # join is already done in get_item_rs - { 'me.dir' => { like => '%/'.$q } }; + { 'me.dir' => { like => $q } }; }, second => sub { }, }, diff --git a/lib/NGCP/Panel/Role/API.pm b/lib/NGCP/Panel/Role/API.pm index 64878e6d58..2f3c904d6e 100644 --- a/lib/NGCP/Panel/Role/API.pm +++ b/lib/NGCP/Panel/Role/API.pm @@ -1167,6 +1167,14 @@ sub get_query_callbacks{ } elsif ('string_eq' eq $p[0]->{query_type}) { $sub_where = sub {my ($q, $c) = @_; { $param => $q };}; } elsif ('wildcard' eq $p[0]->{query_type}) { + $sub_where = sub {my ($q, $c) = @_; { wildcard_search( + search_string => $q, + search => 1, + exact_search => 0, + int_search => 0, + col_name => $param, + ) };}; + } elsif ('wildcard_optional' eq $p[0]->{query_type}) { $sub_where = sub {my ($q, $c) = @_; { wildcard_search( search_string => $q, search => 1, diff --git a/lib/NGCP/Panel/Utils/Generic.pm b/lib/NGCP/Panel/Utils/Generic.pm index 3a99f876ba..8954042990 100644 --- a/lib/NGCP/Panel/Utils/Generic.pm +++ b/lib/NGCP/Panel/Utils/Generic.pm @@ -249,9 +249,15 @@ sub escape_search_string_pattern { } $token; } split(/(\\\\)/,$searchString,-1)); - if (not $is_pattern and not $no_pattern) { - $searchString_escaped .= '%'; - $is_pattern = 1; + if (not $is_pattern and not $no_pattern and length($searchString_escaped) > 0) { + #if ($append) { + $searchString_escaped .= '%'; + $is_pattern = 1; + #} + #if ($prepend) { + # $searchString_escaped = '%' . $searchString_escaped; + # $is_pattern = 1; + #} } return ($searchString_escaped,$is_pattern); diff --git a/share/templates/api/root/collection.tt b/share/templates/api/root/collection.tt index 1e555a6a63..bb5ccbb6cf 100644 --- a/share/templates/api/root/collection.tt +++ b/share/templates/api/root/collection.tt @@ -109,7 +109,11 @@ See description how to obtain properties, if any.