App-Dochazka-REST
view release on metacpan or search on metacpan
lib/App/Dochazka/REST/ACL.pm view on Meta::CPAN
=cut
sub acl_check_is_me {
my $self = shift;
my %pl = @_;
$log->debug( "Entering " . __PACKAGE__ . "::acl_check_is_me with " . Dumper( \%pl ) );
my $ce = $self->context->{'current_obj'};
my $priv = $self->context->{'current_priv'};
return 1 if $priv eq 'admin';
if ( my $eid = $pl{'eid'} ) {
$log->debug( "acl_check_is_me: I am EID " . $ce->eid . " - checking against $eid" );
return ( defined($eid) and defined($ce->eid) and $eid == $ce->eid );
} elsif ( my $nick = $pl{'nick'} ) {
return ( defined($nick) and defined($ce->nick) and $nick eq $ce->nick );
} elsif ( my $sec_id = $pl{'sec_id'} ) {
return ( defined($sec_id) and defined($ce->sec_id) and $sec_id eq $ce->sec_id );
}
die "AAAAGAGAGAHHHHAHAHAAJJAJAJAJAAHAHAHA! " . Dumper( \%pl );
}
=head2 acl_check_is_my_report
Takes a property and a value. The property can be 'eid', 'nick', or 'sec_id'.
This routine first gets the employee object corresponding to the
eid/nick/sec_id and then checks if the current employee is that
employee's supervisor.
=cut
sub acl_check_is_my_report {
my $self = shift;
my %pl = @_;
$log->debug( "Entering " . __PACKAGE__ . "::acl_check_is_my_report with " . Dumper( \%pl ) );
my $ce = $self->context->{'current_obj'};
my $priv = $self->context->{'current_priv'};
my $emp = App::Dochazka::REST::Model::Employee->spawn;
my $conn = $self->context->{'dbix_conn'};
my $status;
return 1 if $priv eq 'admin';
if ( my $eid = $pl{'eid'} ) {
$log->debug( "acl_check_is_my_report: given EID $eid" );
$status = $emp->load_by_eid( $conn, $eid );
} elsif ( my $nick = $pl{'nick'} ) {
$log->debug( "acl_check_is_my_report: given nick $nick" );
$status = $emp->load_by_nick( $conn, $nick );
} elsif ( my $sec_id = $pl{'sec_id'} ) {
$log->debug( "acl_check_is_my_report: given sec_id $sec_id" );
$status = $emp->load_by_sec_id( $conn, $sec_id );
} else {
die "AAAGAAHHAHAHAAJJAJAJAHAHA! " . Dumper( \%pl );
}
if ( $status->not_ok ) {
$log->error( "acl_check_is_my_report: employee lookup failed (" . $status->text . ")" );
return 0;
}
$emp = $status->payload;
if ( defined($emp->supervisor) and defined($ce->eid) and $emp->supervisor eq $ce->eid ) {
$log->debug( "acl_check_is_my_report: I am the supervisor of ->" . $emp->nick . "<-" );
return 1;
}
return 0;
}
1;
( run in 0.514 second using v1.01-cache-2.11-cpan-d7f47b0818f )