Allow multi-valued excluding parameters (#1976)

This commit is contained in:
Christophe Maudoux 2021-01-04 20:23:42 +01:00
parent fc6ea96954
commit 554daba5fe
2 changed files with 20 additions and 17 deletions

View File

@ -85,29 +85,28 @@ sub provideUser {
sub retreiveFindUserParams { sub retreiveFindUserParams {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
my ( $searching, $excluding ) = ( [], [] ); my ( $searching, $excluding ) = ( [], [] );
$self->logger->debug("FindUser: reading parameters..."); $self->logger->debug("FindUser: reading parameters...");
foreach ( sort keys %{ $self->conf->{findUserSearchingAttributes} } ) { @$searching = map {
my $param = $req->params($_) // ''; my $param = $req->params($_) // '';
if ( $param =~ /.+/ ) { $self->logger->debug("Push searching parameter: $_ => $param")
$self->logger->debug( if $param =~ /.+/;
"Pushing searching parameter: $_ => $param" ); $param =~ /.+/ ? { key => $_, value => $param } : ();
push @$searching, { key => $_, value => $param }; } sort keys %{ $self->conf->{findUserSearchingAttributes} };
}
}
if ( scalar @$searching if ( scalar @$searching
&& keys %{ $self->conf->{findUserExcludingAttributes} } ) && keys %{ $self->conf->{findUserExcludingAttributes} } )
{ {
$self->logger->debug("FindUser: reading excluding parameters..."); $self->logger->debug("FindUser: reading excluding parameters...");
foreach ( sort keys %{ $self->conf->{findUserExcludingAttributes} } ) { @$excluding = map {
$self->logger->debug( "Pushing excluding parameter: $_ => " my $key = $_;
. $self->conf->{findUserExcludingAttributes}->{$_} ); map {
push @$excluding, $self->logger->debug("Push excluding parameter: $key => $_");
{ { key => $key,
key => $_, value => $_ } # Allow multivalued excluding parameters
value => $self->conf->{findUserExcludingAttributes}->{$_} } split $self->conf->{multiValuesSeparator},
}; $self->conf->{findUserExcludingAttributes}->{$_};
} } sort keys %{ $self->conf->{findUserExcludingAttributes} };
} }
return ( $searching, $excluding ); return ( $searching, $excluding );

View File

@ -33,6 +33,9 @@ SKIP: {
"INSERT INTO users VALUES ('msmith','msmith','Mr Smith','character','good','0')" "INSERT INTO users VALUES ('msmith','msmith','Mr Smith','character','good','0')"
); );
$dbh->do( $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')" "INSERT INTO users VALUES ('dalek','dalek', 'The Daleks','mutant','bad','1')"
); );
my $client = LLNG::Manager::Test->new( { my $client = LLNG::Manager::Test->new( {
@ -41,6 +44,7 @@ SKIP: {
authentication => 'DBI', authentication => 'DBI',
userDB => 'Same', userDB => 'Same',
dbiAuthChain => "dbi:SQLite:dbname=$userdb", dbiAuthChain => "dbi:SQLite:dbname=$userdb",
multiValuesSeparator => ' # ',
dbiAuthUser => '', dbiAuthUser => '',
dbiAuthPassword => '', dbiAuthPassword => '',
dbiAuthTable => 'users', dbiAuthTable => 'users',
@ -59,7 +63,7 @@ SKIP: {
room => 'Room' room => 'Room'
}, },
findUserExcludingAttributes => findUserExcludingAttributes =>
{ type => 'mutant', uid => 'rtyler' }, { type => 'mutant', uid => 'rtyler # davrosjr # ' },
} }
} }
); );