[Bps-public-commit] RT-Extension-NHD branch, master, updated. 7f3ae82fbcffe7a4fa0751888737563b7966c95f

Ruslan Zakirov ruz at bestpractical.com
Thu Nov 10 09:41:05 EST 2011


The branch, master has been updated
       via  7f3ae82fbcffe7a4fa0751888737563b7966c95f (commit)
       via  83c8b2dded91e3127e3acfa46d4694105d885363 (commit)
      from  3bb9641c6925589dbecbf09e9cc3c86482ffb41b (commit)

Summary of changes:
 lib/RT/Extension/NetworkedHelpDesk.pm |   14 +++++++++++-
 lib/RT/NHD/Ticket.pm                  |   39 ++++++++++++++++++++++-----------
 t/rest/ticket.t                       |    7 +++--
 3 files changed, 43 insertions(+), 17 deletions(-)

- Log -----------------------------------------------------------------
commit 83c8b2dded91e3127e3acfa46d4694105d885363
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 10 12:57:42 2011 +0400

    fix UUID retreiving and generation

diff --git a/lib/RT/Extension/NetworkedHelpDesk.pm b/lib/RT/Extension/NetworkedHelpDesk.pm
index e2892c4..84035fe 100644
--- a/lib/RT/Extension/NetworkedHelpDesk.pm
+++ b/lib/RT/Extension/NetworkedHelpDesk.pm
@@ -65,6 +65,18 @@ sub CheckUUID {
     return 1;
 }
 
+sub ObjectUUID {
+    my $self = shift;
+    my %args = @_%2? ( Object => @_ ) : (@_);
+
+    my ($info) = $args{'Object'}->Attributes->Named('NHD');
+    return undef unless $info;
+    $info = $info->Content || {};
+    my $res;
+    $res = $info->{ $args{'Agreement'}->UUID } if $args{'Agreement'};
+    return $res || $info->{''};
+}
+
 sub JSONRequest {
     my $self = shift;
     my ($method, $uri, %args) = @_;
diff --git a/lib/RT/NHD/Ticket.pm b/lib/RT/NHD/Ticket.pm
index e940b25..9eb0d4b 100644
--- a/lib/RT/NHD/Ticket.pm
+++ b/lib/RT/NHD/Ticket.pm
@@ -152,9 +152,9 @@ sub id { (shift)->Ticket->id }
 sub UUID {
     my $self = shift;
     my $agreement = shift;
-    my ($info) = $self->Ticket->Attributes->Named('NHD');
-    return undef unless $info;
-    return $info->{ $agreement->UUID } || $info->{''};
+    return RT::Extension::NetworkedHelpDesk->ObjectUUID(
+        $self->Ticket, Agreement => $agreement,
+    );
 }
 
 our %FIELDS_MAP = (
@@ -255,8 +255,9 @@ sub PresentUser {
     my %args = @_%2? (User => @_) : @_;
 
     my $user = $args{'User'};
-    my $info = ($user->Attributes->Named('NHD'))[0] || {};
-    my $uuid = $info->{ $args{'Agreement'}->UUID } || $info->{''};
+    my $uuid = RT::Extension::NetworkedHelpDesk->ObjectUUID(
+        $user, Agreement => $args{'Agreement'},
+    );
     unless ( $uuid ) {
         $uuid = sha1_hex(
             join '', 'users', $user->id, $user->Name, $user->EmailAddress
@@ -289,23 +290,30 @@ sub AddAttributes {
 
     if ( $args{'NewObject'} ) {
         my ($status, $msg) = $args{'Object'}->AddAttribute(
-            Name => 'NHDUUID', Value => $args{'UUID'},
+            Name => 'NHDUUID', Content => $args{'UUID'},
         );
         return ($status, $msg) unless $status;
 
         return $args{'Object'}->AddAttribute(
             Name => 'NHD',
-            Value => { $args{'Agreement'}->UUID => $args{'UUID'} },
+            Content => { $args{'Agreement'}->UUID => $args{'UUID'} },
         );
     } else {
         my ($status, $msg) = $args{'Object'}->AddAttribute(
-            Name => 'NHDUUID', Value => $args{'UUID'},
+            Name => 'NHDUUID', Content => $args{'UUID'},
         );
         return ($status, $msg) unless $status;
 
-        my ($info) = $args{'Object'}->Attributes->Named('NHD');
-        $info->{''} = $args{'UUID'};
-        return $args{'Object'}->SetAttribute( Name => 'NHD', Value => $info );
+        my $attr = ($args{'Object'}->Attributes->Named('NHD'))[0];
+        unless ( $attr ) {
+            return $args{'Object'}->AddAttribute(
+                Name => 'NHD',
+                Content => { $args{'Agreement'}->UUID => $args{'UUID'} },
+            );
+        }
+        my %info = %{ $attr->Content || {} };
+        $info{''} = $args{'UUID'};
+        return $args{'Object'}->SetAttribute( Name => 'NHD', Content => \%info );
     }
 }
 

commit 7f3ae82fbcffe7a4fa0751888737563b7966c95f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 10 12:58:28 2011 +0400

    fix dates handling
    
    * NHD in examples uses format that has nothing to do with
      XML schema. Use format from examples and name it NHD
    
    * handle timezones when parsing

diff --git a/lib/RT/Extension/NetworkedHelpDesk.pm b/lib/RT/Extension/NetworkedHelpDesk.pm
index 84035fe..50f1dbc 100644
--- a/lib/RT/Extension/NetworkedHelpDesk.pm
+++ b/lib/RT/Extension/NetworkedHelpDesk.pm
@@ -168,7 +168,7 @@ sub WebSendJSON {
 use RT::Date;
 {
     package RT::Date;
-    sub XMLSchema {
+    sub NHD {
         my $self = shift;
         my %args = (
             Date => 1,
diff --git a/lib/RT/NHD/Ticket.pm b/lib/RT/NHD/Ticket.pm
index 9eb0d4b..cc23f22 100644
--- a/lib/RT/NHD/Ticket.pm
+++ b/lib/RT/NHD/Ticket.pm
@@ -180,7 +180,7 @@ sub ForJSON {
     my %res;
     $res{'uuid'} = $self->UUID( $args{'Agreement'} );
     $res{'subject'} = $ticket->Subject;
-    $res{'requested_at'} = $ticket->CreatedObj->XMLSchema;
+    $res{'requested_at'} = $ticket->CreatedObj->NHD;
     $res{'status'} = $ticket->Status; # XXX: convert it
 
     if ( my $requestor = $ticket->Requestors->UserMembersObj->First ) {
@@ -203,8 +203,13 @@ sub FromJSON {
             next unless exists $args->{ $v };
             $res->{ $k } = $args->{ $v };
             if ( $k eq 'Created' || $k eq 'Updated' ) {
+                my $shift;
+                if ( $res->{ $k } =~ s/\s*(?:([+-])([0-9]{2}):?([0-9]{2})|Z)$//i && ($2||$3) ) {
+                    $shift = ($2*60+$3)*60* ($1 eq '-'? -1 : 1);
+                }
                 my $date = RT::Date->new( RT->SystemUser );
-                $date->Set( Format => 'unknown', Value => $res->{ $k } );
+                $date->Set( Format => 'ISO', Value => $res->{ $k } );
+                $date->AddSeconds( -$shift ) if $shift;
                 $res->{ $k } = $date->ISO;
             }
         };
diff --git a/t/rest/ticket.t b/t/rest/ticket.t
index 17d5b21..9489ca2 100644
--- a/t/rest/ticket.t
+++ b/t/rest/ticket.t
@@ -1,7 +1,5 @@
 #!/usr/bin/perl
 
-BEGIN { $ENV{TZ} = 'GMT' };
-
 use strict;
 use warnings;
 
@@ -9,6 +7,9 @@ use RT::Extension::NetworkedHelpDesk::Test tests => 13;
 my $test = 'RT::Extension::NetworkedHelpDesk::Test';
 use Digest::SHA1 qw(sha1_hex);
 
+BEGIN { $ENV{TZ} = 'GMT' };
+RT->Config->Set('Timezone' => 'GMT');
+
 $test->started_ok;
 
 my $m = $test->new_agent;
@@ -104,7 +105,7 @@ my $access_key = sha1_hex( ''. ++$i );
         {
             uuid => $uuid,
             subject => 'test ticket',
-            requested_at => "2010-11-24 14:13:54 -0800",
+            requested_at => "2010-11-24 22:13:54 +0000",
             status => 'open',
             requester => {
                 uuid => sha1_hex( ''. $i ),

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list