From f2c26cd15ba2dce670fde93a16253f3b44f0460d Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 10 Mar 2009 12:16:27 -0700 Subject: [PATCH 1/6] Add topic README. --- COPY_SENDER_README | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 COPY_SENDER_README diff --git a/COPY_SENDER_README b/COPY_SENDER_README new file mode 100644 index 000000000..f9e82cc99 --- /dev/null +++ b/COPY_SENDER_README @@ -0,0 +1,2 @@ +This topic branch holds the RFE for copying the sender of an inbox message +with a copy of the message, for reference. From fc0312cb6dd5d91ec47c89b44e750f2b284e2175 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 10 Mar 2009 12:21:03 -0700 Subject: [PATCH 2/6] Install script for Copy Sender. --- sbin/installCopySender.pm | 125 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 sbin/installCopySender.pm diff --git a/sbin/installCopySender.pm b/sbin/installCopySender.pm new file mode 100644 index 000000000..0aa313e59 --- /dev/null +++ b/sbin/installCopySender.pm @@ -0,0 +1,125 @@ +#!/usr/bin/env perl + +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +$|++; # 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; + +# 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 ); +# Do your work here +finish($session); + +#---------------------------------------------------------------------------- +# Your sub here +sub installCopySender { + my $session = shift; + return if $session->setting->get('inboxCopySender'); +} + +#---------------------------------------------------------------------------- +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 + +Install the Copy Sender code on a WebGUI site. If the RFE for this is accepted, then +the subroutines should be moved into an upgrade script. + +=head1 SYNOPSIS + + installCopySender --configFile config.conf ... + + installCopySender --help + +=head1 DESCRIPTION + +This WebGUI utility script helps you install Copy Sender. + +=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-2009 SDH Consulting Pty, Ltd. + +=cut + +#vim:ft=perl From 09c5b4cb9e8060181cc5e975df7e34856d60f235 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 10 Mar 2009 13:24:12 -0700 Subject: [PATCH 3/6] Rename install file. Actually call the sub. --- sbin/{installCopySender.pm => installCopySender.pl} | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename sbin/{installCopySender.pm => installCopySender.pl} (95%) diff --git a/sbin/installCopySender.pm b/sbin/installCopySender.pl similarity index 95% rename from sbin/installCopySender.pm rename to sbin/installCopySender.pl index 0aa313e59..88c1d813f 100644 --- a/sbin/installCopySender.pm +++ b/sbin/installCopySender.pl @@ -36,13 +36,15 @@ pod2usage( msg => "Must specify a config file!" ) unless $configFile; my $session = start( $webguiRoot, $configFile ); # Do your work here +installCopySender($session); finish($session); #---------------------------------------------------------------------------- # Your sub here sub installCopySender { my $session = shift; - return if $session->setting->get('inboxCopySender'); + return if $session->setting->has('inboxCopySender'); + $session->setting->add('inboxCopySender',0); } #---------------------------------------------------------------------------- From 0695e4f4fce61274c549128182ba1e58716a8eed Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 10 Mar 2009 13:28:00 -0700 Subject: [PATCH 4/6] Add a has method to settings, with tests. has checks to see if the setting exists in the object's cache. It's safer than poking inside the object's hash. It should mainly be used for developers who run the same script over and over again. --- lib/WebGUI/Session/Setting.pm | 24 ++++++++++++++++++++++++ t/Session/Setting.t | 6 +++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Session/Setting.pm b/lib/WebGUI/Session/Setting.pm index ffb6054c6..06d12d601 100644 --- a/lib/WebGUI/Session/Setting.pm +++ b/lib/WebGUI/Session/Setting.pm @@ -100,6 +100,30 @@ sub get { } +#------------------------------------------------------------------- + +=head2 has ( $param ) + +Returns true if the requested setting exists in this object's cache of the settings. +This works better than using ->get, since it doesn't care about the truthiness of +the value of the setting. + +This method will have little use outside of upgrade and install scripts, to prevent +them from creating and/or overwriting existing settings. + +=head3 $param + +The setting to check. + +=cut + +sub has { + my $self = shift; + my $param = shift; + return exists $self->{_settings}{$param}; +} + + #------------------------------------------------------------------- =head2 new ( session ) diff --git a/t/Session/Setting.t b/t/Session/Setting.t index 29a6a657e..f83a9c4ab 100644 --- a/t/Session/Setting.t +++ b/t/Session/Setting.t @@ -15,7 +15,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 6; # increment this value for each test you create +use Test::More tests => 9; # increment this value for each test you create my $session = WebGUI::Test->session; @@ -27,6 +27,10 @@ $session->setting->set("inmate","37927"); my ($value) = $session->db->quickArray("select value from settings where name='inmate'"); is($value, '37927', "set()"); is($session->setting->get("inmate"), '37927', 'set() also updates object cache'); +is($session->setting->has('inmate'), 1, 'has checks for existance'); +$session->setting->set('inmate', 0); +is($session->setting->get('inmate'), 0, 'get will get 0 values'); +is($session->setting->has('inmate'), 1, 'has checks for existance, regardless of value'); $session->setting->remove("inmate"); my ($value) = $session->db->quickArray("select value from settings where name='inmate'"); is($value, undef, "delete()"); From 51021e5974b891358f87f7d4d454a32564a5a006 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 10 Mar 2009 13:59:00 -0700 Subject: [PATCH 5/6] Inbox Copy sender code, settings and i18n. --- lib/WebGUI/Account/Inbox.pm | 54 +++++++++++++++--------- lib/WebGUI/i18n/English/Account_Inbox.pm | 11 +++++ 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/lib/WebGUI/Account/Inbox.pm b/lib/WebGUI/Account/Inbox.pm index 57d6b5af1..8f61620b6 100644 --- a/lib/WebGUI/Account/Inbox.pm +++ b/lib/WebGUI/Account/Inbox.pm @@ -223,7 +223,13 @@ sub editSettingsForm { label => $i18n->get("inbox rich editor label"), hoverHelp => $i18n->get("inbox rich editor description"), ); - + $f->yesNo( + name => "inboxCopySender", + value => $setting->get("inboxCopySender"), + label => $i18n->get("inbox copy sender label"), + hoverHelp => $i18n->get("inbox copy sender hoverHelp") + ); + return $f->printRowsOnly; } @@ -242,28 +248,29 @@ sub editSettingsFormSave { my $form = $session->form; #Messages Settings - $setting->set("inboxStyleTemplateId", $form->process("inboxStyleTemplateId","template")); - $setting->set("inboxLayoutTemplateId", $form->process("inboxLayoutTemplateId","template")); - $setting->set("inboxViewTemplateId", $form->process("inboxViewTemplateId","template")); - $setting->set("inboxViewMessageTemplateId",$form->process("inboxViewMessageTemplateId","template")); - $setting->set("inboxSendMessageTemplateId",$form->process("inboxSendMessageTemplateId","template")); + $setting->set("inboxStyleTemplateId", $form->process("inboxStyleTemplateId", "template")); + $setting->set("inboxLayoutTemplateId", $form->process("inboxLayoutTemplateId", "template")); + $setting->set("inboxViewTemplateId", $form->process("inboxViewTemplateId", "template")); + $setting->set("inboxViewMessageTemplateId", $form->process("inboxViewMessageTemplateId", "template")); + $setting->set("inboxSendMessageTemplateId", $form->process("inboxSendMessageTemplateId", "template")); $setting->set("inboxMessageConfirmationTemplateId",$form->process("inboxMessageConfirmationTemplateId","template")); - $setting->set("inboxErrorTemplateId",$form->process("inboxErrorTemplateId","template")); + $setting->set("inboxErrorTemplateId", $form->process("inboxErrorTemplateId", "template")); #Friends Invitations Settings - $setting->set("inboxManageInvitationsTemplateId",$form->process("inboxManageInvitationsTemplateId","template")); - $setting->set("inboxViewInvitationTemplateId",$form->process("inboxViewInvitationTemplateId","template")); - $setting->set("inboxInvitationConfirmTemplateId",$form->process("inboxInvitationConfirmTemplateId","template")); + $setting->set("inboxManageInvitationsTemplateId", $form->process("inboxManageInvitationsTemplateId", "template")); + $setting->set("inboxViewInvitationTemplateId", $form->process("inboxViewInvitationTemplateId", "template")); + $setting->set("inboxInvitationConfirmTemplateId", $form->process("inboxInvitationConfirmTemplateId", "template")); #User Invitation Settings - $setting->set("inboxInviteUserEnabled",$form->process("inboxInviteUserEnabled","yesNo")); - $setting->set("inboxInviteUserRestrictSubject",$form->process("inboxInviteUserRestrictSubject","yesNo")); - $setting->set("inboxInviteUserSubject",$form->process("inboxInviteUserSubject","text")); - $setting->set("inboxInviteUserRestrictMessage",$form->process("inboxInviteUserRestrictMessage","yesNo")); - $setting->set("inboxInviteUserMessage",$form->process("inboxInviteUserMessage","HTMLArea")); - $setting->set("inboxInviteUserMessageTemplateId",$form->process("inboxInviteUserMessageTemplateId","template")); - $setting->set("inboxInviteUserTemplateId",$form->process("inboxInviteUserTemplateId","template")); - $setting->set("inboxInviteUserConfirmTemplateId",$form->process("inboxInviteUserConfirmTemplateId","template")); - - $setting->set("inboxRichEditorId", $form->process("inboxRichEditorId", "selectRichEditor") ); + $setting->set("inboxInviteUserEnabled", $form->process("inboxInviteUserEnabled", "yesNo")); + $setting->set("inboxInviteUserRestrictSubject", $form->process("inboxInviteUserRestrictSubject", "yesNo")); + $setting->set("inboxInviteUserSubject", $form->process("inboxInviteUserSubject", "text")); + $setting->set("inboxInviteUserRestrictMessage", $form->process("inboxInviteUserRestrictMessage", "yesNo")); + $setting->set("inboxInviteUserMessage", $form->process("inboxInviteUserMessage", "HTMLArea")); + $setting->set("inboxInviteUserMessageTemplateId", $form->process("inboxInviteUserMessageTemplateId", "template")); + $setting->set("inboxInviteUserTemplateId", $form->process("inboxInviteUserTemplateId", "template")); + $setting->set("inboxInviteUserConfirmTemplateId", $form->process("inboxInviteUserConfirmTemplateId", "template")); + #General Inbox Settings + $setting->set("inboxRichEditorId", $form->process("inboxRichEditorId", "selectRichEditor") ); + $setting->set("inboxCopySender", $form->process("inboxCopySender", "yesNo")); } @@ -913,8 +920,9 @@ sub www_sendMessage { #Add any error passed in to be displayed if the form reloads $var->{'message_display_error'} = $displayError; - #Add common template variable for displaying the inbox my $inbox = WebGUI::Inbox->new($session); + + #Add common template variable for displaying the inbox $self->appendCommonVars($var,$inbox); my $messageId = $form->get("messageId"); @@ -1131,6 +1139,10 @@ sub www_sendMessageSave { } } + if($session->setting->get('inboxCopySender')) { + push @toUsers, $session->user->userId; + } + #Check for client errors if($subject eq "") { my $i18n = WebGUI::International->new($session,'Account_Inbox'); diff --git a/lib/WebGUI/i18n/English/Account_Inbox.pm b/lib/WebGUI/i18n/English/Account_Inbox.pm index 142cafaeb..343f317b4 100644 --- a/lib/WebGUI/i18n/English/Account_Inbox.pm +++ b/lib/WebGUI/i18n/English/Account_Inbox.pm @@ -721,6 +721,17 @@ our $I18N = { context => "template variable for view inbox template", }, + 'inbox copy sender label' => { + message => q|Copy Sender on Messages?|, + context => q|Copy, as in receive a copy. Label for Account/Inbox settings|, + lastUpdated => 0, + }, + + 'inbox copy sender hoverHelp' => { + message => q|If this setting is 'yes', users will receive a copy of messages that they send using the inbox.|, + lastUpdated => 0, + }, + }; 1; From 07266bc25d6ef1904eb159596f94179b52b32e59 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 10 Mar 2009 17:24:14 -0700 Subject: [PATCH 6/6] Mark the message copied to me as read. --- lib/WebGUI/Account/Inbox.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Account/Inbox.pm b/lib/WebGUI/Account/Inbox.pm index 8f61620b6..74554a2f6 100644 --- a/lib/WebGUI/Account/Inbox.pm +++ b/lib/WebGUI/Account/Inbox.pm @@ -1164,13 +1164,16 @@ sub www_sendMessageSave { return $self->www_sendMessage($errorMsg) if $hasError; foreach my $uid (@toUsers) { - $inbox->addMessage({ + my $message = $inbox->addMessage({ message => $message, subject => $subject, userId => $uid, status => 'unread', sentBy => $fromUser->userId }); + if ($uid eq $session->user->userId) { + $message->setRead; + } } $self->appendCommonVars($var,$inbox);