|
|
|
@ -5,6 +5,7 @@ use utf8; |
|
|
|
|
use Mouse; |
|
|
|
|
use JSON qw(from_json to_json); |
|
|
|
|
use POSIX qw(strftime); |
|
|
|
|
use MIME::Base64 qw(decode_base64); |
|
|
|
|
|
|
|
|
|
use Lemonldap::NG::Common::Conf::Constants; |
|
|
|
|
use Lemonldap::NG::Common::PSGI::Constants; |
|
|
|
@ -243,40 +244,56 @@ sub notifications { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub notification { |
|
|
|
|
my ( $self, $req, $id, $type, $uid, $ref ) = @_; |
|
|
|
|
my ( $self, $req, $id, $type ) = @_; |
|
|
|
|
my $backend = $self->{notificationStorage}; |
|
|
|
|
$self->logger->debug("Notification storage: $backend"); |
|
|
|
|
|
|
|
|
|
if ( $type eq 'actives' ) { |
|
|
|
|
( $uid, $ref ) = ( $id =~ /([^_]+?)_(.+)/ ); |
|
|
|
|
my ( $uid, $ref ) = ( $id =~ /([^_]+?)_(.+)/ ); |
|
|
|
|
my $n = $self->notifAccess->get( $uid, $ref ); |
|
|
|
|
unless ($n) { |
|
|
|
|
$self->userLogger->notice( |
|
|
|
|
"Notification $ref not found for user $uid"); |
|
|
|
|
"Active notification $ref not found for user $uid"); |
|
|
|
|
return $self->sendJSONresponse( |
|
|
|
|
$req, |
|
|
|
|
{ |
|
|
|
|
result => 0, |
|
|
|
|
error => "Notification $ref not found for user $uid" |
|
|
|
|
error => "Active otification $ref not found for user $uid" |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
$self->logger->debug("Active notification $ref found for user $uid"); |
|
|
|
|
return $self->sendJSONresponse( $req, |
|
|
|
|
{ result => 1, count => 1, notifications => [ values %$n ] } ); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
my ( $date, $uid, $ref ) = |
|
|
|
|
$backend eq 'File' |
|
|
|
|
? ( $id =~ /([^_]+?)_(.+?)_(.+?)\.done/ ) |
|
|
|
|
: ( $id =~ /([^_]+?)_(.+?)_(.+)/ ); |
|
|
|
|
$ref = decode_base64($ref) if ( $backend eq 'File' ); |
|
|
|
|
my $n = $self->notifAccess->getAccepted( $uid, $ref ); |
|
|
|
|
unless ($n) { |
|
|
|
|
$self->userLogger->notice( |
|
|
|
|
"Notification $ref not found for user $uid"); |
|
|
|
|
"Done notification $ref not found for user $uid"); |
|
|
|
|
return $self->sendJSONresponse( |
|
|
|
|
$req, |
|
|
|
|
{ |
|
|
|
|
result => 0, |
|
|
|
|
error => "Notification $ref not found for user $uid" |
|
|
|
|
error => "Done notification $ref not found for user $uid" |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
return $self->sendJSONresponse( $req, |
|
|
|
|
{ result => 1, count => 1, done => $id, notifications => [ values %$n ] } ); |
|
|
|
|
$self->logger->debug("Done notification $ref found for user $uid"); |
|
|
|
|
return $self->sendJSONresponse( |
|
|
|
|
$req, |
|
|
|
|
{ |
|
|
|
|
result => 1, |
|
|
|
|
count => 1, |
|
|
|
|
done => $id, |
|
|
|
|
notifications => [ values %$n ] |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|