1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2016 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
58 my ($c, $o, $k, $e) = ("", [], {}, 0);
60 my $user = RT::User->new($session{CurrentUser});
63 qw(Name EmailAddress RealName NickName Gecos Organization Address1
64 Address2 City State Zip Country HomePhone WorkPhone MobilePhone PagerPhone
65 FreeformContactInfo Comments Signature Lang EmailEncoding
66 WebEncoding ExternalContactInfoId ContactInfoSystem
67 ExternalAuthId AuthSystem Privileged Disabled);
69 if ( $fields && %$fields ) {
70 @fields = grep { exists $fields->{ lc $_ } } @fields;
73 my %fields = map { lc $_ => $_ } @fields;
78 return [ "# User $id does not exist.", [], {}, 1 ];
82 if (keys %data == 0) {
84 "# Required: Name, EmailAddress",
85 [ qw(id Name EmailAddress Organization Password Comments) ],
100 $create{name} = "Name";
101 $create{password} = "Password";
102 $create{emailaddress} = "EmailAddress";
103 $create{contactinfo} = "FreeformContactInfo";
104 # Do any fields need to be excluded here?
106 foreach my $k (keys %data) {
107 if (exists $create{lc $k}) {
108 $v{$create{lc $k}} = delete $data{$k};
114 return [ "# Could not create user.", [], {}, 1 ];
119 push(@comments, "# User $id created.");
120 goto DONE if keys %data == 0;
124 if (keys %data == 0) {
127 push @data, [ id => "user/".$user->Id ];
129 unless ( $fields && %$fields && !exists $fields->{'password'} ) {
130 push @data, [ Password => '********' ];
133 for my $key (@fields) {
134 my $val = $user->$key;
135 if ( ( $fields && exists $fields->{ lc $key } )
136 || ( defined $format && $format eq 'l' )
137 || ( defined $val && $val ne '' ) )
139 $key = "ContactInfo" if $key eq 'FreeformContactInfo';
140 push @data, [ $key => $val ];
145 my $CustomFields = $user->CustomFields;
146 while ( my $CustomField = $CustomFields->Next() ) {
147 # show cf unless there are specified fields that don't include it
150 || exists $fields->{ lc "CF-" . $CustomField->Name } );
151 next unless $CustomField->CurrentUserHasRight('SeeCustomField');
152 my $CFvalues = $user->CustomFieldValues( $CustomField->Id );
154 while ( my $CFvalue = $CFvalues->Next() ) {
155 push @CFvalues, $CFvalue->Content;
157 push @data, [ "CF-" . $CustomField->Name => \@CFvalues ];
160 my %k = map {@$_} @data;
161 $o = [ map {$_->[0]} @data ];
165 my ($get, $set, $key, $val, $n, $s);
167 foreach $key (keys %data) {
172 if ($key eq 'name' || $key eq 'emailaddress' ||
173 $key eq 'contactinfo' || exists $fields{$key})
175 if (exists $fields{$key}) {
176 $key = $fields{$key};
179 $key = "FreeformContactInfo" if $key eq 'contactinfo';
180 $key = "EmailAddress" if $key eq 'emailaddress';
181 $key = "Name" if $key eq 'name';
185 next if $val eq $user->$key;
186 ($n, $s) = $user->$set($val);
188 elsif ($key eq 'password') {
189 ($n, $s) = $user->SetPassword($val) unless $val =~ /^\**$/;
191 elsif ($key ne 'id') {
193 $s = "Unknown field.";
199 push @comments, "# $key: $s";
201 my %o = keys %$changes;
202 delete @o{"id", @fields};
203 @$o = ("id", @fields, keys %o);
212 push(@comments, "# User $id updated.") if $updated;
216 $c ||= join("\n", @comments) if @comments;
217 return [ $c, $o, $k, $e ];