Show a new ticket tab for a special user group only

Hi list,

I’m stuck. I tried for hours now to extend the tabs of a ticket. This
worked so far with copying /opt/rt3/share/html/Ticket/Modify.html to
local, rename it to RMB.html (my new site including some CFs wich should
be visible for the special user group “Members RMB” and project managers
only). This worked fine.

But now I wanted only members of group “Members RMB” to see this new tab
at the tickets. So I added some lines to
/opt/rt3/local/html/Ticket/Elements/Tabs which look like that:

my $ticket_page_tabs = {
_Aa =>{ title => loc(‘Display’),
path => “Ticket/Display.html?id=” . $id, },
_Ab =>{ title => loc(‘History’),
path => “Ticket/History.html?id=” . $id, },
_B => { title => loc(‘Basics’),
path => “Ticket/Modify.html?id=” . $id, },
_C => { title => loc(‘Dates’),
path => “Ticket/ModifyDates.html?id=” . $id, },
_D => { title => loc(‘People’),
path => “Ticket/ModifyPeople.html?id=” . $id, },
_E => { title => loc(‘Links’),
path => “Ticket/ModifyLinks.html?id=” . $id, },
_F => { title => loc(‘Reminders’),
path => “Ticket/Reminders.html?id=” . $id,
separator => 1, },
_X => { title => loc(‘Jumbo’),
path => “Ticket/ModifyAll.html?id=” . $id, },
};

$RT::Logger->info("User: ", $session{‘CurrentUser’}->Name);
my $groups = $session{‘CurrentUser’}->UserObj->OwnGroups;
$RT::Logger->info("Count: ", $groups->Count);
while (my $group = $groups->Next){
$RT::Logger->info("test: ", $group->Name);
if ( $group->Name =~ /Members RMB/ ){
$RT::Logger->info("found: ", $group->Name);
$ticket_page_tabs->{_Ca} = { title => loc(‘RMB’),
path => “Ticket/RMB.html?id=” . $id,
};
}
}

As you can see I used a lot of logging already but I couldn’t find the
answer to my problem which is the following: The tab “RMB” will only be
shown if the user is member of the group “Members Admin” which have the
right superuser (of course). How can this happen?

Here are some short snippets from my logfile (please compare with the
code above):
This was a working version with user weser as member of group “Members
Admin”:
[Thu May 22 16:04:34 2008] [info]: Successful login for weser from
xxx.xxx.xxx.xxx (/opt/rt3/local/html/autohandler:258)
[Thu May 22 16:04:37 2008] [info]: User: weser
(/opt/rt3/local/html/Ticket/Elements/Tabs:133)
[Thu May 22 16:04:37 2008] [info]: Count: 4
(/opt/rt3/local/html/Ticket/Elements/Tabs:135)
[Thu May 22 16:04:37 2008] [info]: test: AllUsers
(/opt/rt3/local/html/Ticket/Elements/Tabs:137)
[Thu May 22 16:04:37 2008] [info]: test: Members Developer
(/opt/rt3/local/html/Ticket/Elements/Tabs:137)
[Thu May 22 16:04:38 2008] [info]: test: Members Admin
(/opt/rt3/local/html/Ticket/Elements/Tabs:137)
[Thu May 22 16:04:38 2008] [info]: test: Members RMB
(/opt/rt3/local/html/Ticket/Elements/Tabs:137)
[Thu May 22 16:04:38 2008] [info]: found: Members RMB
(/opt/rt3/local/html/Ticket/Elements/Tabs:139)

This happens if I delete user weser from group “Members Admin”:
[Thu May 22 16:06:53 2008] [info]: Successful login for weser from
xxx.xxx.xxx.xxx (/opt/rt3/local/html/autohandler:258)
[Thu May 22 16:06:56 2008] [info]: User: weser
(/opt/rt3/local/html/Ticket/Elements/Tabs:133)
[Thu May 22 16:06:56 2008] [info]: Count: 3
(/opt/rt3/local/html/Ticket/Elements/Tabs:135)

It will not go into the while-loop. Can anybody please explain me why?
Or does anyone has at least some suggestions where else I could have a
look? Or a work around? Anything?

Thanks a lot in advance.
Ben

I’ve recently discovered that for Attachments, the ‘Next’ method will
retrieve the SECOND attachment the first time it’s called, as in the
following:

$self->TransactionObj->Attachments->Next

Maybe the same for your groups?

I was going to ask the list…

  1. …if there’s a better way to cycle through them (without skipping the
    first one) than my current way, which is to get the ->First at the beginning
    of the loop and re-instantiate to ->Next at the end.

  2. …where I can find documentation on ->First, ->Next, TransactionObj,
    TicketObj, etc. etc. and all methods for all objects. (I have been basing
    all my scrips on examples ‘scrounged’ from the list and from bestpractical).

The information contained in this email is strictly confidential and subject
to the Confidentiality Notice at www.mcfina.com/emailpolicy-----Original Message-----
From: rt-users-bounces@lists.bestpractical.com
[mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Benjamin
Weser
Sent: Thursday, May 22, 2008 12:39 PM
To: rt-users
Subject: [rt-users] show a new ticket tab for a special user group only

Hi list,

I’m stuck. I tried for hours now to extend the tabs of a ticket. This
worked so far with copying /opt/rt3/share/html/Ticket/Modify.html to
local, rename it to RMB.html (my new site including some CFs wich should
be visible for the special user group “Members RMB” and project managers
only). This worked fine.

But now I wanted only members of group “Members RMB” to see this new tab
at the tickets. So I added some lines to
/opt/rt3/local/html/Ticket/Elements/Tabs which look like that:

my $ticket_page_tabs = {
_Aa =>{ title => loc(‘Display’),
path => “Ticket/Display.html?id=” . $id, },
_Ab =>{ title => loc(‘History’),
path => “Ticket/History.html?id=” . $id, },
_B => { title => loc(‘Basics’),
path => “Ticket/Modify.html?id=” . $id, },
_C => { title => loc(‘Dates’),
path => “Ticket/ModifyDates.html?id=” . $id, },
_D => { title => loc(‘People’),
path => “Ticket/ModifyPeople.html?id=” . $id, },
_E => { title => loc(‘Links’),
path => “Ticket/ModifyLinks.html?id=” . $id, },
_F => { title => loc(‘Reminders’),
path => “Ticket/Reminders.html?id=” . $id,
separator => 1, },
_X => { title => loc(‘Jumbo’),
path => “Ticket/ModifyAll.html?id=” . $id, },
};

$RT::Logger->info("User: ", $session{‘CurrentUser’}->Name);
my $groups = $session{‘CurrentUser’}->UserObj->OwnGroups;
$RT::Logger->info("Count: ", $groups->Count);
while (my $group = $groups->Next){
$RT::Logger->info("test: ", $group->Name);
if ( $group->Name =~ /Members RMB/ ){
$RT::Logger->info("found: ", $group->Name);
$ticket_page_tabs->{_Ca} = { title => loc(‘RMB’),
path => “Ticket/RMB.html?id=” . $id,
};
}
}

As you can see I used a lot of logging already but I couldn’t find the
answer to my problem which is the following: The tab “RMB” will only be
shown if the user is member of the group “Members Admin” which have the
right superuser (of course). How can this happen?

Here are some short snippets from my logfile (please compare with the
code above):
This was a working version with user weser as member of group “Members
Admin”:
[Thu May 22 16:04:34 2008] [info]: Successful login for weser from
xxx.xxx.xxx.xxx (/opt/rt3/local/html/autohandler:258)
[Thu May 22 16:04:37 2008] [info]: User: weser
(/opt/rt3/local/html/Ticket/Elements/Tabs:133)
[Thu May 22 16:04:37 2008] [info]: Count: 4
(/opt/rt3/local/html/Ticket/Elements/Tabs:135)
[Thu May 22 16:04:37 2008] [info]: test: AllUsers
(/opt/rt3/local/html/Ticket/Elements/Tabs:137)
[Thu May 22 16:04:37 2008] [info]: test: Members Developer
(/opt/rt3/local/html/Ticket/Elements/Tabs:137)
[Thu May 22 16:04:38 2008] [info]: test: Members Admin
(/opt/rt3/local/html/Ticket/Elements/Tabs:137)
[Thu May 22 16:04:38 2008] [info]: test: Members RMB
(/opt/rt3/local/html/Ticket/Elements/Tabs:137)
[Thu May 22 16:04:38 2008] [info]: found: Members RMB
(/opt/rt3/local/html/Ticket/Elements/Tabs:139)

This happens if I delete user weser from group “Members Admin”:
[Thu May 22 16:06:53 2008] [info]: Successful login for weser from
xxx.xxx.xxx.xxx (/opt/rt3/local/html/autohandler:258)
[Thu May 22 16:06:56 2008] [info]: User: weser
(/opt/rt3/local/html/Ticket/Elements/Tabs:133)
[Thu May 22 16:06:56 2008] [info]: Count: 3
(/opt/rt3/local/html/Ticket/Elements/Tabs:135)

It will not go into the while-loop. Can anybody please explain me why?
Or does anyone has at least some suggestions where else I could have a
look? Or a work around? Anything?

Thanks a lot in advance.
Ben

http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Hello Ben,–Am 22. Mai 2008 18:39:12 +0200 schrieb Benjamin Weser weser@osp-dd.de:

$RT::Logger->info("User: ", $session{‘CurrentUser’}->Name);
my $groups = $session{‘CurrentUser’}->UserObj->OwnGroups;
$RT::Logger->info("Count: ", $groups->Count);
while (my $group = $groups->Next){
$RT::Logger->info("test: ", $group->Name);
if ( $group->Name =~ /Members RMB/ ){
$RT::Logger->info("found: ", $group->Name);
$ticket_page_tabs->{_Ca} = { title => loc(‘RMB’),
path => “Ticket/RMB.html?id=” . $id,
};
}
}

I don’t know why your code does not work, but I would do it other way
round: load the group and look if currentuser is a member.

Without guarantee:

my $group = new RT::Group($session{‘CurrentUser’});
$group->LoadUserDefinedGroup(‘Members RMB’);
if ($group->HasMemberRecursively($session{‘CurrentUser’})) {
$ticket_page_tabs->{_Ca} = { title => loc(‘RMB’),
path => “Ticket/RMB.html?id=” . $id,
};
}

Dirk.
Dr. Dirk Pape (eAS - Projektleitung Campus Management)
Freie Universitaet Berlin
Grunewaldstr. 34a, 12165 Berlin
Tel. +49 (30) 838 75143, Fax. +49 (30) 838 54654

Hi Dirk,

thank you, your code works. Almost. :wink:
I had to mix it up a little bit with what I’ve found at the wiki
(TestGroupMembership - Request Tracker Wiki) since
HasMemberRecursively() expects a Principal as parameter.

For everybody with similar problems: here you can see my working code now:

my $group = new RT::Group($session{‘CurrentUser’});
$group->LoadUserDefinedGroup(‘Members RMB’);

my $principal = new RT::Principal($session{‘CurrentUser’});
$principal->Load($session{‘CurrentUser’}->Id);

if ($group->HasMemberRecursively($principal)) {
$RT::Logger->info("found: ", $group->Name);
$ticket_page_tabs->{_Ca} = { title => loc(‘RMB’),
path => “Ticket/RMB.html?id=” . $id,
};
}

Ben

Dirk Pape schrieb: