[rt-users] Users groups modification
Janne Pirkkanen
jp at oppipoika.net
Mon Aug 12 04:08:02 EDT 2002
Hi there.
This message may show here also second time because I sent it first with wrong sender
address. Sorry.
This is my first post to this list but I have read it's archives. We have RT 2.13 in test
box and it looks wonderfull. I've used many contrib -files to make little modifications
to RT:s ui. So I thought that I send this little mod here, if someone finds it usefull
(and makes it better). My perl is awfull and RT experience is only two months so please
look this code carefully through before using it for real :)
So. We are using RT with quite a many different user groups and managing users groups (I
like to think user groups as user profiles) felt difficult. So I made mod based on
Admin/Groups/Members.html (to be Admin/Users/Groups.html). This makes it possible to go
to some users page and see which groups he/she belongs in. And also add/remove user
to/from groups.
Here are the files. Just drop Groups.html and SelectGroups to there folders and modify
UserTabs -file so that you have link to that Admin/Users/Groups.html -file. As always,
take backups from your old files before these modifications.
********************* File: Admin/Users/Groups.html starts **********************
%# File created 2002-08-07 J. Pirkkanen <jp at oppipoika.net>. Based on RT 2.0.13 file
Admin/Groups/Members.html
<& /Admin/Elements/Header, Title => 'RT/Admin/Edit the user '. $User->Name &>
<& /Admin/Elements/UserTabs, id => $id &>
<& /Elements/ListActions, actions => \@results &>
<& /Elements/TitleBoxStart, title => "Editing group memberships for user " . $User-
>Name . " (" . $User->RealName . ")" &>
<FORM ACTION="<%$RT::WebPath%>/Admin/Users/Groups.html" METHOD=POST>
<INPUT TYPE=HIDDEN NAME=id VALUE="<%$User->id%>">
<TABLE WIDTH="100%">
<TR>
<TD>
Add groups</TD>
<TD>
Current groups
</TD>
</TR>
<TR>
<TD VALIGN=TOP>
<& /Admin/Elements/SelectGroups, Name => "AddGroups" &>
</TD>
<TD VALIGN=TOP>
<%PERL>
my $GroupList = "(Check box to remove user from group)\n<UL>\n";
my $ShowList = 0;
while ($Group = $Groups->Next()) {
while ($GrpMember = $Group->MembersObj->Next()) {
my $JumpToNext = 0;
if ($GrpMember->UserObj->id == $id) {
$GroupList .= "<LI><INPUT TYPE=CHECKBOX Name='DeleteMember-
" . $Group->Id . "'>\n";
$GroupList .= "<a href='/Admin/Groups/Modify.html?id=" .
$Group->Id . "'>" . $Group->Name . "</a> (" . $Group->Description . ")\n";
$JumpToNext = 1;
$ShowList = 1;
next;
}
next if $JumpToNext;
}
}
$GroupList .= "</UL>\n";
</%PERL>
% if ($ShowList) {
<% $GroupList | n %>
% } else {
<i>(User doesn't belong to any groups)</i>
% }
</TD>
</TR>
</TABLE>
<& /Elements/TitleBoxEnd &>
<& /Elements/Submit &>
</form>
<%ARGS>
$AddGroups => undef
$id => undef
</%ARGS>
<%INIT>
my $User = new RT::User($session{'CurrentUser'});
if (!($User->CurrentUserHasRight('AdminGroups'))) {
Abort('No permission to execute command.');
}
$User->Load($id);
my $Groups = new RT::Groups($session{'CurrentUser'});
$Groups->LimitToReal();
my $Group = new RT::Group($session{'CurrentUser'});
my $GrpMember = new RT::GroupMember($session{'CurrentUser'});
my (@results);
my $key;
foreach $key (keys %ARGS) {
if ($key =~ /^DeleteMember-(\d+)$/) {
my $grpid = $1;
$Group->Load($grpid) || Abort('Could not load group');
my ($val,$msg) = $Group->DeleteMember($id);
push (@results, $msg);
}
}
# Make sure AddGroups is always an array
my @AddGroups = (ref $AddGroups eq 'ARRAY') ? @{$AddGroups} : ($AddGroups);
foreach my $GroupMember (@AddGroups) {
next unless ($GroupMember);
$Group->Load($GroupMember) || Abort('Could not load group');
my ($val, $msg) = $Group->AddMember($id);
push (@results, $msg);
}
</%INIT>
********************* File: Admin/Users/Groups.html ends **********************
********************* File: Admin/Elements/SelectGroups starts ****************
%# 2002-08-07 JP: Created - based on RT 2.0.13 file Admin/Elements/SelectUsers
<SELECT MULTIPLE NAME="<%$Name%>" SIZE=10>
%while (my $Group = $Groups->Next) {
<OPTION VALUE="<%$Group->Id%>"><%$Group->Name%>
%}
</SELECT>
<%INIT>
my $Groups = new RT::Groups($session{'CurrentUser'});
$Groups->LimitToReal();
</%INIT>
<%ARGS>
$Name => 'Groups'
</%ARGS>
********************* File: Admin/Elements/SelectGroups ends ******************
And you have to modify your Admin/Elements/UserTabs -file to look somethin like this:
********************* File: Admin/Elements/UserTabs starts ********************
<& /Admin/Elements/Tabs, subtabs => $subtabs,
current_tab => 'Admin/Users/',
current_subtab => $current_subtab &>
<hr>
<%INIT>
my $subtabs = {
Queues => { title => 'Basics',
path => "Admin/Users/Modify.html?id=".$id
},
# Scrips => { title => 'Rights',
# path => "Admin/Users/Rights.html?id=".$id
# }
XGroups => { title => 'Groups',
path => "Admin/Users/Groups.html?id=".$id
}
};
</%INIT>
<%ARGS>
$id => undef
$current_subtab => undef
</%ARGS>
********************* File: Admin/Elements/UserTabs starts ********************
I'm keen to hear if there is something wrong in these files so I can learn more about RT
and Perl.
I also have made versions of Admin/Users/Rights.html and Admin/Groups/Rights.html. If
someone is interested on those, drop me a line.
- Janne
email: jp at oppipoika.net
tel: +358-40-5044622
fax: +358-3-2533830
More information about the rt-users
mailing list