From 554daba5fe7003a11e0b8a2b73c18eda9b5f73b1 Mon Sep 17 00:00:00 2001 From: Christophe Maudoux Date: Mon, 4 Jan 2021 20:23:42 +0100 Subject: [PATCH] Allow multi-valued excluding parameters (#1976) --- .../Lemonldap/NG/Portal/Plugins/FindUser.pm | 31 +++++++++---------- lemonldap-ng-portal/t/68-FindUser-with-DBI.t | 6 +++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FindUser.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FindUser.pm index 4e81aee89..4a5358ff1 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FindUser.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FindUser.pm @@ -85,29 +85,28 @@ sub provideUser { sub retreiveFindUserParams { my ( $self, $req ) = @_; my ( $searching, $excluding ) = ( [], [] ); + $self->logger->debug("FindUser: reading parameters..."); - foreach ( sort keys %{ $self->conf->{findUserSearchingAttributes} } ) { + @$searching = map { my $param = $req->params($_) // ''; - if ( $param =~ /.+/ ) { - $self->logger->debug( - "Pushing searching parameter: $_ => $param" ); - push @$searching, { key => $_, value => $param }; - } - } + $self->logger->debug("Push searching parameter: $_ => $param") + if $param =~ /.+/; + $param =~ /.+/ ? { key => $_, value => $param } : (); + } sort keys %{ $self->conf->{findUserSearchingAttributes} }; if ( scalar @$searching && keys %{ $self->conf->{findUserExcludingAttributes} } ) { $self->logger->debug("FindUser: reading excluding parameters..."); - foreach ( sort keys %{ $self->conf->{findUserExcludingAttributes} } ) { - $self->logger->debug( "Pushing excluding parameter: $_ => " - . $self->conf->{findUserExcludingAttributes}->{$_} ); - push @$excluding, - { - key => $_, - value => $self->conf->{findUserExcludingAttributes}->{$_} - }; - } + @$excluding = map { + my $key = $_; + map { + $self->logger->debug("Push excluding parameter: $key => $_"); + { key => $key, + value => $_ } # Allow multivalued excluding parameters + } split $self->conf->{multiValuesSeparator}, + $self->conf->{findUserExcludingAttributes}->{$_}; + } sort keys %{ $self->conf->{findUserExcludingAttributes} }; } return ( $searching, $excluding ); diff --git a/lemonldap-ng-portal/t/68-FindUser-with-DBI.t b/lemonldap-ng-portal/t/68-FindUser-with-DBI.t index a50a1ebc9..30f9c955c 100644 --- a/lemonldap-ng-portal/t/68-FindUser-with-DBI.t +++ b/lemonldap-ng-portal/t/68-FindUser-with-DBI.t @@ -33,6 +33,9 @@ SKIP: { "INSERT INTO users VALUES ('msmith','msmith','Mr Smith','character','good','0')" ); $dbh->do( +"INSERT INTO users VALUES ('davrosjr','davrosjr','Davros Junior','character','bad','0')" + ); + $dbh->do( "INSERT INTO users VALUES ('dalek','dalek', 'The Daleks','mutant','bad','1')" ); my $client = LLNG::Manager::Test->new( { @@ -41,6 +44,7 @@ SKIP: { authentication => 'DBI', userDB => 'Same', dbiAuthChain => "dbi:SQLite:dbname=$userdb", + multiValuesSeparator => ' # ', dbiAuthUser => '', dbiAuthPassword => '', dbiAuthTable => 'users', @@ -59,7 +63,7 @@ SKIP: { room => 'Room' }, findUserExcludingAttributes => - { type => 'mutant', uid => 'rtyler' }, + { type => 'mutant', uid => 'rtyler # davrosjr # ' }, } } );