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/group/default
53 $fields => undef # these are the fields passed to the rt "-f" flag.
58 my ($c, $o, $k, $e) = ("", [], {}, 0);
60 my $group = RT::Group->new($session{CurrentUser});
62 my @fields = qw(Name Description Disabled);
63 if ( $fields && %$fields ) {
64 @fields = grep { exists $fields->{ lc $_ } } @fields;
67 my %fields = map { lc $_ => $_ } @fields;
72 return [ "# Group $id does not exist.", [], {}, 1 ];
79 [ qw(id Name Description) ],
91 $create{name} = "Name";
92 $create{description} = "Description";
93 # Do any fields need to be excluded here?
95 foreach my $k (keys %data) {
96 if (exists $create{lc $k}) {
97 $v{$create{lc $k}} = delete $data{$k};
101 $group->CreateUserDefinedGroup(%v);
102 unless ($group->Id) {
103 return [ "# Could not create group.", [], {}, 1 ];
108 push(@comments, "# Group $id created.");
109 goto DONE if %data == 0;
116 push @data, [ id => "group/".$group->Id ];
117 foreach my $key (@fields) {
118 push @data, [ $key => $group->$key ];
122 unless ( $fields && !exists $fields->{members} ) {
124 my $GroupMembers = $group->MembersObj();
125 while ( my $mo = $GroupMembers->Next() ) {
126 if ( $mo->MemberObj->IsGroup ) {
127 my $us = $mo->MemberObj->Object->UserMembersObj();
129 while ( my $u = $us->Next() ) {
130 push @users, $u->RealName . ' <' . $u->EmailAddress . '>';
134 . $mo->MemberObj->Object->Name . ']' . ' ('
135 . join( ';', @users ) . ')';
136 } elsif ( $mo->MemberObj->IsUser ) {
138 $mo->MemberObj->Object->RealName . ' <'
139 . $mo->MemberObj->Object->EmailAddress . '>';
142 push @data, [ Members => $gms ];
146 my $CustomFields = $group->CustomFields;
147 while ( my $CustomField = $CustomFields->Next() ) {
150 || exists $fields->{ lc "CF-" . $CustomField->Name } );
151 next unless $CustomField->CurrentUserHasRight('SeeCustomField');
152 my $CFvalues = $group->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 'description' || exists $fields{$key})
174 if (exists $fields{$key}) {
175 $key = $fields{$key};
178 $key = "Description" if $key eq 'description';
179 $key = "Name" if $key eq 'name';
183 next if $val eq $group->$key;
184 ($n, $s) = $group->$set($val);
186 elsif ($key ne 'id') {
188 $s = "Unknown field.";
194 push @comments, "# $key: $s";
196 my %o = keys %$changes;
197 delete @o{"id", @fields};
198 @$o = ("id", @fields, keys %o);
207 push(@comments, "# Group $id updated.") if $updated;
211 $c ||= join("\n", @comments) if @comments;
212 return [ $c, $o, $k, $e ];