Skip to content
Snippets Groups Projects
Entity.pm 1.31 KiB
package AccountManager::Entity;

use strict;
use warnings;

use base 'AccountManager::DB::Object';

use List::MoreUtils qw(any);
use Rose::DB::Object::Manager;

__PACKAGE__->meta->setup(
    table   => 'entities',

    columns => [
        id               => { type => 'bigserial', not_null => 1 },
        entityid         => { type => 'varchar', length => 200, not_null => 1 },
        type             => { type => 'varchar', length => 3 },
        display_name     => { type => 'varchar', length => 500 },
        information_url  => { type => 'varchar', length => 200 },
        organization_url => { type => 'varchar', length => 200 },
        contacts         => { type => 'array' },
        federations      => { type => 'array' },
    ],

    primary_key_columns => [ 'id' ],

    unique_key => [ 'entityid' ],
);

Rose::DB::Object::Manager->make_manager_methods('entities');

sub print {
    my ($self, $fd) = @_;
    $fd = \*STDOUT unless $fd;

    printf $fd
        "Entity ID=%s; entityid=%s; displayname=%s; contacts=%s\n",
        $self->id(),
        $self->entityid(),
        $self->display_name() || '',
        join(',', $self->contacts());
}

## Check if email address is a known contact
sub is_contact {
    my ($self, $email) = @_;

    $email = lc($email);

    return any { $email eq lc($_) } $self->contacts();
}

1;