From 9dcd7d4af22cc91ba1a97d49892b2a66a9c6d83d Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 26 Feb 2009 15:25:12 -0800 Subject: [PATCH 01/17] Reuse the same hash in the loop, modifying the unique keys. --- lib/WebGUI/Account/Inbox.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/WebGUI/Account/Inbox.pm b/lib/WebGUI/Account/Inbox.pm index 57d6b5af1..490abce6b 100644 --- a/lib/WebGUI/Account/Inbox.pm +++ b/lib/WebGUI/Account/Inbox.pm @@ -1151,14 +1151,16 @@ sub www_sendMessageSave { #Let sendMessage deal with displaying errors return $self->www_sendMessage($errorMsg) if $hasError; + my $messageProperties = { + message => $message, + subject => $subject, + status => 'unread', + sentBy => $fromUser->userId + }; + foreach my $uid (@toUsers) { - $inbox->addMessage({ - message => $message, - subject => $subject, - userId => $uid, - status => 'unread', - sentBy => $fromUser->userId - }); + $messageProperties->{userId} = $uid; + $inbox->addMessage($messageProperties); } $self->appendCommonVars($var,$inbox); From 684d67fd374ad25b6f7580598b1058da42bda0e7 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 26 Feb 2009 15:25:43 -0800 Subject: [PATCH 02/17] Only make 1 i18n object. --- lib/WebGUI/Inbox/Message.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Inbox/Message.pm b/lib/WebGUI/Inbox/Message.pm index 9cbcfbd19..5fd779e27 100644 --- a/lib/WebGUI/Inbox/Message.pm +++ b/lib/WebGUI/Inbox/Message.pm @@ -104,9 +104,10 @@ sub create { my $session = shift; my $properties = shift; my $self = {}; + my $i18n = WebGUI::International->new('Inbox_Message'); $self->{_properties}{messageId} = "new"; $self->{_properties}{status} = $properties->{status} || "pending"; - $self->{_properties}{subject} = $properties->{subject} || WebGUI::International->new($session)->get(523); + $self->{_properties}{subject} = $properties->{subject} || $i18n->get(523,'WebGUI'); $self->{_properties}{message} = $properties->{message}; $self->{_properties}{dateStamp} = time(); $self->{_properties}{userId} = $properties->{userId}; From e1f77b502d4abb54b5a38bbd87ee3042456db960 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 26 Feb 2009 15:26:04 -0800 Subject: [PATCH 03/17] Message Center i18n. --- lib/WebGUI/i18n/English/Message_Center.pm | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/WebGUI/i18n/English/Message_Center.pm diff --git a/lib/WebGUI/i18n/English/Message_Center.pm b/lib/WebGUI/i18n/English/Message_Center.pm new file mode 100644 index 000000000..145e507b0 --- /dev/null +++ b/lib/WebGUI/i18n/English/Message_Center.pm @@ -0,0 +1,34 @@ +package WebGUI::i18n::English::Message_Center; + +use strict; + +our $I18N = { + + 'receive inbox notifications' => { + message => q|Inbox notifications contain.|, + context => q|Allows a user to choose how they get notified about things in their Inbox.|, + lastUpdated => 1235685248, + }, + + 'short notification' => { + message => q|Short notification|, + context => q|An abbreviated, short message that they have an email.|, + lastUpdated => 1235685248, + }, + + 'full message' => { + message => q|Full content from message|, + context => q|The entire content of the Inbox message.|, + lastUpdated => 1235685248, + }, + + 'receive inbox emails' => { + message => q|Receive inbox notification via SMS?|, + context => q|Allows a user to choose how they get notified about things in their Inbox.|, + lastUpdated => 1235685248, + }, + +}; + +1; +#vim:ft=perl From b2419bffef944716cfba6f2d26374616d71f333f Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 26 Feb 2009 17:05:23 -0800 Subject: [PATCH 04/17] Utility script for Message Center install. --- sbin/installNotifications.pl | 161 +++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 sbin/installNotifications.pl diff --git a/sbin/installNotifications.pl b/sbin/installNotifications.pl new file mode 100644 index 000000000..273637080 --- /dev/null +++ b/sbin/installNotifications.pl @@ -0,0 +1,161 @@ +#!/usr/bin/env perl + +#------------------------------------------------------------------- +# Copyright 2009 SDH Corporation. +#------------------------------------------------------------------- + +$|++; # disable output buffering +our ($webguiRoot, $configFile, $help, $man); + +BEGIN { + $webguiRoot = ".."; + unshift (@INC, $webguiRoot."/lib"); +} + +use strict; +use Pod::Usage; +use Getopt::Long; +use WebGUI::Session; +use WebGUI::ProfileField; + +# Get parameters here, including $help +GetOptions( + 'configFile=s' => \$configFile, + 'help' => \$help, + 'man' => \$man, +); + +pod2usage( verbose => 1 ) if $help; +pod2usage( verbose => 2 ) if $man; +pod2usage( msg => "Must specify a config file!" ) unless $configFile; + +my $session = start( $webguiRoot, $configFile ); + +installUserProfileFields($session); +installSettings($session); + +# Do your work here +finish($session); + +#---------------------------------------------------------------------------- +# Your sub here + +sub installUserProfileFields { + my $session = shift; + WebGUI::ProfileField->create( + $session, + 'receiveInboxEmailNotifications', + { + label => q!WebGUI::International::get('receive inbox notifications','Message_Center')!, + visible => 1, + required => 0, + protected => 1, + editable => 1, + fieldType => 'radioList', + dataDefault => 0, + possibleValues => q!{ +message => WebGUI::International::get('full message','Message_Center'), +note => WebGUI::International::get('short notification','Message_Center'), +}!, + }, + 4, + ); + WebGUI::ProfileField->create( + $session, + 'receiveInboxSMSNotifications', + { + label => q!WebGUI::International::get('receive inbox sms','Message_Center')!, + visible => 1, + required => 0, + protected => 1, + editable => 1, + fieldType => 'yesNo', + dataDefault => 0, + }, + 4, + ); +} + +sub installSettings { + my $session = shift; + $session->setting->add('smsGateway', ''); + $session->setting->add('sendInboxNotificationsOnly', ''); +} + +#---------------------------------------------------------------------------- +sub start { + my $webguiRoot = shift; + my $configFile = shift; + my $session = WebGUI::Session->open($webguiRoot,$configFile); + $session->user({userId=>3}); + + ## If your script is adding or changing content you need these lines, otherwise leave them commented + # + # my $versionTag = WebGUI::VersionTag->getWorking($session); + # $versionTag->set({name => 'Name Your Tag'}); + # + ## + + return $session; +} + +#---------------------------------------------------------------------------- +sub finish { + my $session = shift; + + ## If your script is adding or changing content you need these lines, otherwise leave them commented + # + # my $versionTag = WebGUI::VersionTag->getWorking($session); + # $versionTag->commit; + ## + + $session->var->end; + $session->close; +} + +__END__ + + +=head1 NAME + +utility - A template for WebGUI utility scripts + +=head1 SYNOPSIS + + utility --configFile config.conf ... + + utility --help + +=head1 DESCRIPTION + +This WebGUI utility script helps you... + +=head1 ARGUMENTS + +=head1 OPTIONS + +=over + +=item B<--configFile config.conf> + +The WebGUI config file to use. Only the file name needs to be specified, +since it will be looked up inside WebGUI's configuration directory. +This parameter is required. + +=item B<--help> + +Shows a short summary and usage + +=item B<--man> + +Shows this document + +=back + +=head1 AUTHOR + +Copyright 2001-2008 Plain Black Corporation. + +=cut + +#vim:ft=perl From 180b454ce777c76fdefce3d57bd45fd884e6a2d4 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 26 Feb 2009 17:05:45 -0800 Subject: [PATCH 05/17] Add settings for inbox notifications/SMS. --- lib/WebGUI/Operation/Settings.pm | 16 +++++++++++++++ lib/WebGUI/ProfileCategory.pm | 1 - lib/WebGUI/i18n/English/Message_Center.pm | 24 ++++++++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index 98ec97d6b..d85901962 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -287,6 +287,22 @@ sub definition { hoverHelp=>$i18n->get('mail return path help'), defaultValue=>$setting->get("mailReturnPath") }); + push(@fields, { + tab => 'messaging', + fieldType => 'email', + name => 'smsGateway', + label => $i18n->get('sms gateway', 'Message_Center'), + hoverHelp => $i18n->get('sms gateway help', 'Message_Center'), + defaultValue => $setting->get('smsGateway'), + }); + push(@fields, { + tab => 'messaging', + fieldType => 'yesNo', + name => 'sendInboxNotificationsOnly', + label => $i18n->get('send inbox notifications only', 'Message_Center'), + hoverHelp => $i18n->get('send inbox notifications only help', 'Message_Center'), + defaultValue => $setting->get('sendInboxNotificationsOnly'), + }); # misc push(@fields, { tab=>"misc", diff --git a/lib/WebGUI/ProfileCategory.pm b/lib/WebGUI/ProfileCategory.pm index a9d570d56..3346ae6cd 100644 --- a/lib/WebGUI/ProfileCategory.pm +++ b/lib/WebGUI/ProfileCategory.pm @@ -1,6 +1,5 @@ package WebGUI::ProfileCategory; - =head1 LEGAL ------------------------------------------------------------------- diff --git a/lib/WebGUI/i18n/English/Message_Center.pm b/lib/WebGUI/i18n/English/Message_Center.pm index 145e507b0..c5d21bf3e 100644 --- a/lib/WebGUI/i18n/English/Message_Center.pm +++ b/lib/WebGUI/i18n/English/Message_Center.pm @@ -22,12 +22,34 @@ our $I18N = { lastUpdated => 1235685248, }, - 'receive inbox emails' => { + 'receive inbox sms' => { message => q|Receive inbox notification via SMS?|, context => q|Allows a user to choose how they get notified about things in their Inbox.|, lastUpdated => 1235685248, }, + 'sms gateway' => { + message => q|SMS gateway|, + context => q|email to SMS/text email address for this site.|, + lastUpdated => 1235685248, + }, + + 'sms gateway help' => { + message => q|The email address that this site would use to send an SMS message.|, + lastUpdated => 1235695517, + }, + + 'send inbox notifications only' => { + message => q|Send only Inbox notifications|, + context => q|Site setting. A notification is a short message that something is in the Inbox.|, + lastUpdated => 1235685248, + }, + + 'send inbox notifications only help' => { + message => q|Should WebGUI always just send notifications about Inbox messages, instead of the message itself?|, + lastUpdated => 1235696295, + }, + }; 1; From ad71df4e3fd99a329b774f1e457211c300b4778d Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 26 Feb 2009 20:42:59 -0800 Subject: [PATCH 06/17] Templated Inbox Notification. Everything but the code to drive and use the template from Account/Inbox. --- lib/WebGUI/Operation/Settings.pm | 9 +++ lib/WebGUI/i18n/English/Message_Center.pm | 5 ++ sbin/installNotifications.pl | 56 +++++++++++++++++- .../inbox_notification.wgpkg | Bin 0 -> 777 bytes 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 sbin/message_center_packages/inbox_notification.wgpkg diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index d85901962..2d81035d6 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -303,6 +303,15 @@ sub definition { hoverHelp => $i18n->get('send inbox notifications only help', 'Message_Center'), defaultValue => $setting->get('sendInboxNotificationsOnly'), }); + push(@fields, { + tab => 'messaging', + fieldType => 'template', + name => 'inboxNotificationTemplateId', + label => $i18n->get('inbox notification template', 'Message_Center'), + hoverHelp => $i18n->get('inbox notification template help', 'Message_Center'), + defaultValue => $setting->get('inboxNotificationTemplateId'), + namespace => 'Account/Inbox/Notification', + }); # misc push(@fields, { tab=>"misc", diff --git a/lib/WebGUI/i18n/English/Message_Center.pm b/lib/WebGUI/i18n/English/Message_Center.pm index c5d21bf3e..c607f8314 100644 --- a/lib/WebGUI/i18n/English/Message_Center.pm +++ b/lib/WebGUI/i18n/English/Message_Center.pm @@ -50,6 +50,11 @@ our $I18N = { lastUpdated => 1235696295, }, + 'inbox notification' => { + message => q|You have a new message in your Inbox.|, + lastUpdated => 1235708853, + }, + }; 1; diff --git a/sbin/installNotifications.pl b/sbin/installNotifications.pl index 273637080..9f6fc0c23 100644 --- a/sbin/installNotifications.pl +++ b/sbin/installNotifications.pl @@ -79,7 +79,8 @@ note => WebGUI::International::get('short notification','Message_Center'), sub installSettings { my $session = shift; $session->setting->add('smsGateway', ''); - $session->setting->add('sendInboxNotificationsOnly', ''); + $session->setting->add('sendInboxNotificationsOnly', 0); + $session->setting->add('inboxNotificationTemplateId', 'b1316COmd9xRv4fCI3LLGA'); } #---------------------------------------------------------------------------- @@ -108,11 +109,64 @@ sub finish { # my $versionTag = WebGUI::VersionTag->getWorking($session); # $versionTag->commit; ## + updateTemplates($session); + my $versionTag = WebGUI::VersionTag->getWorking($session); + $versionTag->commit; $session->var->end; $session->close; } +#------------------------------------------------- +sub updateTemplates { + my $session = shift; + my $packageDir = "message_center_packages"; + return undef unless (-d $packageDir); + print "\tUpdating packages.\n"; + opendir(DIR,$packageDir); + my @files = readdir(DIR); + closedir(DIR); + my $newFolder = undef; + foreach my $file (@files) { + next unless ($file =~ /\.wgpkg$/); + # Fix the filename to include a path + $file = $packageDir . "/" . $file; + addPackage( $session, $file ); + } +} + +sub addPackage { + my $session = shift; + my $file = shift; + + # Make a storage location for the package + my $storage = WebGUI::Storage->createTemp( $session ); + $storage->addFileFromFilesystem( $file ); + + # Import the package into the import node + my $package = WebGUI::Asset->getImportNode($session)->importPackage( $storage ); + + # Make the package not a package anymore + $package->update({ isPackage => 0 }); + + # Set the default flag for templates added + my $assetIds + = $package->getLineage( ['self','descendants'], { + includeOnlyClasses => [ 'WebGUI::Asset::Template' ], + } ); + for my $assetId ( @{ $assetIds } ) { + my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId ); + if ( !$asset ) { + print "Couldn't instantiate asset with ID '$assetId'. Please check package '$file' for corruption.\n"; + next; + } + $asset->update( { isDefault => 1 } ); + } + + return; +} + + __END__ diff --git a/sbin/message_center_packages/inbox_notification.wgpkg b/sbin/message_center_packages/inbox_notification.wgpkg new file mode 100644 index 0000000000000000000000000000000000000000..44e87644a2c36bf1da3171c648c85986912004f2 GIT binary patch literal 777 zcmV+k1NQtMiwFP!00000|Ls&;Z`v>v=DEKj%2O+KZ43z%_QdEdRol^)w!3JnOk%(z z*pcmU>D2$eV-rZYbepsy?Eyc;Qtb2jobUV2IVfy?IgV5Dyh1_mW!LP;h25Gjr+^Uh zP`O-2$Sqh1IYp;nLCEG;A{7>pTEHX9`mev2NFwCx$GSLJrZ}_z=IZ}+WU@vp-=hA5 zN(VnAXaAfoK$W%Lu&>j<=y}WfyOp9>uz=0YuTANHu=&*A;)S0((1f;BT;MLTt(x`q z+rIe~3my}pD3SWFxu$Ohf?!3$4-@^@Mz*=E45hLOrTG9_qOeu>YVM5RG( zR6^y($3a*f-wxeQ!!KQ4p4Bs?L_`LhvNj(-F|KHb23S$fvO83s(=a4#IddwTf-9~j z@wDn(QC-24*bh%as!Wudp(!$mqZv`(eWr+D=0P0onk=k*7W-F3N|5cTLG;bN_Zbjn zJtC;O7tyKUgC-VmV>v~bcO(_vhSr3BU-_nEAj1tnW_gVV)1n?p`|RGY)#{qmTCFw9 zeo^&C53}yvGC8HRWv+M#tb!Sgor)!|;v7|-oUasB(eyQ6%V1rvl_BNyfs(0*Dp|@@ zYNl~JMae0E7 z?QQ+@t~16i2vK(T@&#P-pg$vUp{uAoCLNqaE83cNONlq|)oP_$^(w_&d4de71T!Dc z42Rax4?f00e{Pd3E7{{CpPh0snAV-+m4QEGjDu;x^&sF0Q-?;r!v((QJ|Qd+lUOy^ zyrXb8ZP&+1<1Pqqg4U5Q+za7-ikhRNn=B(L?3KA4cihv)`8$OlS~s>HrY}1$Z!xR47+VIm3~U*AO9p-c0S&6z H01f~E{6KnA literal 0 HcmV?d00001 From 668b1e46e8c3d4dd55b76cd02d0c13e9e6e56404 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 26 Feb 2009 21:42:21 -0800 Subject: [PATCH 07/17] Correct the email/SMS user profile settings to match the spec. --- lib/WebGUI/i18n/English/Message_Center.pm | 18 +++--------------- sbin/installNotifications.pl | 10 +++------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/lib/WebGUI/i18n/English/Message_Center.pm b/lib/WebGUI/i18n/English/Message_Center.pm index c607f8314..7d2dc3d1f 100644 --- a/lib/WebGUI/i18n/English/Message_Center.pm +++ b/lib/WebGUI/i18n/English/Message_Center.pm @@ -4,26 +4,14 @@ use strict; our $I18N = { - 'receive inbox notifications' => { - message => q|Inbox notifications contain.|, + 'receive inbox emails' => { + message => q|Receive Inbox message notifications via email?|, context => q|Allows a user to choose how they get notified about things in their Inbox.|, lastUpdated => 1235685248, }, - 'short notification' => { - message => q|Short notification|, - context => q|An abbreviated, short message that they have an email.|, - lastUpdated => 1235685248, - }, - - 'full message' => { - message => q|Full content from message|, - context => q|The entire content of the Inbox message.|, - lastUpdated => 1235685248, - }, - 'receive inbox sms' => { - message => q|Receive inbox notification via SMS?|, + message => q|Receive Inbox message notifications via SMS?|, context => q|Allows a user to choose how they get notified about things in their Inbox.|, lastUpdated => 1235685248, }, diff --git a/sbin/installNotifications.pl b/sbin/installNotifications.pl index 9f6fc0c23..d658921e7 100644 --- a/sbin/installNotifications.pl +++ b/sbin/installNotifications.pl @@ -46,17 +46,13 @@ sub installUserProfileFields { $session, 'receiveInboxEmailNotifications', { - label => q!WebGUI::International::get('receive inbox notifications','Message_Center')!, + label => q!WebGUI::International::get('receive inbox emails','Message_Center')!, visible => 1, required => 0, protected => 1, editable => 1, - fieldType => 'radioList', - dataDefault => 0, - possibleValues => q!{ -message => WebGUI::International::get('full message','Message_Center'), -note => WebGUI::International::get('short notification','Message_Center'), -}!, + fieldType => 'yesNo', + dataDefault => 1, }, 4, ); From 3eccc9d62f9ca8c03d0d3ba5ea2bccee2865abf2 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 10 Mar 2009 11:48:35 -0700 Subject: [PATCH 08/17] I18n message tweak for clarity. --- lib/WebGUI/i18n/English/Message_Center.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WebGUI/i18n/English/Message_Center.pm b/lib/WebGUI/i18n/English/Message_Center.pm index 7d2dc3d1f..e78d89b0b 100644 --- a/lib/WebGUI/i18n/English/Message_Center.pm +++ b/lib/WebGUI/i18n/English/Message_Center.pm @@ -34,7 +34,7 @@ our $I18N = { }, 'send inbox notifications only help' => { - message => q|Should WebGUI always just send notifications about Inbox messages, instead of the message itself?|, + message => q|Should WebGUI just send notifications about Inbox messages, instead of the message itself?|, lastUpdated => 1235696295, }, From 761ac9adb039792fef1d8cb8362d859280e19214 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 10 Mar 2009 11:48:52 -0700 Subject: [PATCH 09/17] fix a bad templateId for the Notification template. --- lib/WebGUI/Operation/Settings.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index 2d81035d6..d0dc4e7b7 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -306,7 +306,8 @@ sub definition { push(@fields, { tab => 'messaging', fieldType => 'template', - name => 'inboxNotificationTemplateId', + #1234567890123456789012 + name => 'inboxNotification00001', label => $i18n->get('inbox notification template', 'Message_Center'), hoverHelp => $i18n->get('inbox notification template help', 'Message_Center'), defaultValue => $setting->get('inboxNotificationTemplateId'), From 6a41f4aa75b15597b17216b73e59f1114d37b652 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 13 Mar 2009 10:07:35 -0700 Subject: [PATCH 10/17] SMS install script. --- sbin/installSms.pl | 209 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 sbin/installSms.pl diff --git a/sbin/installSms.pl b/sbin/installSms.pl new file mode 100644 index 000000000..c95c41ff7 --- /dev/null +++ b/sbin/installSms.pl @@ -0,0 +1,209 @@ +#!/usr/bin/env perl + +#------------------------------------------------------------------- +# Copyright 2009 SDH Corporation. +#------------------------------------------------------------------- + +$|++; # disable output buffering +our ($webguiRoot, $configFile, $help, $man); + +BEGIN { + $webguiRoot = ".."; + unshift (@INC, $webguiRoot."/lib"); +} + +use strict; +use Pod::Usage; +use Getopt::Long; +use WebGUI::Session; +use WebGUI::ProfileField; + +# Get parameters here, including $help +GetOptions( + 'configFile=s' => \$configFile, + 'help' => \$help, + 'man' => \$man, +); + +pod2usage( verbose => 1 ) if $help; +pod2usage( verbose => 2 ) if $man; +pod2usage( msg => "Must specify a config file!" ) unless $configFile; + +my $session = start( $webguiRoot, $configFile ); + +installUserProfileFields($session); +installSettings($session); + +# Do your work here +finish($session); + +#---------------------------------------------------------------------------- +# Your sub here + +sub installUserProfileFields { + my $session = shift; + WebGUI::ProfileField->create( + $session, + 'receiveInboxEmailNotifications', + { + label => q!WebGUI::International::get('receive inbox emails','Message_Center')!, + visible => 1, + required => 0, + protected => 1, + editable => 1, + fieldType => 'yesNo', + dataDefault => 1, + }, + 4, + ); + WebGUI::ProfileField->create( + $session, + 'receiveInboxSMSNotifications', + { + label => q!WebGUI::International::get('receive inbox sms','Message_Center')!, + visible => 1, + required => 0, + protected => 1, + editable => 1, + fieldType => 'yesNo', + dataDefault => 0, + }, + 4, + ); +} + +sub installSettings { + my $session = shift; + $session->setting->add('smsGateway', ''); +} + +#---------------------------------------------------------------------------- +sub start { + my $webguiRoot = shift; + my $configFile = shift; + my $session = WebGUI::Session->open($webguiRoot,$configFile); + $session->user({userId=>3}); + + ## If your script is adding or changing content you need these lines, otherwise leave them commented + # + # my $versionTag = WebGUI::VersionTag->getWorking($session); + # $versionTag->set({name => 'Name Your Tag'}); + # + ## + + return $session; +} + +#---------------------------------------------------------------------------- +sub finish { + my $session = shift; + + ## If your script is adding or changing content you need these lines, otherwise leave them commented + # + # my $versionTag = WebGUI::VersionTag->getWorking($session); + # $versionTag->commit; + ## + updateTemplates($session); + my $versionTag = WebGUI::VersionTag->getWorking($session); + $versionTag->commit; + + $session->var->end; + $session->close; +} + +#------------------------------------------------- +sub updateTemplates { + my $session = shift; + my $packageDir = "message_center_packages"; + return undef unless (-d $packageDir); + print "\tUpdating packages.\n"; + opendir(DIR,$packageDir); + my @files = readdir(DIR); + closedir(DIR); + my $newFolder = undef; + foreach my $file (@files) { + next unless ($file =~ /\.wgpkg$/); + # Fix the filename to include a path + $file = $packageDir . "/" . $file; + addPackage( $session, $file ); + } +} + +sub addPackage { + my $session = shift; + my $file = shift; + + # Make a storage location for the package + my $storage = WebGUI::Storage->createTemp( $session ); + $storage->addFileFromFilesystem( $file ); + + # Import the package into the import node + my $package = WebGUI::Asset->getImportNode($session)->importPackage( $storage ); + + # Make the package not a package anymore + $package->update({ isPackage => 0 }); + + # Set the default flag for templates added + my $assetIds + = $package->getLineage( ['self','descendants'], { + includeOnlyClasses => [ 'WebGUI::Asset::Template' ], + } ); + for my $assetId ( @{ $assetIds } ) { + my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId ); + if ( !$asset ) { + print "Couldn't instantiate asset with ID '$assetId'. Please check package '$file' for corruption.\n"; + next; + } + $asset->update( { isDefault => 1 } ); + } + + return; +} + + +__END__ + + +=head1 NAME + +utility - A template for WebGUI utility scripts + +=head1 SYNOPSIS + + utility --configFile config.conf ... + + utility --help + +=head1 DESCRIPTION + +This WebGUI utility script helps you... + +=head1 ARGUMENTS + +=head1 OPTIONS + +=over + +=item B<--configFile config.conf> + +The WebGUI config file to use. Only the file name needs to be specified, +since it will be looked up inside WebGUI's configuration directory. +This parameter is required. + +=item B<--help> + +Shows a short summary and usage + +=item B<--man> + +Shows this document + +=back + +=head1 AUTHOR + +Copyright 2001-2008 Plain Black Corporation. + +=cut + +#vim:ft=perl From 8413d2337fc911d59130af330a5aedd463fbf25d Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 13 Mar 2009 10:15:55 -0700 Subject: [PATCH 11/17] Removed this. --- sbin/installNotifications.pl | 211 ----------------------------------- 1 file changed, 211 deletions(-) delete mode 100644 sbin/installNotifications.pl diff --git a/sbin/installNotifications.pl b/sbin/installNotifications.pl deleted file mode 100644 index d658921e7..000000000 --- a/sbin/installNotifications.pl +++ /dev/null @@ -1,211 +0,0 @@ -#!/usr/bin/env perl - -#------------------------------------------------------------------- -# Copyright 2009 SDH Corporation. -#------------------------------------------------------------------- - -$|++; # disable output buffering -our ($webguiRoot, $configFile, $help, $man); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - -use strict; -use Pod::Usage; -use Getopt::Long; -use WebGUI::Session; -use WebGUI::ProfileField; - -# Get parameters here, including $help -GetOptions( - 'configFile=s' => \$configFile, - 'help' => \$help, - 'man' => \$man, -); - -pod2usage( verbose => 1 ) if $help; -pod2usage( verbose => 2 ) if $man; -pod2usage( msg => "Must specify a config file!" ) unless $configFile; - -my $session = start( $webguiRoot, $configFile ); - -installUserProfileFields($session); -installSettings($session); - -# Do your work here -finish($session); - -#---------------------------------------------------------------------------- -# Your sub here - -sub installUserProfileFields { - my $session = shift; - WebGUI::ProfileField->create( - $session, - 'receiveInboxEmailNotifications', - { - label => q!WebGUI::International::get('receive inbox emails','Message_Center')!, - visible => 1, - required => 0, - protected => 1, - editable => 1, - fieldType => 'yesNo', - dataDefault => 1, - }, - 4, - ); - WebGUI::ProfileField->create( - $session, - 'receiveInboxSMSNotifications', - { - label => q!WebGUI::International::get('receive inbox sms','Message_Center')!, - visible => 1, - required => 0, - protected => 1, - editable => 1, - fieldType => 'yesNo', - dataDefault => 0, - }, - 4, - ); -} - -sub installSettings { - my $session = shift; - $session->setting->add('smsGateway', ''); - $session->setting->add('sendInboxNotificationsOnly', 0); - $session->setting->add('inboxNotificationTemplateId', 'b1316COmd9xRv4fCI3LLGA'); -} - -#---------------------------------------------------------------------------- -sub start { - my $webguiRoot = shift; - my $configFile = shift; - my $session = WebGUI::Session->open($webguiRoot,$configFile); - $session->user({userId=>3}); - - ## If your script is adding or changing content you need these lines, otherwise leave them commented - # - # my $versionTag = WebGUI::VersionTag->getWorking($session); - # $versionTag->set({name => 'Name Your Tag'}); - # - ## - - return $session; -} - -#---------------------------------------------------------------------------- -sub finish { - my $session = shift; - - ## If your script is adding or changing content you need these lines, otherwise leave them commented - # - # my $versionTag = WebGUI::VersionTag->getWorking($session); - # $versionTag->commit; - ## - updateTemplates($session); - my $versionTag = WebGUI::VersionTag->getWorking($session); - $versionTag->commit; - - $session->var->end; - $session->close; -} - -#------------------------------------------------- -sub updateTemplates { - my $session = shift; - my $packageDir = "message_center_packages"; - return undef unless (-d $packageDir); - print "\tUpdating packages.\n"; - opendir(DIR,$packageDir); - my @files = readdir(DIR); - closedir(DIR); - my $newFolder = undef; - foreach my $file (@files) { - next unless ($file =~ /\.wgpkg$/); - # Fix the filename to include a path - $file = $packageDir . "/" . $file; - addPackage( $session, $file ); - } -} - -sub addPackage { - my $session = shift; - my $file = shift; - - # Make a storage location for the package - my $storage = WebGUI::Storage->createTemp( $session ); - $storage->addFileFromFilesystem( $file ); - - # Import the package into the import node - my $package = WebGUI::Asset->getImportNode($session)->importPackage( $storage ); - - # Make the package not a package anymore - $package->update({ isPackage => 0 }); - - # Set the default flag for templates added - my $assetIds - = $package->getLineage( ['self','descendants'], { - includeOnlyClasses => [ 'WebGUI::Asset::Template' ], - } ); - for my $assetId ( @{ $assetIds } ) { - my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId ); - if ( !$asset ) { - print "Couldn't instantiate asset with ID '$assetId'. Please check package '$file' for corruption.\n"; - next; - } - $asset->update( { isDefault => 1 } ); - } - - return; -} - - -__END__ - - -=head1 NAME - -utility - A template for WebGUI utility scripts - -=head1 SYNOPSIS - - utility --configFile config.conf ... - - utility --help - -=head1 DESCRIPTION - -This WebGUI utility script helps you... - -=head1 ARGUMENTS - -=head1 OPTIONS - -=over - -=item B<--configFile config.conf> - -The WebGUI config file to use. Only the file name needs to be specified, -since it will be looked up inside WebGUI's configuration directory. -This parameter is required. - -=item B<--help> - -Shows a short summary and usage - -=item B<--man> - -Shows this document - -=back - -=head1 AUTHOR - -Copyright 2001-2008 Plain Black Corporation. - -=cut - -#vim:ft=perl From e70494900adf73cd557dcdb92f46203c6f33fc91 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 13 Mar 2009 10:21:52 -0700 Subject: [PATCH 12/17] Pruning out notifications code from SMS. --- lib/WebGUI/Operation/Settings.pm | 22 +--------- lib/WebGUI/i18n/English/Message_Center.pm | 49 ----------------------- lib/WebGUI/i18n/English/WebGUI.pm | 12 ++++++ 3 files changed, 14 insertions(+), 69 deletions(-) delete mode 100644 lib/WebGUI/i18n/English/Message_Center.pm diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index d0dc4e7b7..83b565971 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -291,28 +291,10 @@ sub definition { tab => 'messaging', fieldType => 'email', name => 'smsGateway', - label => $i18n->get('sms gateway', 'Message_Center'), - hoverHelp => $i18n->get('sms gateway help', 'Message_Center'), + label => $i18n->get('sms gateway'), + hoverHelp => $i18n->get('sms gateway help'), defaultValue => $setting->get('smsGateway'), }); - push(@fields, { - tab => 'messaging', - fieldType => 'yesNo', - name => 'sendInboxNotificationsOnly', - label => $i18n->get('send inbox notifications only', 'Message_Center'), - hoverHelp => $i18n->get('send inbox notifications only help', 'Message_Center'), - defaultValue => $setting->get('sendInboxNotificationsOnly'), - }); - push(@fields, { - tab => 'messaging', - fieldType => 'template', - #1234567890123456789012 - name => 'inboxNotification00001', - label => $i18n->get('inbox notification template', 'Message_Center'), - hoverHelp => $i18n->get('inbox notification template help', 'Message_Center'), - defaultValue => $setting->get('inboxNotificationTemplateId'), - namespace => 'Account/Inbox/Notification', - }); # misc push(@fields, { tab=>"misc", diff --git a/lib/WebGUI/i18n/English/Message_Center.pm b/lib/WebGUI/i18n/English/Message_Center.pm deleted file mode 100644 index e78d89b0b..000000000 --- a/lib/WebGUI/i18n/English/Message_Center.pm +++ /dev/null @@ -1,49 +0,0 @@ -package WebGUI::i18n::English::Message_Center; - -use strict; - -our $I18N = { - - 'receive inbox emails' => { - message => q|Receive Inbox message notifications via email?|, - context => q|Allows a user to choose how they get notified about things in their Inbox.|, - lastUpdated => 1235685248, - }, - - 'receive inbox sms' => { - message => q|Receive Inbox message notifications via SMS?|, - context => q|Allows a user to choose how they get notified about things in their Inbox.|, - lastUpdated => 1235685248, - }, - - 'sms gateway' => { - message => q|SMS gateway|, - context => q|email to SMS/text email address for this site.|, - lastUpdated => 1235685248, - }, - - 'sms gateway help' => { - message => q|The email address that this site would use to send an SMS message.|, - lastUpdated => 1235695517, - }, - - 'send inbox notifications only' => { - message => q|Send only Inbox notifications|, - context => q|Site setting. A notification is a short message that something is in the Inbox.|, - lastUpdated => 1235685248, - }, - - 'send inbox notifications only help' => { - message => q|Should WebGUI just send notifications about Inbox messages, instead of the message itself?|, - lastUpdated => 1235696295, - }, - - 'inbox notification' => { - message => q|You have a new message in your Inbox.|, - lastUpdated => 1235708853, - }, - -}; - -1; -#vim:ft=perl diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index 5342c4957..61fcfef6b 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -4338,6 +4338,18 @@ Users may override this setting in their profile. 'recaptcha public key' => { message => 'reCAPTCHA Public Key' }, + + 'sms gateway' => { + message => q|SMS gateway|, + context => q|email to SMS/text email address for this site.|, + lastUpdated => 1235685248, + }, + + 'sms gateway help' => { + message => q|The email address that this site would use to send an SMS message.|, + lastUpdated => 1235695517, + }, + }; 1; From 18094751f315e000809a83a74e04ecf311f7ff25 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 13 Mar 2009 10:26:38 -0700 Subject: [PATCH 13/17] Remote notifications template from SMS branch. --- .../inbox_notification.wgpkg | Bin 777 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 sbin/message_center_packages/inbox_notification.wgpkg diff --git a/sbin/message_center_packages/inbox_notification.wgpkg b/sbin/message_center_packages/inbox_notification.wgpkg deleted file mode 100644 index 44e87644a2c36bf1da3171c648c85986912004f2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 777 zcmV+k1NQtMiwFP!00000|Ls&;Z`v>v=DEKj%2O+KZ43z%_QdEdRol^)w!3JnOk%(z z*pcmU>D2$eV-rZYbepsy?Eyc;Qtb2jobUV2IVfy?IgV5Dyh1_mW!LP;h25Gjr+^Uh zP`O-2$Sqh1IYp;nLCEG;A{7>pTEHX9`mev2NFwCx$GSLJrZ}_z=IZ}+WU@vp-=hA5 zN(VnAXaAfoK$W%Lu&>j<=y}WfyOp9>uz=0YuTANHu=&*A;)S0((1f;BT;MLTt(x`q z+rIe~3my}pD3SWFxu$Ohf?!3$4-@^@Mz*=E45hLOrTG9_qOeu>YVM5RG( zR6^y($3a*f-wxeQ!!KQ4p4Bs?L_`LhvNj(-F|KHb23S$fvO83s(=a4#IddwTf-9~j z@wDn(QC-24*bh%as!Wudp(!$mqZv`(eWr+D=0P0onk=k*7W-F3N|5cTLG;bN_Zbjn zJtC;O7tyKUgC-VmV>v~bcO(_vhSr3BU-_nEAj1tnW_gVV)1n?p`|RGY)#{qmTCFw9 zeo^&C53}yvGC8HRWv+M#tb!Sgor)!|;v7|-oUasB(eyQ6%V1rvl_BNyfs(0*Dp|@@ zYNl~JMae0E7 z?QQ+@t~16i2vK(T@&#P-pg$vUp{uAoCLNqaE83cNONlq|)oP_$^(w_&d4de71T!Dc z42Rax4?f00e{Pd3E7{{CpPh0snAV-+m4QEGjDu;x^&sF0Q-?;r!v((QJ|Qd+lUOy^ zyrXb8ZP&+1<1Pqqg4U5Q+za7-ikhRNn=B(L?3KA4cihv)`8$OlS~s>HrY}1$Z!xR47+VIm3~U*AO9p-c0S&6z H01f~E{6KnA From 987269f3c3d975b1d714e56718bbb8337b69d772 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 13 Mar 2009 10:27:48 -0700 Subject: [PATCH 14/17] Remove notification package code from SMS install script. --- sbin/installSms.pl | 51 ---------------------------------------------- 1 file changed, 51 deletions(-) diff --git a/sbin/installSms.pl b/sbin/installSms.pl index c95c41ff7..73f288a13 100644 --- a/sbin/installSms.pl +++ b/sbin/installSms.pl @@ -103,7 +103,6 @@ sub finish { # my $versionTag = WebGUI::VersionTag->getWorking($session); # $versionTag->commit; ## - updateTemplates($session); my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->commit; @@ -111,56 +110,6 @@ sub finish { $session->close; } -#------------------------------------------------- -sub updateTemplates { - my $session = shift; - my $packageDir = "message_center_packages"; - return undef unless (-d $packageDir); - print "\tUpdating packages.\n"; - opendir(DIR,$packageDir); - my @files = readdir(DIR); - closedir(DIR); - my $newFolder = undef; - foreach my $file (@files) { - next unless ($file =~ /\.wgpkg$/); - # Fix the filename to include a path - $file = $packageDir . "/" . $file; - addPackage( $session, $file ); - } -} - -sub addPackage { - my $session = shift; - my $file = shift; - - # Make a storage location for the package - my $storage = WebGUI::Storage->createTemp( $session ); - $storage->addFileFromFilesystem( $file ); - - # Import the package into the import node - my $package = WebGUI::Asset->getImportNode($session)->importPackage( $storage ); - - # Make the package not a package anymore - $package->update({ isPackage => 0 }); - - # Set the default flag for templates added - my $assetIds - = $package->getLineage( ['self','descendants'], { - includeOnlyClasses => [ 'WebGUI::Asset::Template' ], - } ); - for my $assetId ( @{ $assetIds } ) { - my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId ); - if ( !$asset ) { - print "Couldn't instantiate asset with ID '$assetId'. Please check package '$file' for corruption.\n"; - next; - } - $asset->update( { isDefault => 1 } ); - } - - return; -} - - __END__ From bc3b204d9bc64f94c95eee4aad8e4fd1941b47dd Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 16 Mar 2009 11:17:58 -0700 Subject: [PATCH 15/17] Add a method to return emails for Inbox notifications. Method is driven by profile data and settings. --- lib/WebGUI/User.pm | 28 +++++++++++++++++++++++++++ t/User.t | 47 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 6181c5d0c..364d9d5c5 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -503,6 +503,34 @@ sub getGroupIdsRecursive { #------------------------------------------------------------------- +=head2 getInboxAddresses ( ) + +Return a string with addresses that the user wants to receive Inbox +notifications. If the user does not want Inbox notifications, then +the string will be empty. + +=cut + +sub getInboxAddresses { + my $self = shift; + my $emails = ''; + if ( $self->profileField('receiveInboxEmailNotifications') + && $self->profileField('email')) { + $emails = $self->profileField('email'); + } + if ( $self->profileField('receiveInboxSmsNotifications') + && $self->profileField('cellPhone') + && $self->session->setting->get('smsGateway')) { + $emails .= ',' if $emails; + my $phoneNumber = $self->profileField('cellPhone'); + $phoneNumber =~ tr/0-9//dc; ##remove nonnumbers + $emails = join '', $emails, $phoneNumber, '@', $self->session->setting->get('smsGateway'); + } + return $emails; +} + +#------------------------------------------------------------------- + =head2 getProfileFieldPrivacySetting ( [field ]) Returns the privacy setting for the field passed in. If no field is passed in the entire hash is returned diff --git a/t/User.t b/t/User.t index 309f103a9..13f210fb5 100644 --- a/t/User.t +++ b/t/User.t @@ -20,7 +20,7 @@ use WebGUI::Cache; use WebGUI::User; use WebGUI::ProfileField; -use Test::More tests => 143; # increment this value for each test you create +use Test::More tests => 152; # increment this value for each test you create use Test::Deep; my $session = WebGUI::Test->session; @@ -620,7 +620,6 @@ cmp_bag( 'getGroupIdsRecursive returns the correct set of groups, ignoring expire date and not duplicating groups' ); - #---------------------------------------------------------------------------- # Test the new create() method SKIP: { @@ -637,9 +636,49 @@ ok( my $newCreateUser = WebGUI::User->create( $session ), ); isa_ok( $newCreateUser, 'WebGUI::User', 'create() returns a WebGUI::User' ); +################################################################ +# +# getInboxAddresses +# +################################################################ + +my $origSmsGateway = $session->setting->get('smsGateway'); +$session->setting->set('smsGateway', ''); +my $inmate = WebGUI::User->create($session); +$inmate->profileField('email', ''); +$inmate->profileField('cellPhone', ''); +$inmate->profileField('receiveInboxEmailNotifications', 0); +$inmate->profileField('receiveInboxSmsNotifications', 0); +is ($inmate->getInboxAddresses, '', 'getInboxAddresses: with no profile info, returns blank'); + +$inmate->profileField('receiveInboxEmailNotifications', 1); +is ($inmate->getInboxAddresses, '', 'getInboxAddresses: with receiveInboxEmailNotifications=1, but not email address, returns blank'); + +$inmate->profileField('email', 'andy@shawshank.com'); +is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: email address only'); + +$inmate->profileField('receiveInboxSmsNotifications', 1); +is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 but no other profile info'); + +$inmate->profileField('cellPhone', '37927'); +is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 and cell phone but no gateway'); + +$inmate->profileField('cellPhone', ''); +$session->setting->set('smsGateway', 'textme.com'); +is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 and gateway but no cell phone'); + +$inmate->profileField('cellPhone', '37927'); +is ($inmate->getInboxAddresses, 'andy@shawshank.com,37927@textme.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 and gateway but no cell phone'); + +$inmate->profileField('receiveInboxEmailNotifications', 0); +is ($inmate->getInboxAddresses, '37927@textme.com', 'getInboxAddresses: can get SMS and no email, even with email info present'); + +$inmate->profileField('receiveInboxSmsNotifications', 0); +is ($inmate->getInboxAddresses, '', 'getInboxAddresses: can get no SMS and no email, even with profile info present'); END { - foreach my $account ($user, $dude, $buster, $buster3, $neighbor, $friend, $newFish, $newCreateUser) { + foreach my $account ($user, $dude, $buster, $buster3, $neighbor, $friend, + $newFish, $newCreateUser, $inmate) { (defined $account and ref $account eq 'WebGUI::User') and $account->delete; } @@ -662,6 +701,8 @@ END { $newProfileField->delete(); + $session->setting->set('smsGateway', $origSmsGateway); + $testCache->flush; my $newNumberOfUsers = $session->db->quickScalar('select count(*) from users'); my $newNumberOfGroups = $session->db->quickScalar('select count(*) from groups'); From 7336d2d6306eae06d8f4d44580f18027a6a9287d Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 17 Mar 2009 14:35:13 -0700 Subject: [PATCH 16/17] SMS coding complete, beginning testing. Added getInboxAddresses method to User.pm, with tests. All SMS/Email address choices are made in Mail/Send, on create and on send, since that's when it handles groups. Test variable addresses on creating mails. Updated t/smtpd.pl to handle receiving and sending multiple messages. --- lib/WebGUI/Inbox/Message.pm | 11 +-- lib/WebGUI/Mail/Send.pm | 48 +++++++++---- sbin/installSms.pl | 8 ++- t/Mail/Send.t | 136 +++++++++++++++++++++++++++++------- t/User.t | 8 +-- t/smtpd.pl | 14 +++- 6 files changed, 174 insertions(+), 51 deletions(-) diff --git a/lib/WebGUI/Inbox/Message.pm b/lib/WebGUI/Inbox/Message.pm index 5fd779e27..036b06b2d 100644 --- a/lib/WebGUI/Inbox/Message.pm +++ b/lib/WebGUI/Inbox/Message.pm @@ -151,16 +151,17 @@ sub create { my $subject = (defined $properties->{emailSubject}) ? $properties->{emailSubject} : $self->{_properties}{subject}; my $mail = WebGUI::Mail::Send->create($session, { - toUser=>$self->{_properties}{userId}, - toGroup=>$self->{_properties}{groupId}, - subject=>$subject, - }); + toUser => $self->{_properties}{userId}, + toGroup => $self->{_properties}{groupId}, + subject => $subject, + }, + 'fromInbox', + ); if (defined $mail) { my $preface = ""; my $fromUser = WebGUI::User->new($session, $properties->{sentBy}); #Don't append prefaces to the visitor users or messages that don't specify a user (default case) unless ($fromUser->isVisitor || $fromUser->userId eq 3) { #Can't use isAdmin because it will not send prefaces from normal users who in the admin group - my $i18n = WebGUI::International->new($session, 'Inbox_Message'); $preface = sprintf($i18n->get('from user preface'), $fromUser->username); } my $msg = (defined $properties->{emailMessage}) ? $properties->{emailMessage} : $self->{_properties}{message}; diff --git a/lib/WebGUI/Mail/Send.pm b/lib/WebGUI/Mail/Send.pm index e7ad886ea..b6ec1933f 100644 --- a/lib/WebGUI/Mail/Send.pm +++ b/lib/WebGUI/Mail/Send.pm @@ -267,16 +267,28 @@ A unique id for this message, in case you want to see what replies come in for i If this is a reply to a previous message, then you should specify the messageId of the previous message here. +=head3 isInbox + +A flag indicating that this email message is from the Inbox, and should follow per user settings +for delivery. + =cut sub create { my $class = shift; my $session = shift; my $headers = shift; + my $isInbox = shift; if ($headers->{toUser}) { my $user = WebGUI::User->new($session, $headers->{toUser}); if (defined $user) { - my $email = $user->profileField("email"); + my $email; + if ($isInbox) { + $email = $user->getInboxAddresses; + } + else { + $email = $user->profileField("email"); + } if ($email) { if ($headers->{to}) { $headers->{to} .= ','.$email; @@ -286,9 +298,9 @@ sub create { } } } - my $from = $headers->{from} || $session->setting->get('comanyName') . " <".$session->setting->get("companyEmail").">"; + my $from = $headers->{from} || $session->setting->get('comanyName') . " <".$session->setting->get("companyEmail").">"; my $type = $headers->{contentType} || "multipart/mixed"; - my $replyTo = $headers->{replyTo} || $session->setting->get("mailReturnPath"); + my $replyTo = $headers->{replyTo} || $session->setting->get("mailReturnPath"); # format of Message-Id should be '' my $id = $headers->{messageId} || "WebGUI-" . $session->id->generate; @@ -324,7 +336,7 @@ sub create { delete $headers->{toGroup}; $message->attach(Data=>"This message was intended for ".$to." but was overridden in the config file.\n\n"); } - bless {_message=>$message, _session=>$session, _toGroup=>$headers->{toGroup} }, $class; + bless {_message=>$message, _session=>$session, _toGroup=>$headers->{toGroup}, _isInbox => $isInbox }, $class; } #------------------------------------------------------------------- @@ -467,10 +479,10 @@ sub send { else { my $smtp = Net::SMTP->new($smtpServer); # connect to an SMTP server if (defined $smtp) { - $smtp->mail($mail->head->get("X-Return-Path")); - $smtp->to(split(",",$mail->head->get("to"))); - $smtp->cc(split(",",$mail->head->get("cc"))); - $smtp->bcc(split(",",$mail->head->get("bcc"))); + $smtp->mail($mail->head->get('X-Return-Path')); + $smtp->to( split(',', $mail->head->get('to') )); + $smtp->cc( split(',', $mail->head->get('cc') )); + $smtp->bcc( split(',', $mail->head->get('bcc') )); $smtp->data(); # Start the mail $smtp->datasend($mail->stringify); $smtp->dataend(); # Finish sending the mail @@ -490,15 +502,21 @@ sub send { if ($group) { my $group = WebGUI::Group->new($self->session, $group); return $status if !defined $group; - $mail->head->replace("bcc", undef); - $mail->head->replace("cc", undef); - foreach my $userId (@{$group->getAllUsers(1)}) { + $mail->head->replace('bcc', undef); + $mail->head->replace('cc', undef); + USER: foreach my $userId (@{$group->getAllUsers(1)}) { my $user = WebGUI::User->new($self->session, $userId); - next unless $user->status eq 'Active'; ##Don't send this to invalid user accounts - if ($user->profileField("email")) { - $mail->head->replace("To",$user->profileField("email")); - $self->queue; + next USER unless $user->status eq 'Active'; ##Don't send this to invalid user accounts + my $emailAddress; + if ($self->{_isInbox}) { + $emailAddress = $user->getInboxAddresses; } + else { + $emailAddress = $user->profileField('email'); + } + next USER unless $emailAddress; + $mail->head->replace('To', $emailAddress); + $self->queue; } #Delete the group if it is flagged as an AdHocMailGroup $group->delete if ($group->isAdHocMailGroup); diff --git a/sbin/installSms.pl b/sbin/installSms.pl index 73f288a13..e6f796bbb 100644 --- a/sbin/installSms.pl +++ b/sbin/installSms.pl @@ -33,6 +33,7 @@ my $session = start( $webguiRoot, $configFile ); installUserProfileFields($session); installSettings($session); +upgradeMailQueue($session); # Do your work here finish($session); @@ -58,7 +59,7 @@ sub installUserProfileFields { ); WebGUI::ProfileField->create( $session, - 'receiveInboxSMSNotifications', + 'receiveInboxSmsNotifications', { label => q!WebGUI::International::get('receive inbox sms','Message_Center')!, visible => 1, @@ -77,6 +78,11 @@ sub installSettings { $session->setting->add('smsGateway', ''); } +sub upgradeMailQueue { + my $session = shift; + $session->db->write('alter table mailQueue add column isInbox TINYINT(4) default 0'); +} + #---------------------------------------------------------------------------- sub start { my $webguiRoot = shift; diff --git a/t/Mail/Send.t b/t/Mail/Send.t index 534650485..95ba5f06c 100644 --- a/t/Mail/Send.t +++ b/t/Mail/Send.t @@ -17,10 +17,13 @@ use strict; use lib "$FindBin::Bin/../lib"; use JSON qw( from_json to_json ); use Test::More; +use Test::Deep; use File::Spec; +use Data::Dumper; use WebGUI::Test; use WebGUI::Mail::Send; +use WebGUI::User; #---------------------------------------------------------------------------- # Init @@ -43,13 +46,17 @@ my $SMTP_PORT = '54921'; if ($hasServer) { $oldSettings{ smtpServer } = $session->setting->get('smtpServer'); $session->setting->set( 'smtpServer', $SMTP_HOST . ':' . $SMTP_PORT ); - + + my $smtpd = File::Spec->catfile( WebGUI::Test->root, 't', 'smtpd.pl' ); + open MAIL, "perl $smtpd $SMTP_HOST $SMTP_PORT 4 |" + or die "Could not open pipe to SMTPD: $!"; + sleep 1; # Give the smtpd time to establish itself } #---------------------------------------------------------------------------- # Tests -plan tests => 6; # Increment this number for each test you create +plan tests => 9; # Increment this number for each test you create #---------------------------------------------------------------------------- # Test create @@ -86,7 +93,7 @@ is( $mime->parts(0)->as_string =~ m/\n/, $newlines, #---------------------------------------------------------------------------- # Test addHtml $mail = WebGUI::Mail::Send->create( $session ); -my $text = <<'EOF'; +$text = <<'EOF'; Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse eu lacus ut ligula fringilla elementum. Cras condimentum, velit commodo pretium semper, odio ante accumsan orci, a ultrices risus justo a nulla. Aliquam erat volutpat. EOF @@ -97,7 +104,7 @@ $mime = $mail->getMimeEntity; # TODO: Test that addHtml creates a body with the right content type # addHtml should add newlines after 78 characters -my $newlines = length $text / 78; +$newlines = length $text / 78; is( $mime->parts(0)->as_string =~ m/\n/, $newlines, "addHtml should add newlines after 78 characters", ); @@ -107,7 +114,7 @@ is( $mime->parts(0)->as_string =~ m/\n/, $newlines, #---------------------------------------------------------------------------- # Test addHtmlRaw $mail = WebGUI::Mail::Send->create( $session ); -my $text = <<'EOF'; +$text = <<'EOF'; Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse eu lacus ut ligula fringilla elementum. Cras condimentum, velit commodo pretium semper, odio ante accumsan orci, a ultrices risus justo a nulla. Aliquam erat volutpat. EOF @@ -117,13 +124,15 @@ $mime = $mail->getMimeEntity; # TODO: Test that addHtmlRaw doesn't add an HTML wrapper # addHtmlRaw should add newlines after 78 characters -my $newlines = length $text / 78; +$newlines = length $text / 78; is( $mime->parts(0)->as_string =~ m/\n/, $newlines, "addHtmlRaw should add newlines after 78 characters", ); # TODO: Test that addHtml creates a body with the right content type +my $smtpServerOk = 0; + #---------------------------------------------------------------------------- # Test emailOverride SKIP: { @@ -138,23 +147,25 @@ SKIP: { if ( !$hasServer ) { skip "Cannot test emailOverride: Module Net::SMTP::Server not loaded!", $numtests; } - + + $smtpServerOk = 1; + # Override the emailOverride my $oldEmailOverride = $session->config->get('emailOverride'); $session->config->set( 'emailOverride', 'dufresne@localhost' ); my $oldEmailToLog = $session->config->get('emailToLog'); $session->config->set( 'emailToLog', 0 ); - + # Send the mail my $mail = WebGUI::Mail::Send->create( $session, { to => 'norton@localhost', } ); $mail->addText( 'His judgement cometh and that right soon.' ); - + my $received = sendToServer( $mail ); - - if (!$received) { + + if ($received->{error}) { skip "Cannot test emailOverride: No response received from smtpd", $numtests; } @@ -168,6 +179,79 @@ SKIP: { $session->config->set( 'emailToLog', $oldEmailToLog ); } +#---------------------------------------------------------------------------- +# +# Test sending an Inbox message to a user who has various notifications configured +# +#---------------------------------------------------------------------------- + +my $inboxUser = WebGUI::User->create($session); +$inboxUser->username('red'); +$inboxUser->profileField('receiveInboxEmailNotifications', 1); +$inboxUser->profileField('receiveInboxSmsNotifications', 0); +$inboxUser->profileField('email', 'ellis_boyd_redding@shawshank.gov'); +$inboxUser->profileField('cellPhone', '55555'); +$oldSettings{smsGateway} = $session->setting->get('smsGateway'); +$session->setting->set('smsGateway', 'textme.com'); + +SKIP: { + my $numtests = 1; # Number of tests in this block + + # Must be able to write the config, or we'll die + skip "Cannot test email notifications", $numtests unless $smtpServerOk; + + # Send the mail + $mail = WebGUI::Mail::Send->create( $session, { + toUser => $inboxUser->userId, + }, + 'fromInbox', + ); + $mail->addText( 'sent via email' ); + + my $received = sendToServer( $mail ) ; + + # Test the mail + is($received->{to}->[0], '', 'send, toUser with email address'); + + $inboxUser->profileField('receiveInboxEmailNotifications', 0); + $inboxUser->profileField('receiveInboxSmsNotifications', 1); + + # Send the mail + $mail = WebGUI::Mail::Send->create( $session, { + toUser => $inboxUser->userId, + }, + 'fromInbox', + ); + $mail->addText( 'sent via SMS' ); + + my $received = sendToServer( $mail ) ; + + # Test the mail + is($received->{to}->[0], '<55555@textme.com>', 'send, toUser with SMS address'); + + $inboxUser->profileField('receiveInboxEmailNotifications', 1); + $inboxUser->profileField('receiveInboxSmsNotifications', 1); + + # Send the mail + $mail = WebGUI::Mail::Send->create( $session, { + toUser => $inboxUser->userId, + }, + 'fromInbox', + ); + $mail->addText( 'sent via SMS' ); + + my $received = sendToServer( $mail ) ; + + # Test the mail + cmp_bag( + $received->{to}, + ['<55555@textme.com>', '',], + 'send, toUser with SMS and email addresses' + ); + + +} + # TODO: Test the emailToLog config setting @@ -177,6 +261,14 @@ END { for my $name ( keys %oldSettings ) { $session->setting->set( $name, $oldSettings{ $name } ); } + + if ($inboxUser) { + $inboxUser->delete; + } + + close MAIL + or die "Could not close pipe to SMTPD: $!"; + sleep 1; } #---------------------------------------------------------------------------- @@ -193,21 +285,17 @@ END { # by a MIME::Entity parser sub sendToServer { my $mail = shift; - - my $smtpd = File::Spec->catfile( WebGUI::Test->root, 't', 'smtpd.pl' ); - open MAIL, "perl $smtpd $SMTP_HOST $SMTP_PORT |" - or die "Could not open pipe to SMTPD: $!"; - sleep 1; # Give the smtpd time to establish itself - - $mail->send; + my $status = $mail->send; my $json; - while ( my $line = ) { - $json .= $line; + if ($status) { + $json = ; + } + else { + $json = ' { "error": "mail not sent" } '; + } + if (!$json) { + $json = ' { "error": "error in getting mail" } '; } - - close MAIL - or die "Could not close pipe to SMTPD: $!"; - return from_json( $json ); } diff --git a/t/User.t b/t/User.t index 13f210fb5..40ab7466f 100644 --- a/t/User.t +++ b/t/User.t @@ -658,17 +658,17 @@ $inmate->profileField('email', 'andy@shawshank.com'); is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: email address only'); $inmate->profileField('receiveInboxSmsNotifications', 1); -is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 but no other profile info'); +is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 but no other profile info'); $inmate->profileField('cellPhone', '37927'); -is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 and cell phone but no gateway'); +is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 and cell phone but no gateway'); $inmate->profileField('cellPhone', ''); $session->setting->set('smsGateway', 'textme.com'); -is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 and gateway but no cell phone'); +is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 and gateway but no cell phone'); $inmate->profileField('cellPhone', '37927'); -is ($inmate->getInboxAddresses, 'andy@shawshank.com,37927@textme.com', 'getInboxAddresses: receive only email address, with receiveInboSmsNotifications=1 and gateway but no cell phone'); +is ($inmate->getInboxAddresses, 'andy@shawshank.com,37927@textme.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 and gateway but no cell phone'); $inmate->profileField('receiveInboxEmailNotifications', 0); is ($inmate->getInboxAddresses, '37927@textme.com', 'getInboxAddresses: can get SMS and no email, even with email info present'); diff --git a/t/smtpd.pl b/t/smtpd.pl index 88ea75c3a..631f5750f 100644 --- a/t/smtpd.pl +++ b/t/smtpd.pl @@ -1,6 +1,7 @@ my $HOST = shift; my $PORT = shift; +my $EMAILS = shift || 1; die "HOST must be first argument" unless $HOST; @@ -13,17 +14,26 @@ use Net::SMTP::Server::Client; my $server = Net::SMTP::Server->new( $HOST, $PORT ); -while ( my $conn = $server->accept ) { +my $counter = 0; + +$| = 1; + +CONNECTION: while ( my $conn = $server->accept ) { my $client = Net::SMTP::Server::Client->new( $conn ); $client->process; print to_json({ to => $client->{TO}, from => $client->{FROM}, contents => $client->{MSG}, + counter => $counter, + emails => $EMAILS, }); - exit(0); + print "\n"; + last CONNECTION if ++$counter >= $EMAILS; } +sleep 3; +exit(0); =head1 NAME From 5248423519dc2ae19186957c1f499430ed419621 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 17 Mar 2009 16:11:37 -0700 Subject: [PATCH 17/17] Add tests for toGroup sending. --- t/Mail/Send.t | 65 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/t/Mail/Send.t b/t/Mail/Send.t index 95ba5f06c..1869bbf01 100644 --- a/t/Mail/Send.t +++ b/t/Mail/Send.t @@ -56,7 +56,7 @@ if ($hasServer) { #---------------------------------------------------------------------------- # Tests -plan tests => 9; # Increment this number for each test you create +plan tests => 13; # Increment this number for each test you create #---------------------------------------------------------------------------- # Test create @@ -194,6 +194,18 @@ $inboxUser->profileField('cellPhone', '55555'); $oldSettings{smsGateway} = $session->setting->get('smsGateway'); $session->setting->set('smsGateway', 'textme.com'); +my $emailUser = WebGUI::User->create($session); +$emailUser->username('heywood'); +$emailUser->profileField('email', 'heywood@shawshank.gov'); + +my $lonelyUser = WebGUI::User->create($session); +$lonelyUser->profileField('receiveInboxEmailNotifications', 0); +$lonelyUser->profileField('receiveInboxSmsNotifications', 0); +$lonelyUser->profileField('email', 'jake@shawshank.gov'); + +my $inboxGroup = WebGUI::Group->new($session, 'new'); +$inboxGroup->addUsers([$emailUser->userId, $inboxUser->userId, $lonelyUser->userId]); + SKIP: { my $numtests = 1; # Number of tests in this block @@ -249,9 +261,49 @@ SKIP: { 'send, toUser with SMS and email addresses' ); - } +#---------------------------------------------------------------------------- +# +# Test sending an Inbox message to a group with various user profile settings +# +#---------------------------------------------------------------------------- + +my @mailIds; +@mailIds = $session->db->buildArray('select messageId from mailQueue'); +my $startingMessages = scalar @mailIds; + +$mail = WebGUI::Mail::Send->create( $session, { + toGroup => $inboxGroup->getId, + }, + 'fromInbox', +); +$mail->addText('Mail::Send test message'); +@mailIds = $session->db->buildArray('select messageId from mailQueue'); +is(scalar @mailIds, $startingMessages, 'creating a message does not queue a message'); + +$mail->send; +@mailIds = $session->db->buildArray('select messageId from mailQueue'); +is(scalar @mailIds, $startingMessages+2, 'sending a message with a group added two messages'); + +@mailIds = $session->db->buildArray("select messageId from mailQueue where message like ?",['%Mail::Send test message%']); +is(scalar @mailIds, $startingMessages+2, 'sending a message with a group added the right two messages'); + +my @emailAddresses = (); +foreach my $mailId (@mailIds) { + my $mail = WebGUI::Mail::Send->retrieve($session, $mailId); + push @emailAddresses, $mail->getMimeEntity->head->get('to'); +} + +cmp_bag( + \@emailAddresses, + [ + 'heywood@shawshank.gov'."\n", + 'ellis_boyd_redding@shawshank.gov,55555@textme.com'."\n", + ], + 'send: when the original is sent, new messages are created for each user in the group, following their user profile settings' +); + # TODO: Test the emailToLog config setting @@ -262,13 +314,16 @@ END { $session->setting->set( $name, $oldSettings{ $name } ); } - if ($inboxUser) { - $inboxUser->delete; - } + $inboxUser->delete if $inboxUser; + $emailUser->delete if $emailUser; + $lonelyUser->delete if $lonelyUser; + $inboxGroup->delete if $inboxGroup; close MAIL or die "Could not close pipe to SMTPD: $!"; sleep 1; + + $session->db->write('delete from mailQueue'); } #----------------------------------------------------------------------------