Skip to content
Snippets Groups Projects
Commit 20049973 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

let ORM handle multi-valued attributes

parent 527f42e4
Branches
Tags
No related merge requests found
...@@ -12,7 +12,7 @@ __PACKAGE__->meta->setup( ...@@ -12,7 +12,7 @@ __PACKAGE__->meta->setup(
id => { type => 'bigserial', not_null => 1 }, id => { type => 'bigserial', not_null => 1 },
entityid => { type => 'varchar', length => 200, not_null => 1 }, entityid => { type => 'varchar', length => 200, not_null => 1 },
displayname => { type => 'varchar', length => 500 }, displayname => { type => 'varchar', length => 500 },
contacts => { type => 'varchar', length => 2000 }, contacts => { type => 'array' },
], ],
primary_key_columns => [ 'id' ], primary_key_columns => [ 'id' ],
...@@ -25,8 +25,6 @@ sub new { ...@@ -25,8 +25,6 @@ sub new {
my $self = $pkg->SUPER::new(%args); my $self = $pkg->SUPER::new(%args);
$self->{dev_sp_contact} = $args{dev_sp_contact};
return $self; return $self;
} }
...@@ -37,32 +35,17 @@ sub print { ...@@ -37,32 +35,17 @@ sub print {
printf $fd printf $fd
"ServiceProvider ID=%s; entityid=%s; displayname=%s; contacts=%s\n", "ServiceProvider ID=%s; entityid=%s; displayname=%s; contacts=%s\n",
$self->id(), $self->entityid(), $self->displayname(), $self->contacts(); $self->id(), $self->entityid(), $self->displayname(), join(',', $self->contacts());
}
## list contacts for this SP, including those listed in conf.dev_sp_contact
sub list_contacts_as_array {
my ($self) = @_;
my %contact_list;
foreach my $contact_email (split /,/, $self->contacts()) {
$contact_list{$contact_email}++;
}
foreach my $contact_email (split /,/, $self->{dev_sp_contact}) {
$contact_list{$contact_email}++;
}
return keys %contact_list;
} }
## Check if email address is a known contact (or conf.dev_sp_contact) ## Check if email address is a known contact (or conf.dev_sp_contact)
sub is_contact { sub is_contact {
my ($self, $email) = @_; my ($self, $email) = @_;
foreach my $known_contact ($self->list_contacts_as_array()) { $email = lc($email);
return 1 if (lc($email) eq lc($known_contact));
foreach my $contact ($self->contacts()) {
return 1 if $email eq lc($contact);
} }
return 0; return 0;
......
...@@ -277,9 +277,8 @@ sub req_select_sp { ...@@ -277,9 +277,8 @@ sub req_select_sp {
# complete persistent object # complete persistent object
$provider->displayname($sp->{display_name}); $provider->displayname($sp->{display_name});
$provider->contacts( $provider->contacts(map { $_->{EmailAddress} } @{$sp->{contacts}})
join(',', map { $_->{EmailAddress} } @{$sp->{contacts}}) if $sp->{contacts};
) if $sp->{contacts};
# save in DB # save in DB
unless ($provider->save()) { unless ($provider->save()) {
......
...@@ -11,7 +11,7 @@ Before you can create test accounts at this Identity Provider, we need to ensure ...@@ -11,7 +11,7 @@ Before you can create test accounts at this Identity Provider, we need to ensure
<div class="radio_inline"> <div class="radio_inline">
[% FOREACH email IN provider.list_contacts_as_array.sort %] [% FOREACH email IN provider.contacts.sort %]
<input name="email_address" value="[% email %]" type="radio" class="required"/><label for="email_address">[% email %]</label><br/> <input name="email_address" value="[% email %]" type="radio" class="required"/><label for="email_address">[% email %]</label><br/>
<input type="hidden" name="sp_entityid" value="[% provider.entityid %]" id="sp_entityid"/> <input type="hidden" name="sp_entityid" value="[% provider.entityid %]" id="sp_entityid"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment