Allow input type select with FindUser (#1976)
This commit is contained in:
parent
8debc0fd1d
commit
7c3955b2aa
|
@ -479,20 +479,17 @@ sub display {
|
|||
|
||||
# Display authentication form
|
||||
else {
|
||||
my $plugin =
|
||||
$self->loadedModules->{
|
||||
"Lemonldap::NG::Portal::Plugins::FindUser"};
|
||||
my $fields = [];
|
||||
if ( $self->conf->{findUser}
|
||||
if ( $plugin
|
||||
&& $self->conf->{findUser}
|
||||
&& $self->conf->{impersonationRule}
|
||||
&& $self->conf->{findUserSearchingAttributes} )
|
||||
{
|
||||
$login = $req->data->{findUser};
|
||||
$self->logger->debug(
|
||||
'Building array ref with searching fields...');
|
||||
@$fields = map { {
|
||||
key => $_,
|
||||
value =>
|
||||
$self->conf->{findUserSearchingAttributes}->{$_}
|
||||
};
|
||||
} sort keys %{ $self->conf->{findUserSearchingAttributes} };
|
||||
$login = $req->data->{findUser};
|
||||
$fields = $plugin->buildForm();
|
||||
}
|
||||
|
||||
# Authentication loop
|
||||
|
|
|
@ -88,13 +88,15 @@ sub retreiveFindUserParams {
|
|||
|
||||
$self->logger->debug("FindUser: reading parameters...");
|
||||
@$searching = map {
|
||||
my $param = $req->params($_) // '';
|
||||
if ( $param =~ /$self->{conf}->{findUserControl}/o ) {
|
||||
$self->logger->debug("Push searching parameter: $_ => $param");
|
||||
{ key => $_, value => $param };
|
||||
my $key = ( split '#', $_ )[0];
|
||||
my $value = $req->params($key) // '';
|
||||
if ( $value =~ /$self->{conf}->{findUserControl}/o ) {
|
||||
$self->logger->debug("Push searching parameter: $key => $value");
|
||||
{ key => $key, value => $value };
|
||||
}
|
||||
else {
|
||||
$self->logger->warn("Parameter $_ has been reject by findUserControl");
|
||||
$self->logger->warn(
|
||||
"Parameter $key has been reject by findUserControl");
|
||||
();
|
||||
}
|
||||
} sort keys %{ $self->conf->{findUserSearchingAttributes} };
|
||||
|
@ -119,4 +121,48 @@ sub retreiveFindUserParams {
|
|||
return ( $searching, $excluding );
|
||||
}
|
||||
|
||||
sub buildForm {
|
||||
my $self = shift;
|
||||
my $fields = [];
|
||||
$self->logger->debug('Building array ref with searching fields...');
|
||||
@$fields =
|
||||
sort { $a->{select} <=> $b->{select} || $a->{value} cmp $b->{value} }
|
||||
map {
|
||||
my ( $key, $value, $null ) = split '#', $_;
|
||||
my @values = split $self->conf->{multiValuesSeparator},
|
||||
$self->conf->{findUserSearchingAttributes}->{$_} || $_;
|
||||
my $nbr = scalar @values;
|
||||
if ( $nbr > 1 ) {
|
||||
if ( $nbr % 2 ) { () }
|
||||
else {
|
||||
my %hash = @values;
|
||||
my $choices = [];
|
||||
$nbr /= 2;
|
||||
$self->logger->debug(
|
||||
"Building $key with type 'select' and $nbr entries...");
|
||||
@$choices = map { { key => $_, value => $hash{$_} } }
|
||||
sort keys %hash;
|
||||
{
|
||||
select => 1,
|
||||
key => $key,
|
||||
null => $null,
|
||||
value => $value ? $value : $key,
|
||||
choices => $choices
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
{
|
||||
select => 0,
|
||||
key => $key,
|
||||
value => $self->conf->{findUserSearchingAttributes}->{$_}
|
||||
? $self->conf->{findUserSearchingAttributes}->{$_}
|
||||
: $_
|
||||
};
|
||||
}
|
||||
} sort keys %{ $self->conf->{findUserSearchingAttributes} };
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -8,12 +8,24 @@
|
|||
<input type="hidden" name="token" value="<TMPL_VAR NAME="TOKEN">" />
|
||||
</TMPL_IF>
|
||||
<TMPL_LOOP NAME="FIELDS">
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><label for="<TMPL_VAR NAME="key">" class="mb-0"><i class="fa fa-user"></i></label></span>
|
||||
<TMPL_IF NAME="select">
|
||||
<label for="<TMPL_VAR NAME="key">"><TMPL_VAR NAME="value"></label>
|
||||
<select id="findUser_<TMPL_VAR NAME="key">" name="<TMPL_VAR NAME="key">">
|
||||
<TMPL_IF NAME="null">
|
||||
<option value=""></option>
|
||||
</TMPL_IF>
|
||||
<TMPL_LOOP NAME="choices">
|
||||
<option value="<TMPL_VAR NAME="key">"><TMPL_VAR NAME="value"></option>
|
||||
</TMPL_LOOP>
|
||||
</select>
|
||||
<TMPL_ELSE>
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><label for="<TMPL_VAR NAME="key">" class="mb-0"><i class="fa fa-user"></i></label></span>
|
||||
</div>
|
||||
<input id="findUser_<TMPL_VAR NAME="key">" name="<TMPL_VAR NAME="key">" type="text" autocomplete="off" class="form-control" placeholder="<TMPL_VAR NAME="value">" />
|
||||
</div>
|
||||
<input id="findUser_<TMPL_VAR NAME="key">" name="<TMPL_VAR NAME="key">" type="text" autocomplete="off" class="form-control" placeholder="<TMPL_VAR NAME="value">" />
|
||||
</div>
|
||||
</TMPL_IF>
|
||||
</TMPL_LOOP>
|
||||
<button type="submit" class="btn btn-info" >
|
||||
<span class="fa fa-eye"></span>
|
||||
|
|
|
@ -22,7 +22,7 @@ my $client = LLNG::Manager::Test->new( {
|
|||
findUserControl => '^[\w*\s]+$',
|
||||
findUserWildcard => '*',
|
||||
findUserSearchingAttributes =>
|
||||
{ uid => 'Login', guy => 'Kind', cn => 'Name' },
|
||||
{ uid => undef, guy => 'Kind', cn => 'Name' },
|
||||
findUserExcludingAttributes =>
|
||||
{ type => 'mutant', uid => 'rtyler' },
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ m%<input id="findUser_guy" name="guy" type="text" autocomplete="off" class="form
|
|||
) or explain( $res->[2]->[0], 'id="findUser_guy"' );
|
||||
ok(
|
||||
$res->[2]->[0] =~
|
||||
m%<input id="findUser_uid" name="uid" type="text" autocomplete="off" class="form-control" placeholder="Login" />%,
|
||||
m%<input id="findUser_uid" name="uid" type="text" autocomplete="off" class="form-control" placeholder="uid" />%,
|
||||
'id="findUser_uid"'
|
||||
) or explain( $res->[2]->[0], 'id="findUser_uid"' );
|
||||
ok(
|
||||
|
|
Loading…
Reference in New Issue
Block a user