1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
48 %# REST/1.0/Forms/user/default
57 my ($c, $o, $k, $e) = ("", [], {}, 0);
59 my $user = new RT::User $session{CurrentUser};
60 my @fields = qw(RealName NickName Gecos Organization Address1 Address2 City
61 State Zip Country HomePhone WorkPhone MobilePhone PagerPhone
62 FreeformContactInfo Comments Signature Lang EmailEncoding
63 WebEncoding ExternalContactInfoId ContactInfoSystem
64 ExternalAuthId AuthSystem Privileged Disabled);
65 my %fields = map { lc $_ => $_ } @fields;
70 return [ "# User $id does not exist.", [], {}, 1 ];
74 if (keys %data == 0) {
76 "# Required: Name, EmailAddress",
77 [ qw(id Name EmailAddress Organization Password Comments) ],
92 $create{name} = "Name";
93 $create{password} = "Password";
94 $create{emailaddress} = "EmailAddress";
95 $create{contactinfo} = "FreeformContactInfo";
96 # Do any fields need to be excluded here?
98 foreach my $k (keys %data) {
99 if (exists $create{lc $k}) {
100 $v{$create{lc $k}} = delete $data{$k};
106 return [ "# Could not create user.", [], {}, 1 ];
111 push(@comments, "# User $id created.");
112 goto DONE if keys %data == 0;
116 if (keys %data == 0) {
119 push @data, [ id => "user/".$user->Id ];
120 push @data, [ Name => $user->Name ];
121 push @data, [ Password => '********' ];
122 push @data, [ EmailAddress => $user->EmailAddress ];
124 foreach my $key (@fields) {
125 my $val = $user->$key;
127 if ( (defined ($format) && $format eq 'l') || (defined $val && $val ne '')) {
128 $key = "ContactInfo" if $key eq 'FreeformContactInfo';
129 push @data, [ $key => $val ];
133 my %k = map {@$_} @data;
134 $o = [ map {$_->[0]} @data ];
138 my ($get, $set, $key, $val, $n, $s);
140 foreach $key (keys %data) {
145 if ($key eq 'name' || $key eq 'emailaddress' ||
146 $key eq 'contactinfo' || exists $fields{$key})
148 if (exists $fields{$key}) {
149 $key = $fields{$key};
152 $key = "FreeformContactInfo" if $key eq 'contactinfo';
153 $key = "EmailAddress" if $key eq 'emailaddress';
154 $key = "Name" if $key eq 'name';
158 next if $val eq $user->$key;
159 ($n, $s) = $user->$set($val);
161 elsif ($key eq 'password') {
162 ($n, $s) = $user->SetPassword($val) unless $val =~ /^\**$/;
164 elsif ($key ne 'id') {
166 $s = "Unknown field.";
172 push @comments, "# $key: $s";
174 my %o = keys %$changes;
175 delete @o{"id", @fields};
176 @$o = ("id", @fields, keys %o);
182 push(@comments, "# User $id updated.") unless $n == 0;
186 $c ||= join("\n", @comments) if @comments;
187 return [ $c, $o, $k, $e ];