lemonldap-ng/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications.pm

46 lines
980 B
Perl
Raw Normal View History

2016-06-02 23:20:36 +02:00
package Lemonldap::NG::Common::Notifications;
use strict;
use Mouse;
2019-02-12 18:21:38 +01:00
our $VERSION = '2.1.0';
2016-06-02 23:20:36 +02:00
extends 'Lemonldap::NG::Common::Module';
sub import {
if ( $_[1] eq 'XML' ) {
extends 'Lemonldap::NG::Common::Notifications::XML',
'Lemonldap::NG::Common::Module';
2016-06-02 23:20:36 +02:00
}
else {
extends 'Lemonldap::NG::Common::Notifications::JSON',
'Lemonldap::NG::Common::Module';
}
}
2016-06-02 23:20:36 +02:00
has notifField => (
is => 'rw',
builder => sub {
my $uid =
$_[0]->conf->{notificationField}
|| $_[0]->conf->{whatToTrace}
|| 'uid';
$uid =~ s/^\$//;
return $uid;
}
);
sub getNotifications {
my ( $self, $uid ) = @_;
my $forUser = $self->get($uid);
2016-12-26 10:23:35 +01:00
my $forAll = $self->get( $self->conf->{notificationWildcard} );
2016-06-02 23:20:36 +02:00
if ( $forUser and $forAll ) {
return { %$forUser, %$forAll };
}
else {
return ( ( $forUser ? $forUser : $forAll ), $forUser );
}
}
1;