[Rt-commit] r18040 - in rt/3.999/branches/merge_to_3.8.2: share/html/REST/1.0/Forms/group

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Jan 29 09:40:19 EST 2009


Author: sunnavy
Date: Thu Jan 29 09:40:19 2009
New Revision: 18040

Added:
   rt/3.999/branches/merge_to_3.8.2/share/html/REST/1.0/Forms/group/
   rt/3.999/branches/merge_to_3.8.2/share/html/REST/1.0/Forms/group/customfields
   rt/3.999/branches/merge_to_3.8.2/share/html/REST/1.0/Forms/group/default
   rt/3.999/branches/merge_to_3.8.2/share/html/REST/1.0/Forms/group/ns
Modified:
   rt/3.999/branches/merge_to_3.8.2/   (props changed)

Log:
 r19266 at sunnavys-mb:  sunnavy | 2009-01-29 22:14:02 +0800
 added share/html/REST/1.0/Forms/group


Added: rt/3.999/branches/merge_to_3.8.2/share/html/REST/1.0/Forms/group/customfields
==============================================================================
--- (empty file)
+++ rt/3.999/branches/merge_to_3.8.2/share/html/REST/1.0/Forms/group/customfields	Thu Jan 29 09:40:19 2009
@@ -0,0 +1,96 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%# 
+%# COPYRIGHT:
+%# 
+%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+%#                                          <jesse at bestpractical.com>
+%# 
+%# (Except where explicitly superseded by other copyright notices)
+%# 
+%# 
+%# LICENSE:
+%# 
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%# 
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%# 
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%# 
+%# 
+%# CONTRIBUTION SUBMISSION POLICY:
+%# 
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%# 
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%# 
+%# END BPS TAGGED BLOCK }}}
+%# REST/1.0/Forms/group/customfields
+%#
+<%ARGS>
+$id
+$format => 's'
+$changes => {}
+</%ARGS>
+<%perl>
+my @comments;
+my ($c, $o, $k, $e) = ("", [], {}, 0);
+my $group = RT::Model::Group->new( current_user => Jifty->web->current_user );
+
+$group->load($id);
+if (!$group->Id) {
+    return [ "# Group $id does not exist.", [], {}, 1 ];
+}
+
+if (%$changes) {
+    $e = 1;
+    $c = "Cannot modify Group CF definitions via REST";
+    goto DONE;
+}
+
+my @data;
+
+push @data, [ id => "group/" . $group->Id ];
+my $gcfs = $group->custom_fields;
+while ( my $gcf = $gcfs->next() ) {
+    if ( $format eq "l" ) {
+        my $cfadmin
+            = ( $gcf->single_value ? 'SingleValue' : 'MultiValue' )
+            . $gcf->type
+            . ( $gcf->pattern ? ( ' ' . $gcf->friendly_pattern ) : '' );
+
+        push @data,
+            [ $gcf->name . ' (' . $gcf->description . ')' => $cfadmin ];
+    } else {
+        push @data, [ $gcf->name => "" ];
+    }
+}
+
+my %k = map {@$_} @data;
+$o = [ map { $_->[0] } @data ];
+$k = \%k;
+
+DONE:
+$c ||= join("\n", @comments) if @comments;
+return [ $c, $o, $k, $e ];
+</%perl>

Added: rt/3.999/branches/merge_to_3.8.2/share/html/REST/1.0/Forms/group/default
==============================================================================
--- (empty file)
+++ rt/3.999/branches/merge_to_3.8.2/share/html/REST/1.0/Forms/group/default	Thu Jan 29 09:40:19 2009
@@ -0,0 +1,203 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%# 
+%# COPYRIGHT:
+%# 
+%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+%#                                          <jesse at bestpractical.com>
+%# 
+%# (Except where explicitly superseded by other copyright notices)
+%# 
+%# 
+%# LICENSE:
+%# 
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%# 
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%# 
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%# 
+%# 
+%# CONTRIBUTION SUBMISSION POLICY:
+%# 
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%# 
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%# 
+%# END BPS TAGGED BLOCK }}}
+%# REST/1.0/Forms/group/default
+%#
+<%ARGS>
+$id
+$format => 's'
+$fields => undef # these are the fields passed to the rt "-f" flag.
+$changes => {}
+</%ARGS>
+<%perl>
+my @comments;
+my ($c, $o, $k, $e) = ("", [], {}, 0);
+my %data = %$changes;
+my $group = RT::Model::Group->new( current_user => Jifty->web->current_user );
+my @fields = qw(Name Description);
+my %fields = map { lc $_ => $_ } @fields;
+
+if ($id ne 'new') {
+    $group->load($id);
+    if (!$group->Id) {
+        return [ "# Group $id does not exist.", [], {}, 1 ];
+    }
+}
+else {
+    if (%data == 0) {
+        return [
+            "# Required: Name",
+            [ qw(id name description) ],
+            {
+                id => "group/new",
+                name => "",
+                description => ""
+            },
+            0
+        ];
+    }
+    else {
+        my %v;
+        my %create = %fields;
+        $create{name}         = "name";
+        $create{description}   = "description";
+        # Do any fields need to be excluded here?
+
+        foreach my $k (keys %data) {
+            if (exists $create{lc $k}) {
+                $v{$create{lc $k}} = delete $data{$k};
+            }
+        }
+
+        $group->create_user_defined_group(%v);
+        unless ($group->Id) {
+            return [ "# Could not create group.", [], {}, 1 ];
+        }
+
+        $id = $group->Id;
+        delete $data{id};
+        push(@comments, "# Group $id created.");
+        goto DONE if %data == 0;
+    }
+}
+
+if (%data == 0) {
+    my @data;
+
+    push @data, [ id => "group/".$group->Id ];
+    push @data, [ Name => $group->name ];
+    push @data, [ Description => $group->description ];
+
+
+    # Members
+    my $gms = [];
+    my $GroupMembers = $group->members_obj();
+    while ( my $mo = $GroupMembers->next() ) {
+        if ( $mo->member_obj->is_group ) {
+            my $us = $mo->member_obj->object->user_members_obj();
+            my @users;
+            while ( my $u = $us->next() ) {
+                push @users, $u->real_name . ' <' . $u->email . '>';
+            }
+            push @$gms,
+                'GROUP ['
+                . $mo->member_obj->object->name . ']' . ' ('
+                . join( ';', @users ) . ')';
+        } elsif ( $mo->member_obj->is_user ) {
+            push @$gms,
+                $mo->member_obj->object->real_name . ' <'
+                . $mo->member_obj->object->email . '>';
+        }
+    }
+    push @data, [ Members => $gms ];
+
+    # Custom fields
+    my $CustomFields = $group->custom_fields;
+    while ( my $CustomField = $custom_fields->next() ) {
+        next
+            unless ( !%$fields
+            || exists $fields->{ lc "CF-" . $CustomField->name } );
+        next unless $CustomField->current_user_has_right('SeeCustomField');
+        my $CFvalues = $group->custom_field_values( $CustomField->id );
+        my @CFvalues;
+        while ( my $CFvalue = $CFvalues->next() ) {
+            push @CFvalues, $CFvalue->content;
+        }
+        push @data, [ "CF-" . $CustomField->name => \@CFvalues ];
+    }
+
+    my %k = map {@$_} @data;
+    $o = [ map {$_->[0]} @data ];
+    $k = \%k;
+}
+else {
+    my ($get, $set, $key, $val, $n, $s);
+
+    foreach $key (keys %data) {
+        $val = $data{$key};
+        $key = lc $key;
+        $n = 1;
+
+        if ($key eq 'name' || $key eq 'description' || exists $fields{$key})
+        {
+            if (exists $fields{$key}) {
+                $key = $fields{$key};
+            }
+            else {
+                $key = "description" if $key eq 'description';
+                $key = "name" if $key eq 'name';
+            }
+            $set = "set_$key";
+
+            next if $val eq $group->$key;
+            ($n, $s) = $group->$set($val);
+        }
+        elsif ($key ne 'id') {
+            $n = 0;
+            $s = "Unknown field.";
+        }
+
+    SET:
+        if ($n == 0) {
+            $e = 1;
+            push @comments, "# $key: $s";
+            unless (@$o) {
+                my %o = keys %$changes;
+                delete @o{"id", @fields};
+                @$o = ("id", @fields, keys %o);
+                $k = $changes;
+            }
+        }
+    }
+
+    push(@comments, "# Group $id updated.") unless $n == 0;
+}
+
+DONE:
+$c ||= join("\n", @comments) if @comments;
+return [ $c, $o, $k, $e ];
+</%perl>

Added: rt/3.999/branches/merge_to_3.8.2/share/html/REST/1.0/Forms/group/ns
==============================================================================
--- (empty file)
+++ rt/3.999/branches/merge_to_3.8.2/share/html/REST/1.0/Forms/group/ns	Thu Jan 29 09:40:19 2009
@@ -0,0 +1,62 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%# 
+%# COPYRIGHT:
+%# 
+%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+%#                                          <jesse at bestpractical.com>
+%# 
+%# (Except where explicitly superseded by other copyright notices)
+%# 
+%# 
+%# LICENSE:
+%# 
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%# 
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%# 
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%# 
+%# 
+%# CONTRIBUTION SUBMISSION POLICY:
+%# 
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%# 
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%# 
+%# END BPS TAGGED BLOCK }}}
+%# REST/1.0/Forms/group/ns
+%#
+<%ARGS>
+$id
+</%ARGS>
+<%perl>
+use RT::Model::Groups;
+
+my $groups = RT::Model::Groups->new( current_user => Jifty->web->current_user );
+$groups->limit(column => 'name', operator => '=', value => $id);
+if ($groups->count == 0) {
+    return (0, "No group named $id exists.");
+}
+return $groups->next->id;
+</%perl>


More information about the Rt-commit mailing list