[rt-users] Help with TimeWorked Report

Kenneth Crocker kfcrocker at lbl.gov
Tue Mar 1 14:43:42 EST 2011


To list,

I have implemented the "TimeWorkedReport" in our environment and it works
well. However, I want to modify something that is a bit of a problem for us.
The delivered code allows for a "SuperUser" to see the time reported by any
other User. Our problem is that for our Group Managers to use this
functionality, they would have to be "SuperUSers". We have over 110 Queues
and our Group Managers (5 of them) just don't want to see such a HUGE list
of Queues in the dropdown lists of Queues. They just want to see their own.

My answer to the problem was to modify the code to see if the user is a
member of a group (called 'BS-Group Managers') instead of checking if they
have "SuperUser" rights. I was thinking this would keep my code
modifications to a minimum as the only code I would have to change would be
where the "SuperUser" right is checked.

My biggest problem is I am in *NO WAY* a perl programmer. I get by by
copying code and making small changes.

I've looked at other code in RT and found what *I thought* were good
examples of the kind of code I need. Obviously, I need to identify the Group
and the user. This is what I have so far:

# Get the Group Objects

my $GroupObj = new RT::Group($session{$RT::CurrentUser});
$GroupObj->LoadUserDefinedGroup('BS-Group Managers');
my $UserId = new RT::User($session{$RT::CurrentUser}); # part of second
option
#my $GrpMgr =
$GroupObj->UserMemberObj->PrincipalId($session{$RT::CurrentUser}); # first
option
my $GrpMgr = $GroupObj->UserMemberObj->PrincipalId($UserId);  # second
option

# Skip next code if user not in Mgr Group

# if this person is not a member of the mgrs group, we should only show them
the report for themselves
# which means we should remove all keys from %stats except their own
username

unless ($GrpMgr)
   {
    my %tempstats;
    $tempstats{$session{CurrentUser}->Name} =
$stats{$session{CurrentUser}->Name};
    %stats = %tempstats;
   }

Once I have the group identified, I tried to see if the *current user* is in
it, then I modified the "check for SuperUser right" to check for that
membership.

When I test using my first option "$session{$RT::CurrentUser}", I get this:

Can't locate object method "PrincipalId" via package "No object mapping for
field" (perhaps you forgot to load "No object mapping for field"?) at
/opt/rt3/local/html/Tools/Reports/TimeWorkedReport.html line 222, line 307.

When I test using my second option "$UserId", I get this:

Can't locate object method "PrincipalId" via package "No object mapping for
field" (perhaps you forgot to load "No object mapping for field"?) at
/opt/rt3/local/html/Tools/Reports/TimeWorkedReport.html line 224, line 307.

I know it looks like I'm bumbling around with these objects and I AM!  I've
asked my boss to send me to a perl class and he has OK'd that, but until
then, I just can't see why my code is wrong. I thought "PrincipalId" was
kinda built-in when looking at users.
*AND* I think I'm may be misunderstanding the code "new
RT::Group($session{$RT::CurrentUser})". I can't tell if it is the same as
this "RT::Group->new($RT::SystemUser);" (which I've used successfully in
other code) and I'm not sure if it actually gives an ID or is temporaryily
pointing to one.

So, If anyone can get me a little help so I can understand how to go about
doing this, I'd be *REALLY* grateful.

Thanks.

Kenn
LBNL
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20110301/f1fde763/attachment.htm>


More information about the rt-users mailing list