<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>Auto adding users to privileged groups</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">Interestingly, my original email hadn't shown up on the list yet… but I made the script work myself. I was missing a few steps.</FONT></P>
<P><FONT SIZE=2 FACE="Arial">I have an email alias pointing to the 'accounts' queue. I gave unpriv users the ability the create tickets in the accounts queue. On Create, I have two scripts. One for $self->TicketObj->SetStatus('resolved'); and the other: </FONT></P>
<P><FONT SIZE=2 FACE="Arial">my $domains = {};</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">my %domain_map = (</FONT>
<BR><FONT SIZE=2 FACE="Arial"> '\@.*\.?cust1\.com' => "cust1",</FONT>
<BR><FONT SIZE=2 FACE="Arial"> '\@.*\.?cust2\.com' => "cust2",</FONT>
<BR><FONT SIZE=2 FACE="Arial"> '\@.*\.?cust3\.com' => "cust3",</FONT>
<BR><FONT SIZE=2 FACE="Arial"> );</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">foreach my $domainKey (keys %domain_map ){</FONT>
<BR><FONT SIZE=2 FACE="Arial">if($self->TicketObj->RequestorAddresses =~ /^.*?${domainKey}/) {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial">my $user = RT::User->new( $RT::SystemUser );</FONT>
<BR><FONT SIZE=2 FACE="Arial">$user->LoadByEmail($self->TicketObj->RequestorAddresses);</FONT>
<BR><FONT SIZE=2 FACE="Arial">die "couldn't load user" unless $user->id;</FONT>
<BR><FONT SIZE=2 FACE="Arial">my $group = RT::Group->new( $RT::SystemUser );</FONT>
<BR><FONT SIZE=2 FACE="Arial"> $group->LoadUserDefinedGroup( $domain_map{$domainKey} );</FONT>
<BR><FONT SIZE=2 FACE="Arial"> $group->AddMember($user->id);</FONT>
<BR><FONT SIZE=2 FACE="Arial"> }</FONT>
<BR><FONT SIZE=2 FACE="Arial">}</FONT>
</P>
<BR>
<P><FONT SIZE=2 FACE="Arial">Whoever wrote the code snippets page on the wiki is officially my hero. </FONT>
</P>
</BODY>
</HTML>