[Rt-devel] REST: should retrieving a particular attachment require a ticket number?

Dmitri Tikhonov dtikhonov at yahoo.com
Tue Jul 25 18:26:09 EDT 2006


Dear fellow RTers,

Looking at html/REST/1.0/Forms/ticket/attachments, I realized that one
does not really need to pass the ticket id in order to see a particular
attachment.  As it stands right now, however, this is enforced by the
implementation.  Let's look at an example run of 'rt' utility
(attached).  Since RT::Attachment is an object in its own right, why
not allow it to be accessed as such?  Furthermore, ticket-loading code
at the top of html/REST/1.0/Forms/ticket/attachments does not do
anything useful, because it does not check whether a specific
attachment is actually associated with the ticket.

Attached patch moves ticket-loading code to the place where it's
needed, so one can access any attachment using rt tool by saying

  rt show ticket/0/attachments/6

To take things even further, why shouldn't there be
html/REST/1.0/Forms/attachment?  Then we could say things like

  rt show attachment/6

Rationale: as I am writing RT::Client::REST, I am trying to make a
uniform framework for creating, editing, and retrieving of *any*
REST-supported RT object.  Attachments, by being unnecessarily (IMO)
tagged onto ticket, don't fit into my paradigm (you may call it a
fantasy world, though :).

Questions:
1. What do you think?  Agree/disagree?
2. If the answer to (1) is agree, will you accept a patch?

Thank you,

  - Dmitri.

P.S.  RT::Client::REST 0.12 is now up on CPAN.  While docs are still
pretty scarce, you can see where I am going with it.
-------------- next part --------------
[dmitri at localhost ~]$ /opt/rt3/bin/rt show ticket/1/attachments
id: ticket/1/attachments

Attachments: 1:  (text/plain / 26b), 2:  (text/plain / 637b),
             6:  (text/plain / 2b), 7:  (text/plain / 4b),
             8:  (text/plain / 5b), 9:  (text/plain / 4b),
             10:  (text/plain / 5b),
             11: rt-3.6-rest.patch.txt (text/plain / 1.3k),
             12: BeepBeep.pm (text/plain / 93b),
             13:  (text/plain / 5b), 14:  (text/plain / 6b)
[dmitri at localhost ~]$ /opt/rt3/bin/rt show ticket/1/attachments/6
id: 6
Subject:
Creator: 34
Created: 2006-07-24 01:43:18
Transaction: 58
Parent: 0
MessageId:
Filename:
ContentType: text/plain
ContentEncoding: none

Headers: MIME-Version: 1.0
         X-Mailer: MIME-tools 5.420 (Entity 5.420)
         RT-Send-CC:
         RT-Message-ID: <rt-3.6.HEAD-24109-1153705398-218.1-0-0 at example.com>
         Content-Type: text/plain
         Content-Disposition: inline
         Content-Transfer-Encoding: binary
         Content-Length: 2

Content: ac
[dmitri at localhost ~]$
-------------- next part --------------
Index: Forms/ticket/attachments
===================================================================
RCS file: /home/dmitri/cvs/rt3/html/REST/1.0/Forms/ticket/attachments,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 attachments
*** Forms/ticket/attachments	22 Jul 2006 23:24:32 -0000	1.1.1.1
--- Forms/ticket/attachments	25 Jul 2006 22:07:09 -0000
***************
*** 52,63 ****
  <%INIT>
  my @data;
  my ($c, $o, $k, $e) = ("", [], {}, "");
- my $ticket = new RT::Ticket $session{CurrentUser};
- 
- $ticket->Load($id);
- unless ($ticket->Id) {
-     return [ "# Ticket $id does not exist.", [], {}, 1 ];
- }
  
  my @arglist = split('/', $args);
  my ($aid, $content);
--- 52,57 ----
***************
*** 103,108 ****
--- 97,108 ----
  
  }
  else {
+     my $ticket = new RT::Ticket $session{CurrentUser};
+ 
+     $ticket->Load($id);
+     unless ($ticket->Id) {
+         return [ "# Ticket $id does not exist.", [], {}, 1 ];
+     }
      my @attachments;
      my $transactions = $ticket->Transactions;
      while (my $t = $transactions->Next) {


More information about the Rt-devel mailing list