[Bps-public-commit] RT-Extension-NHD branch, master, updated. 3bb9641c6925589dbecbf09e9cc3c86482ffb41b
Ruslan Zakirov
ruz at bestpractical.com
Wed Nov 9 18:01:13 EST 2011
The branch, master has been updated
via 3bb9641c6925589dbecbf09e9cc3c86482ffb41b (commit)
via 927ce39c93b104d9f7346cd0ff707b55a6b24e84 (commit)
from 30c8a6128c733fb54dccbdea2f576ded80e2e136 (commit)
Summary of changes:
TODO | 3 +
lib/RT/Extension/NetworkedHelpDesk.pm | 35 +++++++++++-
lib/RT/NHD/Ticket.pm | 104 +++++++++++++++++++++++++++++++-
spec_question.txt | 5 ++
t/rest/ticket.t | 27 ++++++++-
5 files changed, 168 insertions(+), 6 deletions(-)
- Log -----------------------------------------------------------------
commit 927ce39c93b104d9f7346cd0ff707b55a6b24e84
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Nov 10 01:24:54 2011 +0400
XML schema date formatter for sharing
diff --git a/lib/RT/Extension/NetworkedHelpDesk.pm b/lib/RT/Extension/NetworkedHelpDesk.pm
index b002d43..ff5e760 100644
--- a/lib/RT/Extension/NetworkedHelpDesk.pm
+++ b/lib/RT/Extension/NetworkedHelpDesk.pm
@@ -153,6 +153,39 @@ sub WebSendJSON {
return $self->GoodWebRequest( $status );
}
+use RT::Date;
+{
+ package RT::Date;
+ sub XMLSchema {
+ my $self = shift;
+ my %args = (
+ Date => 1,
+ Time => 1,
+ Seconds => 1,
+ Timezone => 'user',
+ @_,
+ );
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
+ $self->Localtime( $args{'Timezone'} );
+
+ #the month needs incrementing, as gmtime returns 0-11
+ $mon++;
+
+ my $res = '';
+ if ( $args{'Date'} ) {
+ $res .= sprintf("%04d-%02d-%02d", $year, $mon, $mday);
+ }
+ if ( $args{'Time'} ) {
+ $res .= ' ' if $res;
+ $res .= sprintf '%02d:%02d', $hour, $min;
+ $res .= sprintf ':%02d', $sec if $args{'Seconds'};
+ $res .= sprintf "%s%02d:%02d", $self->_SplitOffset( $offset );
+ }
+
+ return $res;
+ }
+}
+
=head1 AUTHOR
Ruslan Zakirov E<lt>ruz at bestpractical.comE<gt>
commit 3bb9641c6925589dbecbf09e9cc3c86482ffb41b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Nov 10 03:00:52 2011 +0400
first step towards sharing tickets
diff --git a/TODO b/TODO
index 50021be..bb52f2e 100644
--- a/TODO
+++ b/TODO
@@ -15,3 +15,6 @@
*** done, test it
* deal with users for tickets
+
+* make sure we record and check that this ticket shared by this
+ agreement
diff --git a/lib/RT/Extension/NetworkedHelpDesk.pm b/lib/RT/Extension/NetworkedHelpDesk.pm
index ff5e760..e2892c4 100644
--- a/lib/RT/Extension/NetworkedHelpDesk.pm
+++ b/lib/RT/Extension/NetworkedHelpDesk.pm
@@ -27,7 +27,7 @@ sub ProcessRequest {
my ($object, $action, $data) = @args{qw(Object Action Data)};
if ( $object->id ) {
if ( $action eq 'show' ) {
- return $self->WebSendJSON( $object->ForJSON );
+ return $self->WebSendJSON( $object->ForJSON( %$data ) );
}
elsif ( $action eq 'update' ) {
my ($status, $msg) = $object->Update( %$data );
@@ -179,7 +179,7 @@ use RT::Date;
$res .= ' ' if $res;
$res .= sprintf '%02d:%02d', $hour, $min;
$res .= sprintf ':%02d', $sec if $args{'Seconds'};
- $res .= sprintf "%s%02d:%02d", $self->_SplitOffset( $offset );
+ $res .= sprintf " %s%02d%02d", $self->_SplitOffset( $offset );
}
return $res;
diff --git a/lib/RT/NHD/Ticket.pm b/lib/RT/NHD/Ticket.pm
index 090ab30..e940b25 100644
--- a/lib/RT/NHD/Ticket.pm
+++ b/lib/RT/NHD/Ticket.pm
@@ -95,7 +95,13 @@ sub Create {
);
$self->Ticket( $ticket );
- $ticket->AddAttribute( Name => 'NHDUUID', Value => $args{'UUID'} );
+ (my $status, $msg) = $self->AddAttributes(
+ Object => $ticket,
+ UUID => $args{'UUID'},
+ Agreement => $agreement,
+ );
+ return ($status, "Couldn't add attribute: $msg")
+ unless $status;
return ($id, $msg);
}
@@ -143,6 +149,14 @@ sub Update {
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->{''};
+}
+
our %FIELDS_MAP = (
Subject => 'subject',
Status => 'status',
@@ -151,7 +165,7 @@ our %FIELDS_MAP = (
Requestor => 'requester',
Creator => 'author',
Content => 'body',
- Created => 'authored_at',
+ Updated => 'authored_at',
Corresponds => 'comments',
Name => 'name',
UpdatedBy => 'current_actor',
@@ -159,8 +173,23 @@ our %FIELDS_MAP = (
sub ForJSON {
my $self = shift;
+ my %args = @_;
+
+ my $ticket = $self->Ticket;
my %res;
+ $res{'uuid'} = $self->UUID( $args{'Agreement'} );
+ $res{'subject'} = $ticket->Subject;
+ $res{'requested_at'} = $ticket->CreatedObj->XMLSchema;
+ $res{'status'} = $ticket->Status; # XXX: convert it
+
+ if ( my $requestor = $ticket->Requestors->UserMembersObj->First ) {
+ $res{'requester'} = $self->PresentUser(
+ User => $requestor, Agreement => $args{'Agreement'},
+ );
+ }
+
+ return \%res;
}
sub FromJSON {
@@ -173,10 +202,10 @@ sub FromJSON {
while ( my ($k, $v) = each %FIELDS_MAP ) {
next unless exists $args->{ $v };
$res->{ $k } = $args->{ $v };
- if ( $k eq 'Created' ) {
+ if ( $k eq 'Created' || $k eq 'Updated' ) {
my $date = RT::Date->new( RT->SystemUser );
$date->Set( Format => 'unknown', Value => $res->{ $k } );
- $res->{ $k } = $date;
+ $res->{ $k } = $date->ISO;
}
};
return $res;
@@ -210,9 +239,76 @@ sub LoadOrCreateUser {
Comments => "Auto created by Networked Help Desk",
);
return ($status, $msg) unless $status;
+
+ ($status, $msg) = $self->AddAttributes(
+ Object => $user,
+ UUID => $args{'UUID'},
+ Agreement => $args{'Agreement'},
+ );
+ return ($status, "Couldn't add attribute: $msg") unless $status;
+
return ($user, 'Created');
}
+sub PresentUser {
+ my $self = shift;
+ my %args = @_%2? (User => @_) : @_;
+
+ my $user = $args{'User'};
+ my $info = ($user->Attributes->Named('NHD'))[0] || {};
+ my $uuid = $info->{ $args{'Agreement'}->UUID } || $info->{''};
+ unless ( $uuid ) {
+ $uuid = sha1_hex(
+ join '', 'users', $user->id, $user->Name, $user->EmailAddress
+ );
+ my ($status, $msg) = $self->AddAttributes(
+ NewObject => 0,
+ Object => $user,
+ UUID => $uuid,
+ Agreement => $args{'Agreement'},
+ );
+ $RT::Logger->error("Couldn't add attribute: $msg")
+ unless $status;
+ }
+
+ return {
+ uuid => $uuid,
+ name => $user->RealName || $user->EmailAddress || $user->Name,
+ };
+}
+
+sub AddAttributes {
+ my $self = shift;
+ my %args = (
+ Object => undef,
+ UUID => undef,
+ Agreement => undef,
+ NewObject => 1,
+ @_
+ );
+
+ if ( $args{'NewObject'} ) {
+ my ($status, $msg) = $args{'Object'}->AddAttribute(
+ Name => 'NHDUUID', Value => $args{'UUID'},
+ );
+ return ($status, $msg) unless $status;
+
+ return $args{'Object'}->AddAttribute(
+ Name => 'NHD',
+ Value => { $args{'Agreement'}->UUID => $args{'UUID'} },
+ );
+ } else {
+ my ($status, $msg) = $args{'Object'}->AddAttribute(
+ Name => 'NHDUUID', Value => $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 );
+ }
+}
+
sub RollbackTransaction {
my $self = shift;
my $msg = shift;
diff --git a/spec_question.txt b/spec_question.txt
index ee186ad..70d9333 100644
--- a/spec_question.txt
+++ b/spec_question.txt
@@ -16,3 +16,8 @@
* There are two sections "Retrieving a Ticket Sharing Agreement"
in the spec. Second one should be renamed - "Retrieving a Ticket".
+
+* Two fields (requested_at and authored_at) are defined as "a date
+ expressed in XML-schema format as a string". All examples use
+ completly different format that has nothing to do with XML schema:
+ http://www.w3.org/TR/xmlschema11-2/#vp-dateTimeCanRep
diff --git a/t/rest/ticket.t b/t/rest/ticket.t
index de4b361..17d5b21 100644
--- a/t/rest/ticket.t
+++ b/t/rest/ticket.t
@@ -1,5 +1,7 @@
#!/usr/bin/perl
+BEGIN { $ENV{TZ} = 'GMT' };
+
use strict;
use warnings;
@@ -70,7 +72,7 @@ my $access_key = sha1_hex( ''. ++$i );
is $ticket->Subject, 'test ticket';
is $ticket->Status, 'open';
- my $response = $m->json_request(
+ $response = $m->json_request(
PUT => '/tickets/'. $uuid,
Headers => {
'X-Ticket-Sharing-Token' => "$auuid:$access_key",
@@ -87,5 +89,28 @@ my $access_key = sha1_hex( ''. ++$i );
ok $ticket && $ticket->id, 'created a ticket';
is $ticket->Subject, 'another test ticket';
is $ticket->Status, 'stalled';
+
+ $response = $m->json_request(
+ GET => '/tickets/'. $uuid,
+ Headers => {
+ 'X-Ticket-Sharing-Token' => "$auuid:$access_key",
+ },
+ );
+
+ diag $response->content;
+ my $json = RT::Extension::NetworkedHelpDesk->FromJSON( $response->content );
+ is_deeply(
+ $json,
+ {
+ uuid => $uuid,
+ subject => 'test ticket',
+ requested_at => "2010-11-24 14:13:54 -0800",
+ status => 'open',
+ requester => {
+ uuid => sha1_hex( ''. $i ),
+ name => 'John Doe',
+ },
+ },
+ );
}
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list