<& /Elements/ListActions, actions => \@results &>

<& /Admin/Tools/RightsMatrix/Elements/ObjectRightsMatrix, ObjectType => 'RT::Queue', PrincipalObj => $principal, %ARGS  &>

<%INIT>
my @results;
my $principal;

if ( $ARGS{WhereFrom} ) {
        $m->comp("../WhereRightComesFrom.html", %ARGS);
        $m->abort;
}

if ( $ARGS{Principal} and $ARGS{User} ) {
        $m->comp("/Elements/Error", Why => loc("You can't select a user and enter one manually."));
        $m->abort;
}

if ($ARGS{Principal} =~ /^\d+$/) {
    $principal = RT::Principal->new($session{CurrentUser});
    my ($rv, $msg) = $principal->Load($ARGS{Principal});
    if (! $rv) {
        $m->comp("/Elements/Error", Why => loc("Principal not found"));
        $m->abort;
    }
}
elsif ($ARGS{Principal} =~ /^(.*)-Role$/) {
    $principal = RTx::RightsMatrix::RolePrincipal->new($1);
}
elsif ($ARGS{User}) {
    my $user = RT::User->new($session{CurrentUser});
    my ($rv, $msg) = $user->Load($ARGS{User});
    if (! $rv) {
        $m->comp("/Elements/Error", Why => loc("User [_1] not found: [_2]", $ARGS{User}, $msg));
        $m->abort;
    }
    $principal = $user->PrincipalObj;
}
else {
    $principal = $session{CurrentUser}->PrincipalObj;
}

</%INIT>
<%ARGS>
$User => undef
$Edit => 0
</%ARGS>
<%ONCE>
use RTx::RightsMatrix;
use RTx::RightsMatrix::RolePrincipal;

</%ONCE>
