ModifyUserPreferences

From Request Tracker Wiki
Revision as of 09:13, 3 May 2011 by 193.62.202.241 (talk) (Changing a user's email frequency preference)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I had a situation where a once-privileged user had been made non-privileged, since they had left our institute, but they had email preference settings set to weekly batch.

Unfortunately, the GUI has no interface to change a user's preferences, other than having the user do it themselves. Fortunately, it wasn't too difficult to write a small perl script to delete a named user's email preference setting:

#!/usr/bin/perl -w

use strict;

use lib qw(/opt/rt3/lib /opt/rt3/local/lib);

use Getopt::Long;
use RT;
use RT::Interface::CLI qw/GetCurrentUser/;

RT::LoadConfig;
RT::Init;

my $name;

GetOptions("name=s" => \$name);

die "Usage: $0 --name=bloggs\n" unless ($name);

my $u = RT::User->new($RT::SystemUser);

my ($id, $err) = $u->LoadByCol('Name' => $name);
die("Couldn't load user '$name': $err\n") unless ($id > 0);

my $p = $u->Preferences( $RT::System );
delete($p->{'EmailFrequency'});
$u->SetPreferences( $RT::System, $p);