Skip to content

Commit

Permalink
Choose the referenced source to check for sponsor
Browse files Browse the repository at this point in the history
  • Loading branch information
fdurand committed Jul 16, 2019
1 parent a7c9302 commit a52caba
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,13 @@ Validate the provided sponsor is allowed to do sponsoring
sub _validate_sponsor {
my ($self, $sponsor_email) = @_;
# Putting no context to that authentication request as no stripping has to be done here since its an email
my $value = pf::authentication::match( pf::authentication::getInternalAuthenticationSources(), { email => $sponsor_email, 'rule_class' => $Rules::ADMIN , 'context' => $pf::constants::realm::NO_CONTEXT}, $Actions::MARK_AS_SPONSOR );
my @sources;
foreach my $source (@{$self->source->sources}) {
push @sources, pf::authentication::getAuthenticationSource($source);
}
@sources = @{pf::authentication::getInternalAuthenticationSources()} if !(scalar @sources);

my $value = pf::authentication::match( \@sources, { email => $sponsor_email, 'rule_class' => $Rules::ADMIN , 'context' => $pf::constants::realm::NO_CONTEXT}, $Actions::MARK_AS_SPONSOR );

if (!defined $value) {
$self->app->flash->{error} = [ $GUEST::ERRORS{$GUEST::ERROR_SPONSOR_NOT_ALLOWED}, $sponsor_email ];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package pfappserver::Base::Form::Role::SourcesAssociated;

=head1 NAME
pfappserver::Base::Form::Role::SourcesAssociated
=cut

=head1 DESCRIPTION
pfappserver::Base::Form::Role::SourcesAssociated
=cut

use strict;
use warnings;
use namespace::autoclean;
use HTML::FormHandler::Moose::Role;
use pf::authentication;
with 'pfappserver::Base::Form::Role::Help';

has_field 'sources' => (
type => 'Select',
multiple => 1,
label => 'Associated Source',
options_method => \&options_sources,
element_class => ['chzn-deselect', 'input-xxlarge'],
element_attr => { 'data-placeholder' => 'Click to add a source' },
tags => {
after_element => \&help,
help => 'Sources that will be associated with this source (For the Sponsor)'
},
default => '',
);

has_block associated_sources => (
render_list => [qw(sources)],
);

=head2 options_sources
Returns the list of sources to be displayed
=cut

sub options_sources {
return map { { value => $_->id, label => $_->id, attributes => { 'data-source-class' => $_->class } } } grep { $_->{'type'} eq "AD" or $_->{'type'} eq "LDAP" or $_->{'type'} eq "SQL" } @{getInternalAuthenticationSources()};
}

=head1 AUTHOR
Inverse inc. <info@inverse.ca>
=head1 COPYRIGHT
Copyright (C) 2005-2019 Inverse inc.
=head1 LICENSE
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
=cut

1;
2 changes: 1 addition & 1 deletion html/pfappserver/lib/pfappserver/Form/Config/Source.pm
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ sub getSourceArgs {
}
}
}
for my $r (qw(realms searchattributes local_realm reject_realm)) {
for my $r (qw(realms searchattributes sources local_realm reject_realm)) {
$args->{$r} //= [];
if (ref($args->{$r}) ne "ARRAY" ) {
$args->{$r} = [$args->{$r}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ with qw(
pfappserver::Base::Form::Role::Help
pfappserver::Base::Form::Role::SourceLocalAccount
pfappserver::Base::Form::Role::EmailFiltering
pfappserver::Base::Form::Role::SourcesAssociated
);

use pfappserver::Form::Field::Duration;
use pf::Authentication::Source::SponsorEmailSource;
use pf::config qw(%Config %Doc_Config);
use pf::authentication;

# Form fields

Expand Down
1 change: 1 addition & 0 deletions lib/pf/Authentication/Source/SponsorEmailSource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ has 'sponsorship_bcc' => (isa => 'Maybe[Str]', is => 'rw');
has 'email_activation_timeout' => (isa => 'Str', is => 'rw', default => '30m');
has 'validate_sponsor' => (isa => 'Str', is => 'rw', default => 'yes');
has 'lang' => (isa => 'Maybe[Str]', is => 'rw', default => '');
has 'sources' => (isa => 'ArrayRef[Str]', is => 'rw');

=head2 dynamic_routing_module
Expand Down
1 change: 1 addition & 0 deletions lib/pf/ConfigStore/Source.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ our %TYPE_TO_EXPANDED_FIELDS = (
Eduroam => [qw(local_realm reject_realm)],
AD => [qw(searchattributes)],
LDAP => [qw(searchattributes)],
SponsorEmail => [qw(sources)],
);

sub _fields_expanded {
Expand Down
1 change: 1 addition & 0 deletions lib/pf/authentication.pm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ BEGIN {
getAllAuthenticationSources
deleteAuthenticationSource
getAuthenticationClassByType
getInternalAuthenticationSources
%guest_self_registration
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/pfconfig/namespaces/config/Authentication.pm
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ sub newAuthenticationSource {

sub cleanup_after_read {
my ( $self, $id, $data ) = @_;
$self->expand_list( $data, qw(realms local_realm reject_realm searchattributes) );
$self->expand_list( $data, qw(realms local_realm reject_realm searchattributes sources) );
}

=head1 AUTHOR
Expand Down

0 comments on commit a52caba

Please sign in to comment.