[Rt-commit] r10085 - in rt/branches/3.7-EXPERIMENTAL: . html/Elements/GnuPG

ruz at bestpractical.com ruz at bestpractical.com
Mon Dec 24 18:49:24 EST 2007


Author: ruz
Date: Mon Dec 24 18:49:23 2007
New Revision: 10085

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/html/Elements/GnuPG/SignEncryptWidget
   rt/branches/3.7-EXPERIMENTAL/html/Ticket/Create.html
   rt/branches/3.7-EXPERIMENTAL/html/Ticket/Update.html

Log:
 r9879 at cubic-pc (orig r9878):  ruz | 2007-12-11 04:53:51 +0300
 * move more code into SignEncryptWidget


Modified: rt/branches/3.7-EXPERIMENTAL/html/Elements/GnuPG/SignEncryptWidget
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Elements/GnuPG/SignEncryptWidget	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Elements/GnuPG/SignEncryptWidget	Mon Dec 24 18:49:23 2007
@@ -1,24 +1,55 @@
 <table>
 <td><% loc('Sign')%></td>
-<td><& /Widgets/Form/Boolean:InputOnly, Name => 'Sign', CurrentValue => $ARGS{'Sign'} &>
+<td><& /Widgets/Form/Boolean:InputOnly, Name => 'Sign', CurrentValue => $self->{'Sign'} &>
 using <& /Elements/SelectKeyForSigning, Addresses => \@signers &>
 </td>
 <td><% loc('Encrypt')%></td>
-<td><& /Widgets/Form/Boolean:InputOnly, Name => 'Encrypt', CurrentValue => $ARGS{'Encrypt'} &></td>
+<td><& /Widgets/Form/Boolean:InputOnly, Name => 'Encrypt', CurrentValue => $self->{'Encrypt'} &></td>
 </table>
 <%ARGS>
-$QueueObj
+$self => undef,
+$TicketObj => undef,
+$QueueObj => undef,
 </%ARGS>
 <%INIT>
-return unless RT->Config->Get('GnuPG')->{'Enable'};
+return unless $self;
+
+$QueueObj ||= $TicketObj->QueueObj if $TicketObj;
 
 my @signers;
-push @signers, ($ARGS{'UpdateType'}||'') eq "private"
+push @signers, ($self->{'UpdateType'}||'') eq "private"
     ? ( $QueueObj->CommentAddress || RT->Config->Get('CommentAddress') )
     : ( $QueueObj->CorrespondAddress || RT->Config->Get('CorrespondAddress') );
 push @signers, $session{'CurrentUser'}->EmailAddress;
 </%INIT>
 
+<%METHOD new>
+<%ARGS>
+$Arguments => {}
+</%ARGS>
+<%INIT>
+return undef unless RT->Config->Get('GnuPG')->{'Enable'};
+
+require RT::Crypt::GnuPG;
+return { %$Arguments };
+</%INIT>
+</%METHOD>
+
+<%METHOD ShowIssues>
+<%ARGS>
+$self => undef,
+</%ARGS>
+<%INIT>
+return unless $self;
+
+return $m->comp( '/Elements/GnuPGKeyIssues',
+    Issues => $self->{'GnuPGRecipientsKeyIssues'} || [],
+    SignAddresses => $self->{'GnuPGCanNotSignAs'} || [],
+);
+</%INIT>
+</%METHOD>
+
+
 <%METHOD Process>
 <%ARGS>
 $QueueObj
@@ -36,3 +67,78 @@
 }
 </%INIT>
 </%METHOD>
+
+<%METHOD Check>
+<%ARGS>
+$self      => undef
+$Operation => 'Update'
+$TicketObj => undef
+$QueueObj  => undef
+</%ARGS>
+<%INIT>
+return 1 unless $self;
+
+my $checks_failure = 0;
+
+if ( $self->{'Sign'} ) {
+    $QueueObj ||= $TicketObj->QueueObj
+        if $TicketObj;
+
+    my $address = $self->{'SignUsing'};
+    $address ||= $self->{'UpdateType'} eq "private"
+        ? ( $QueueObj->CommentAddress || RT->Config->Get('CommentAddress') )
+        : ( $QueueObj->CorrespondAddress || RT->Config->Get('CorrespondAddress') );
+
+    unless ( RT::Crypt::GnuPG::DrySign( $address ) ) {
+        $self->{'GnuPGCanNotSignAs'} = [ $address ];
+        $checks_failure = 1;
+    } else {
+        RT::Crypt::GnuPG::UseKeyForSigning( $self->{'SignUsing'} )
+            if $self->{'SignUsing'};
+    }
+}
+
+if ( $self->{'Encrypt'} ) {
+
+    my @recipients;
+
+    if ( $Operation eq 'Update' ) {
+        # skip any email addresses that we won't be sending mail to
+        my %squelch = $m->comp(
+            '/Ticket/Elements/PreviewScrips:SquelchRecipients',
+            %$self,
+            TicketObj => $TicketObj
+        );
+
+        @recipients = $m->comp(
+            '/Ticket/Elements/PreviewScrips:GetRecipients',
+            %$self, TicketObj => $TicketObj
+        );
+    }
+    elsif ( $Operation eq 'Create' ) {
+        @recipients = $m->comp(
+            '/Ticket/Elements/PreviewScrips:GetRecipientsOnCreate',
+            %$self,
+        );
+    }
+    else {
+        $RT::Logger->crit('Incorrect operation: '. $Operation );
+    }
+
+    my %seen;
+    @recipients = grep !$seen{ lc $_ }++, @recipients;
+
+    RT::Crypt::GnuPG::UseKeyForEncryption(
+        map { (/^UseKey-(.*)$/)[0] => $self->{ $_ } }
+        grep $self->{ $_ } && /^UseKey-/,
+        keys %$self
+    );
+
+    my ($status, @issues) = RT::Crypt::GnuPG::CheckRecipients( @recipients );
+    $self->{'GnuPGRecipientsKeyIssues'} = \@issues;
+    $checks_failure = 1 unless $status;
+}
+
+return $checks_failure ? 0 : 1;
+</%INIT>
+</%METHOD>

Modified: rt/branches/3.7-EXPERIMENTAL/html/Ticket/Create.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Ticket/Create.html	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Ticket/Create.html	Mon Dec 24 18:49:23 2007
@@ -57,7 +57,10 @@
 <input type="hidden" class="hidden" name="id" value="new" />
 % $m->callback( CallbackName => 'FormStart', ARGSRef => \%ARGS );
 
-<& /Elements/GnuPGKeyIssues, Issues => \@gnupg_keys_issues, SignAddresses => \@cannot_sign_as &>
+<& /Elements/GnuPG/SignEncryptWidget:ShowIssues,
+    self => $gnupg_widget,
+    QueueObj => $QueueObj,
+&>
 
 <div id="Ticket-Create-basics">
 <a name="basics"></a>
@@ -150,9 +153,9 @@
 </td>
 </tr>
 
-% if ( RT->Config->Get('GnuPG')->{'Enable'} ) {
+% if ( $gnupg_widget ) {
 <tr><td>&nbsp;</td><td colspan="5">
-<& /Elements/GnuPG/SignEncryptWidget, %ARGS, QueueObj => $QueueObj &>
+<& /Elements/GnuPG/SignEncryptWidget, self => $gnupg_widget, QueueObj => $QueueObj &>
 </td></tr>
 % }
 
@@ -308,45 +311,16 @@
 }
 
 my $checks_failure = 0;
-my @cannot_sign_as;
-my @gnupg_keys_issues;
 
-if (RT->Config->Get('GnuPG')->{'Enable'}) {
-    require RT::Crypt::GnuPG;
-}
+my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
 
 if ( !exists $ARGS{'AddMoreAttach'} && ($ARGS{'id'}||'') eq 'new' ) {
-
-    # check to see if we have a good passphrase
-    if ( $ARGS{'Sign'} ) {
-        my $address = $ARGS{'SignUsing'}
-            || $QueueObj->CorrespondAddress
-            || RT->Config->Get('CorrespondAddress');
-        unless ( RT::Crypt::GnuPG::DrySign( $address ) ) {
-            push @cannot_sign_as, $address;
-            $checks_failure = 1;
-        } else {
-            RT::Crypt::GnuPG::UseKeyForSigning( $ARGS{'SignUsing'} )
-                if $ARGS{'SignUsing'};
-        }
-    }
-
-    if ( $ARGS{'Encrypt'} ) {
-        my @recipients = $m->comp(
-            '/Ticket/Elements/PreviewScrips:GetRecipientsOnCreate',
-            %ARGS
-        );
-
-        RT::Crypt::GnuPG::UseKeyForEncryption(
-            map { (/^UseKey-(.*)$/)[0] => $ARGS{ $_ } }
-            grep $ARGS{$_} && /^UseKey-/,
-            keys %ARGS
-        );
-
-        my $status;
-        ($status, @gnupg_keys_issues) = RT::Crypt::GnuPG::CheckRecipients( @recipients );
-        $checks_failure = 1 unless $status;
-    }
+    my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
+        self      => $gnupg_widget,
+        Operation => 'Create',
+        QueueObj  => $QueueObj,
+    );
+    $checks_failure = 1 unless $status;
 }
 
 

Modified: rt/branches/3.7-EXPERIMENTAL/html/Ticket/Update.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Ticket/Update.html	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Ticket/Update.html	Mon Dec 24 18:49:23 2007
@@ -60,7 +60,10 @@
 <input type="hidden" class="hidden" name="DefaultStatus" value="<% $DefaultStatus ||''%>" />
 <input type="hidden" class="hidden" name="Action" value="<% $ARGS{Action}||'' %>" />
 
-<& /Elements/GnuPGKeyIssues, Issues => \@gnupg_keys_issues, SignAddresses => \@cannot_sign_as &>
+<& /Elements/GnuPG/SignEncryptWidget:ShowIssues,
+    self => $gnupg_widget,
+    TicketObj => $TicketObj,
+&>
 
 <table border="0">
 
@@ -122,9 +125,12 @@
 <tr><td align="right"><&|/l&>Attach</&>:</td><td><input name="Attach" type="file" /><input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" /><input type="hidden" class="hidden" name="UpdateAttach" value="1" />
 </td></tr>
 
-% if ( RT->Config->Get('GnuPG')->{'Enable'} ) {
+% if ( $gnupg_widget ) {
 <tr><td>&nbsp;</td><td>
-<& /Elements/GnuPG/SignEncryptWidget, %ARGS, QueueObj => $TicketObj->QueueObj &>
+<& /Elements/GnuPG/SignEncryptWidget,
+    self => $gnupg_widget,
+    TicketObj => $TicketObj,
+&>
 </td></tr>
 % }
 
@@ -239,55 +245,15 @@
 # }}}
 
 my @results;
-my @cannot_sign_as;
-my @gnupg_keys_issues;
 
-if (RT->Config->Get('GnuPG')->{'Enable'}) {
-    require RT::Crypt::GnuPG;
-}
+my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
 
 if ( $ARGS{'SubmitTicket'} ) {
-
-    # check to see if we have a good passphrase
-    if ( $ARGS{'Sign'} ) {
-        my $address = $ARGS{'SignUsing'};
-        $address ||= $ARGS{'UpdateType'} eq "private"
-            ? ( $TicketObj->QueueObj->CommentAddress
-                || RT->Config->Get('CommentAddress') )
-            : ( $TicketObj->QueueObj->CorrespondAddress
-                || RT->Config->Get('CorrespondAddress') );
-        unless ( RT::Crypt::GnuPG::DrySign( $address ) ) {
-            push @cannot_sign_as, $address;
-            $checks_failure = 1;
-        } else {
-            RT::Crypt::GnuPG::UseKeyForSigning( $ARGS{'SignUsing'} )
-                if $ARGS{'SignUsing'}
-        }
-    }
-
-    if ( $ARGS{'Encrypt'} ) {
-
-        # skip any email addresses that we won't be sending mail to
-        my %squelch = $m->comp(
-                        '/Ticket/Elements/PreviewScrips:SquelchRecipients',
-                        %ARGS, TicketObj => $TicketObj
-                    );
-        my %seen = map { lc($_) => 1 } @{ $squelch{'EmailAddresses'} };
-
-        my @recipients = grep {!$seen{lc $_}} $m->comp(
-            '/Ticket/Elements/PreviewScrips:GetRecipients',
-            %ARGS, TicketObj => $TicketObj
-        );
-
-        RT::Crypt::GnuPG::UseKeyForEncryption(
-            map { (/^UseKey-(.*)$/)[0] => $ARGS{ $_ } }
-            grep $ARGS{$_} && /^UseKey-/,
-            keys %ARGS
-        );
-        my $status;
-        ($status, @gnupg_keys_issues) = RT::Crypt::GnuPG::CheckRecipients( @recipients );
-        $checks_failure = 1 unless $status;
-    }
+    my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
+        self      => $gnupg_widget,
+        TicketObj => $TicketObj,
+    );
+    $checks_failure = 1 unless $status;
 }
 
 if ( !$checks_failure && exists $ARGS{SubmitTicket} ) {


More information about the Rt-commit mailing list