[Jifty-commit] jifty-plugin-feedback branch, master, updated. 0.04-2-g681c215

Jifty commits jifty-commit at lists.jifty.org
Thu Feb 3 12:24:12 EST 2011


The branch, master has been updated
       via  681c215b181a47488d5f99f8301df46dd391519e (commit)
       via  63b33d9f48ecaa9516f32f5d6b27df881d3ca67f (commit)
      from  faa8f478379fbdfb4632a6e280d259ef43cb726d (commit)

Summary of changes:
 lib/Jifty/Plugin/Feedback.pm                     |   13 +++++--
 lib/Jifty/Plugin/Feedback/Action/SendFeedback.pm |   38 ++++++++++---------
 lib/Jifty/Plugin/Feedback/Notification.pm        |   42 ++++++++++++++++++++++
 3 files changed, 71 insertions(+), 22 deletions(-)
 create mode 100644 lib/Jifty/Plugin/Feedback/Notification.pm

- Log -----------------------------------------------------------------
commit 63b33d9f48ecaa9516f32f5d6b27df881d3ca67f
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Feb 3 12:22:44 2011 -0500

    Refactor the feedback notification into a proper class
    
    This lets the user override the notification class used in their config
    and subclass the default Jifty::Plugin::Feedback::Notification class.

diff --git a/lib/Jifty/Plugin/Feedback.pm b/lib/Jifty/Plugin/Feedback.pm
index db92d9b..7f2edfc 100644
--- a/lib/Jifty/Plugin/Feedback.pm
+++ b/lib/Jifty/Plugin/Feedback.pm
@@ -20,6 +20,8 @@ Add to your app's config:
     - Feedback: 
         from: defaultsender at example.com
         to: recipient at example.com
+        # optional
+        notification: YourApp::Notification::Feedback
 
 Add to your app's UI where you want the feedback box:
 
@@ -27,12 +29,14 @@ Add to your app's UI where you want the feedback box:
 
 =cut
 
-__PACKAGE__->mk_accessors(qw(from to));
+__PACKAGE__->mk_accessors(qw(from to notification));
 
 =head2 init
 
-Initializes the Feedback object. Takes a paramhash with keys 'from'
-and 'to', which are email addresses.
+Initializes the Feedback object. Takes a paramhash with keys C<from> and C<to>,
+which are email addresses.  The optional C<notification> key is used to
+override the plugin's default L<Jifty::Plugin::Feedback::Notification> when
+sending mail.
 
 =cut
 
@@ -41,6 +45,7 @@ sub init {
     my %opt = @_;
     $self->from($opt{'from'});
     $self->to($opt{'to'});
+    $self->notification($opt{'notification'} || 'Jifty::Plugin::Feedback::Notification');
 }
 
 =head1 AUTHOR
diff --git a/lib/Jifty/Plugin/Feedback/Action/SendFeedback.pm b/lib/Jifty/Plugin/Feedback/Action/SendFeedback.pm
index 6d84955..1736daa 100755
--- a/lib/Jifty/Plugin/Feedback/Action/SendFeedback.pm
+++ b/lib/Jifty/Plugin/Feedback/Action/SendFeedback.pm
@@ -48,33 +48,35 @@ sub take_action {
     return 1 unless ( $self->argument_value('content') );
 
     my ($plugin) = Jifty->find_plugin('Jifty::Plugin::Feedback');
-    my $debug_info = $self->build_debugging_info();
-
-    my $msg = $self->argument_value('content') . "\n\n" . $debug_info;
-    my $subject = substr( $self->argument_value('content'), 0, 60 );
-    $subject =~ s/\n/ /g;
-
-    # Fall back to normal email
-    my $mail = Jifty::Notification->new;
-    $mail->body($msg);
+    my $from     = $plugin->from;
 
+    # Set the from to the current user if we can
     if (    Jifty->web->current_user->id
          && Jifty->web->current_user->user_object->can('email') ) {
 
          my $user = Jifty->web->current_user->user_object;
          my $CurrentUser = Jifty->app_class('CurrentUser');
          $user->current_user( $CurrentUser->superuser );
-         $mail->from( $user->email() || $plugin->from );
-    }
-    else {
-        $mail->from( $plugin->from );
+         $from = $user->email() || $plugin->from;
     }
 
-    $mail->recipients( $plugin->to );
-    $mail->subject( "["
-            . Jifty->config->framework('ApplicationName')
-            . " feedback] "
-            . $subject );
+    my $body = $self->argument_value('content') . "\n\n" .
+               $self->build_debugging_info;
+
+    my $subject = substr( $self->argument_value('content'), 0, 60 );
+    $subject =~ s/\n/ /g;    
+
+    Jifty::Util->require($plugin->notification);
+
+    # Specifying all our notification attributes in the constructor makes for
+    # easier to write a custom feedback notification class
+    my $mail = $plugin->notification->new(
+        recipients  => $plugin->to,
+        from        => $from,
+        subject     => $subject,
+        body        => $body,
+    );
+
     $mail->send_one_message;
 
     $self->result->message(qq[Thanks for the feedback. We appreciate it!]);
diff --git a/lib/Jifty/Plugin/Feedback/Notification.pm b/lib/Jifty/Plugin/Feedback/Notification.pm
new file mode 100644
index 0000000..49bd14d
--- /dev/null
+++ b/lib/Jifty/Plugin/Feedback/Notification.pm
@@ -0,0 +1,42 @@
+use warnings;
+use strict;
+
+package Jifty::Plugin::Feedback::Notification;
+use base qw/Jifty::Notification/;
+
+=head1 NAME
+
+Jifty::Plugin::Feedback::Notification - the default feedback email
+
+=head1 ARGUMENTS
+
+=over
+
+=item recipients
+
+=item from
+
+=item body
+
+=back
+
+=cut
+
+=head2 setup
+
+Set up the subject
+
+=cut
+
+sub setup {
+    my $self = shift;
+    $self->SUPER::setup(@_);
+
+    # Subject: [AppName feedback] first 60 chars of message [set by the action]
+    my $subject = "[".Jifty->config->framework('ApplicationName')." feedback] ";
+    $subject .= $self->subject;
+    $self->subject($subject);
+}
+
+1;
+

commit 681c215b181a47488d5f99f8301df46dd391519e
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Feb 3 12:24:07 2011 -0500

    Bump the version for external deps

diff --git a/lib/Jifty/Plugin/Feedback.pm b/lib/Jifty/Plugin/Feedback.pm
index 7f2edfc..5664aa2 100644
--- a/lib/Jifty/Plugin/Feedback.pm
+++ b/lib/Jifty/Plugin/Feedback.pm
@@ -4,7 +4,7 @@ use warnings;
 package Jifty::Plugin::Feedback;
 use base qw/Jifty::Plugin Class::Accessor::Fast/;
 
-our $VERSION = '0.04';
+our $VERSION = '0.05';
 
 =head1 NAME
 

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


More information about the Jifty-commit mailing list