1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
6 %# <jesse@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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 %# CONTRIBUTION SUBMISSION POLICY:
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
45 %# END BPS TAGGED BLOCK }}}
46 %# REST/1.0/Forms/user/default
55 my ($c, $o, $k, $e) = ("", [], {}, 0);
57 my $user = new RT::User $session{CurrentUser};
58 my @fields = qw(RealName NickName Gecos Organization Address1 Address2 City
59 State Zip Country HomePhone WorkPhone MobilePhone PagerPhone
60 FreeformContactInfo Comments Signature Lang EmailEncoding
61 WebEncoding ExternalContactInfoId ContactInfoSystem
62 ExternalAuthId AuthSystem);
63 my %fields = map { lc $_ => $_ } @fields;
68 return [ "# User $id does not exist.", [], {}, 1 ];
74 "# Required: Name, EmailAddress",
75 [ qw(id Name EmailAddress Organization Password Comments) ],
90 $create{name} = "Name";
91 $create{password} = "Password";
92 $create{emailaddress} = "EmailAddress";
93 $create{contactinfo} = "FreeformContactInfo";
94 # Do any fields need to be excluded here?
96 foreach my $k (keys %data) {
97 if (exists $create{lc $k}) {
98 $v{$create{lc $k}} = delete $data{$k};
104 return [ "# Could not create user.", [], {}, 1 ];
109 push(@comments, "# User $id created.");
110 goto DONE if %data == 0;
117 push @data, [ id => "user/".$user->Id ];
118 push @data, [ Name => $user->Name ];
119 push @data, [ Password => '********' ];
120 push @data, [ EmailAddress => $user->EmailAddress ];
122 foreach my $key (@fields) {
123 my $val = $user->$key;
125 if ($format eq 'l' || (defined $val && $val ne '')) {
126 $key = "ContactInfo" if $key eq 'FreeformContactInfo';
127 push @data, [ $key => $val ];
131 my %k = map {@$_} @data;
132 $o = [ map {$_->[0]} @data ];
136 my ($get, $set, $key, $val, $n, $s);
138 foreach $key (keys %data) {
143 if ($key eq 'name' || $key eq 'emailaddress' ||
144 $key eq 'contactinfo' || exists $fields{$key})
146 if (exists $fields{$key}) {
147 $key = $fields{$key};
150 $key = "FreeformContactInfo" if $key eq 'contactinfo';
151 $key = "EmailAddress" if $key eq 'emailaddress';
152 $key = "Name" if $key eq 'name';
156 next if $val eq $user->$key;
157 ($n, $s) = $user->$set($val);
159 elsif ($key eq 'password') {
160 ($n, $s) = $user->SetPassword($val) unless $val =~ /^\**$/;
162 elsif ($key ne 'id') {
164 $s = "Unknown field.";
170 push @comments, "# $key: $s";
172 my %o = keys %$changes;
173 delete @o{"id", @fields};
174 @$o = ("id", @fields, keys %o);
180 push(@comments, "# User $id updated.") unless $n == 0;
184 $c ||= join("\n", @comments) if @comments;
185 return [ $c, $o, $k, $e ];