Re: limit queues by right ModifyTicket also for SuperUser

Shawn Moore <[email protected]> Tue, 19 May 2015 11:35:50 -0400
Newsgroups gmane.comp.bug-tracking.request-tracker.devel
Message-ID <[email protected]>
> 2015/05/19 8:17、Christian Loos <[email protected]> のメール:
> 
> Hi,

Hi Christian,

> our users have ShowQueue (together with ShowTicket) on many queues and
> ModifyTicket on few queues. This results in a long list of queues in the
> " Quick search" element.
> 
> To help our users to have a better overview of the queues they manage
> (where they have ModifyTicket), I wanted to create a MyQueues element
> which only list the queues where the users have the ModifyTicket right.

Just in case you missed it, a user can hide queues from that list by clicking the “edit” link next to the “Quick search” header. But I understand if that isn’t going to do it for you. :-)

> For normal users this is easy by using the
> /Elements/QueueSummaryByStatus with "sub {
> $_->CurrentUserHasRight('ModifyTicket') }" as queue_filter.
> 
> Sadly this doesn't work for SuperUser as they have ModifyTicket on all
> queues by the SuperUser right [1].
> 
> Is there any way to limit the queues also for SuperUser to ones that
> they have the ModifyTicket right?

The first place to check is the code that supports the admin UI for editing a user’s rights. Since SuperUser doesn’t automatically check every checkbox, there must be code that looks at the rights more closely than ->HasRight() to decide what to display. And sure enough there is:


share/html/Admin/Elements/EditRightsCategoryTabs:

# Find all the current rights for this principal
my %current_rights;
if ($Principal) {
    my $acls = RT::ACL->new($session{'CurrentUser'});
    $acls->LimitToObject( $Context );
    $acls->LimitToPrincipal( Id => $Principal->PrincipalId );

    while ( my $ace = $acls->Next ) {
        my $right = $ace->RightName;
        $current_rights{$right} = 1;
    }
}


This iterates over all the rights granted only to the specific principal, so it does not handle rights granted by group membership, either directly, or recursively. You can use the cached group members table (RT::CachedGroupMembers) to iterate over a user’s recursive group memberships to limit the RT::ACL search down. And of course you can limit the ACL you care about to just ModifyTicket instead of iterating over all of those.

It’s probably about twenty lines of code. I hope there aren’t too many corner cases… like what if the user has ModifyTicket only due to being an AdminCc? Also I’m not sure how slow it’ll be for your system: rights is one place RT does some careful caching. Please let us know how it goes!

> Chris


Cheers,
Shawn
signature.asc (application/pgp-signature, 801 B)
-----BEGIN PGP SIGNATURE-----

iQIcBAEBCAAGBQJVW1hbAAoJEDdW4lQxRAUg1NgQAJXhDPo3Bf0rWZGiVym4bSX8
LfXqLEkJB912A/wCN+ugWSYdA5t33pFVEYOPyhxjChLV5/X3UHXcpXpmaUmOMxvG
YF9Wjk8f6K6lL862hXIDxda/qa/cX5fnTJBHhLL+yYZ1NcWGFsM5MDqMvx8C4WxO
axfqjKLRysViWF+8Kw5N4e9+ztTGS6QXE+/ZySKkB+WHVMe62DGr3454oloJbTHY
5lIZhygK1CWzqbV4VSQZ3EBw1DBp4ruqAt/uYRoglQUnA5eHV3+QXnd1LhoZjr12
tr4H322MdJgmEpKv/wf/Zz3LIt1NbLJvj/GkDikD1EvtPrx1z++uqZ9dVlDwnqio
TQtFbMQ/ZimVyvJ6v4aKP6MDagGT7TgyBPKh2X55JPYbbBuylPYBF9fKwzEA58eU
ImB+m8B88KOKJy80bKJyFfP4CndkyozTOk45P3rEuz4iMInEiFd7fHaN7se7smfc
wDOOL1NdHzlVjdnpARzSR1bp09xx+X1xQf/83fAFyQm+pk4iebbPzP2i0fKvYzI7
fRBrC61OzdUfiHgT+R9vAPqx3qqKQk5uoTZSOnrKE2LnPgJNXt7GgyrjmNJGftQW
gNC1QTkjJJUEj09i/TE54DrDViNt7XJtIyZCgB2Mdqj27B1sySF1BUopHOTd3DR7
euHPiCP/infhxeNt7R3u
=7una
-----END PGP SIGNATURE-----