2016-06-02 23:20:36 +02:00
|
|
|
package Lemonldap::NG::Common::Notifications;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2019-12-19 17:58:39 +01:00
|
|
|
use JSON qw(to_json);
|
2016-06-02 23:20:36 +02:00
|
|
|
|
2019-12-19 17:58:39 +01:00
|
|
|
our $VERSION = '2.0.7';
|
2016-06-02 23:20:36 +02:00
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Common::Module';
|
|
|
|
|
2017-01-31 20:11:59 +01:00
|
|
|
sub import {
|
|
|
|
if ( $_[1] eq 'XML' ) {
|
|
|
|
extends 'Lemonldap::NG::Common::Notifications::XML',
|
|
|
|
'Lemonldap::NG::Common::Module';
|
2016-06-02 23:20:36 +02:00
|
|
|
}
|
2017-01-31 20:11:59 +01: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 ) = @_;
|
2019-12-19 17:58:39 +01:00
|
|
|
my $forAll = $self->get( $self->conf->{notificationWildcard} );
|
2019-12-20 21:34:52 +01:00
|
|
|
if ( $uid and $uid =~ /^_all(Pending|Existing)_$/ ) {
|
|
|
|
$self->logger->info("Retrieve all $1 notifications");
|
|
|
|
my $all = ( $1 eq 'Pending' ? $self->getAll() : $self->getExisting() );
|
2019-12-19 17:58:39 +01:00
|
|
|
$all = { map { $_ => to_json( $all->{$_} ) } keys %$all };
|
2019-12-20 21:34:52 +01:00
|
|
|
return ( $forAll ? { %$all, %$forAll } : $all );
|
2019-12-19 17:58:39 +01:00
|
|
|
}
|
2016-06-02 23:20:36 +02:00
|
|
|
my $forUser = $self->get($uid);
|
|
|
|
if ( $forUser and $forAll ) {
|
|
|
|
return { %$forUser, %$forAll };
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ( ( $forUser ? $forUser : $forAll ), $forUser );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|