From e1de42261d9f7746ba5e20e799adb49fc3c89cb2 Mon Sep 17 00:00:00 2001
From: James Tolley
Date: Mon, 9 Jul 2007 20:02:09 +0000
Subject: [PATCH] workflow activity to notify admins of old version tags; start
thread group in CS
---
.../PBtmpl0000000000000026.tmpl | 82 +++++++++++
docs/upgrades/upgrade_7.3.19-7.4.0.pl | 17 +++
etc/WebGUI.conf.original | 2 +-
lib/WebGUI/Asset/Wobject/Collaboration.pm | 33 ++++-
lib/WebGUI/Help/Asset_Collaboration.pm | 10 ++
.../NotifyAdminsWithOpenVersionTags.pm | 128 ++++++++++++++++++
.../i18n/English/Asset_Collaboration.pm | 20 +++
...ctivity_NotifyAdminsWithOpenVersionTags.pm | 40 ++++++
8 files changed, 330 insertions(+), 2 deletions(-)
create mode 100644 docs/upgrades/templates-7.4.0/PBtmpl0000000000000026.tmpl
create mode 100644 lib/WebGUI/Workflow/Activity/NotifyAdminsWithOpenVersionTags.pm
create mode 100644 lib/WebGUI/i18n/English/Workflow_Activity_NotifyAdminsWithOpenVersionTags.pm
diff --git a/docs/upgrades/templates-7.4.0/PBtmpl0000000000000026.tmpl b/docs/upgrades/templates-7.4.0/PBtmpl0000000000000026.tmpl
new file mode 100644
index 000000000..171755f70
--- /dev/null
+++ b/docs/upgrades/templates-7.4.0/PBtmpl0000000000000026.tmpl
@@ -0,0 +1,82 @@
+#PBtmpl0000000000000026
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+ |
+ |
+ |
+ |
+ |
+ |
+
+ |
+
+
+
+
+
+ |
+
+ |
+
+ |
+
+ |
+
+ |
+ |
+ |
+ @ |
+
+
+
+ by
+
+
+
+
+
+ on @
+ |
+
+
+
+
+
+
+
+
diff --git a/docs/upgrades/upgrade_7.3.19-7.4.0.pl b/docs/upgrades/upgrade_7.3.19-7.4.0.pl
index eb88ac5a0..b6d5fab6c 100644
--- a/docs/upgrades/upgrade_7.3.19-7.4.0.pl
+++ b/docs/upgrades/upgrade_7.3.19-7.4.0.pl
@@ -31,9 +31,26 @@ addUserInvitations($session);
addPrivateMessaging($session);
addNewsletter($session);
addHttpProxyUrlPatternFilter($session);
+addCanStartThreadToCS($session);
finish($session); # this line required
+#-------------------------------------------------
+
+sub addCanStartThreadToCS {
+ my $session = shift;
+
+ # add the columns required
+ $session->db->write("ALTER TABLE Collaboration add column canStartThreadGroupId varchar(22) NOT NULL default 2 AFTER postGroupId");
+ $session->db->write("ALTER TABLE Collaboration add column threadApprovalWorkflow varchar(22) NOT NULL default 'pbworkflow000000000003' AFTER approvalWorkflow");
+
+ # set defaults for existing records
+ $session->db->write('UPDATE Collaboration SET canStartThreadGroupId = postGroupId');
+ $session->db->write('UPDATE Collaboration SET threadApprovalWorkflow = approvalWorkflow');
+
+ return;
+}
+
#-------------------------------------------------
sub addKeywordTagging {
my $session = shift;
diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original
index 362ae4c08..3b4f264b2 100644
--- a/etc/WebGUI.conf.original
+++ b/etc/WebGUI.conf.original
@@ -412,7 +412,7 @@
"WebGUI::Workflow::Activity::GetSyndicatedContent", "WebGUI::Workflow::Activity::ProcessRecurringPayments",
"WebGUI::Workflow::Activity::SyncProfilesToLdap", "WebGUI::Workflow::Activity::SummarizePassiveProfileLog",
"WebGUI::Workflow::Activity::SendQueuedMailMessages","WebGUI::Workflow::Activity::CleanDatabaseCache",
- "WebGUI::Workflow::Activity::CalendarUpdateFeeds"],
+ "WebGUI::Workflow::Activity::CalendarUpdateFeeds","WebGUI::Workflow::Activity::NotifyAdminsWithOpenVersionTags"],
"WebGUI::User" : ["WebGUI::Workflow::Activity::CreateCronJob", "WebGUI::Workflow::Activity::NotifyAboutUser"],
"WebGUI::VersionTag" : ["WebGUI::Workflow::Activity::CommitVersionTag", "WebGUI::Workflow::Activity::RollbackVersionTag",
"WebGUI::Workflow::Activity::TrashVersionTag", "WebGUI::Workflow::Activity::CreateCronJob",
diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm
index 27461cf1e..593a5d539 100644
--- a/lib/WebGUI/Asset/Wobject/Collaboration.pm
+++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm
@@ -289,6 +289,21 @@ sub canSubscribe {
return ($self->session->user->userId ne "1" && $self->canView);
}
+#-------------------------------------------------------------------
+sub canStartThread {
+ my $self = shift;
+ return (
+ (
+ $self->get("status") eq "approved" ||
+ $self->getTagCount > 1 # checks to make sure that the cs has been committed at least once
+ ) && (
+ $self->session->user->isInGroup($self->get("canStartThreadGroupId"))
+ || $self->SUPER::canEdit
+ )
+ );
+}
+
+
#-------------------------------------------------------------------
sub canView {
my $self = shift;
@@ -393,6 +408,14 @@ sub definition {
label=>$i18n->get('approval workflow'),
hoverHelp=>$i18n->get('approval workflow description'),
},
+ threadApprovalWorkflow =>{
+ fieldType=>"workflow",
+ defaultValue=>"pbworkflow000000000003",
+ type=>'WebGUI::VersionTag',
+ tab=>'security',
+ label=>$i18n->get('thread approval workflow'),
+ hoverHelp=>$i18n->get('thread approval workflow description'),
+ },
thumbnailSize => {
fieldType => "integer",
defaultValue => 0,
@@ -683,6 +706,13 @@ sub definition {
label=>$i18n->get('who posts'),
hoverHelp=>$i18n->get('who posts description'),
},
+ canStartThreadGroupId =>{
+ fieldType=>"group",
+ defaultValue=>'2',
+ tab=>'security',
+ label=>$i18n->get('who threads'),
+ hoverHelp=>$i18n->get('who threads description'),
+ },
defaultKarmaScale => {
fieldType=>"integer",
defaultValue=>1,
@@ -904,6 +934,7 @@ sub getViewTemplateVars {
$sortOrder ||= "desc";
my %var;
$var{'user.canPost'} = $self->canPost;
+ $var{'user.canStartThread'} = $self->canStartThread;
$var{"add.url"} = $self->getNewThreadUrl;
$var{"rss.url"} = $self->getRssUrl;
$var{'user.isModerator'} = $self->canModerate;
@@ -1039,7 +1070,7 @@ See WebGUI::Asset::prepareView() for details.
sub prepareView {
my $self = shift;
$self->SUPER::prepareView();
- my $template = WebGUI::Asset::Template->new($self->session, $self->get("collaborationTemplateId"));
+ my $template = WebGUI::Asset::Template->new($self->session, $self->get("collaborationTemplateId")) or die "no good: ".$self->get("collaborationTemplateId");
$self->session->style->setLink($self->getRssUrl,{ rel=>'alternate', type=>'application/rss+xml', title=>'RSS' });
$template->prepare;
$self->{_viewTemplate} = $template;
diff --git a/lib/WebGUI/Help/Asset_Collaboration.pm b/lib/WebGUI/Help/Asset_Collaboration.pm
index 7e1274147..7fb0432e2 100644
--- a/lib/WebGUI/Help/Asset_Collaboration.pm
+++ b/lib/WebGUI/Help/Asset_Collaboration.pm
@@ -61,11 +61,21 @@ our $HELP = {
description => 'who posts description',
namespace => 'Asset_Collaboration',
},
+ {
+ title => 'who threads',
+ description => 'who threads description',
+ namespace => 'Asset_Collaboration',
+ },
{
title => 'approval workflow',
description => 'approval workflow description',
namespace => 'Asset_Collaboration',
},
+ {
+ title => 'thread approval workflow',
+ description => 'thread approval workflow description',
+ namespace => 'Asset_Collaboration',
+ },
{
title => 'threads/page',
description => 'threads/page description',
diff --git a/lib/WebGUI/Workflow/Activity/NotifyAdminsWithOpenVersionTags.pm b/lib/WebGUI/Workflow/Activity/NotifyAdminsWithOpenVersionTags.pm
new file mode 100644
index 000000000..f4389a7ab
--- /dev/null
+++ b/lib/WebGUI/Workflow/Activity/NotifyAdminsWithOpenVersionTags.pm
@@ -0,0 +1,128 @@
+package WebGUI::Workflow::Activity::NotifyAdminsWithOpenVersionTags;
+
+
+=head1 LEGAL
+
+ -------------------------------------------------------------------
+ WebGUI is Copyright 2001-2006 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
+ -------------------------------------------------------------------
+
+=cut
+
+use strict;
+use base 'WebGUI::Workflow::Activity';
+
+use WebGUI::Mail::Send;
+
+=head1 NAME
+
+Package WebGUI::Workflow::Activity::NotifyAdminsWithOpenVersionTags
+
+=head1 DESCRIPTION
+
+This sends out notifications to all users that have an uncommitted tag. It only does this if the version tags are empty. It takes an arg which specifies the length of time a tag should be outstanding before sending the notification. The default is 3 days.
+
+=head1 SYNOPSIS
+
+See WebGUI::Workflow::Activity for details on how to use any activity.
+
+=head1 METHODS
+
+These methods are available from this class:
+
+=cut
+
+
+#-------------------------------------------------------------------
+
+=head2 definition ( session, definition )
+
+See WebGUI::Workflow::Activity::defintion() for details.
+
+=cut
+
+sub definition {
+ my $class = shift;
+ my $session = shift;
+ my $definition = shift;
+ my $i18n = WebGUI::International->new($session, "Workflow_Activity_NotifyAdminsWithOpenVersionTags");
+ push(@{$definition}, {
+ name => $i18n->get('activityName'),
+ properties => {
+ daysLeftOpen => {
+ fieldType => 'integer',
+ label => $i18n->get('days left open label'),
+ defaultValue => 3,
+ hoverHelp => $i18n->get('days left open hoverhelp'),
+ },
+ }
+ });
+
+ return $class->SUPER::definition($session,$definition);
+}
+
+
+#-------------------------------------------------------------------
+
+=head2 execute ( [ object ] )
+
+See WebGUI::Workflow::Activity::execute() for details.
+
+=cut
+
+sub execute {
+ my $self = shift;
+
+ my $i18n = WebGUI::International->new($self->session, "Workflow_Activity_NotifyAdminsWithOpenVersionTags");
+
+ my $daysLeftOpen = $self->get('daysLeftOpen') + 0;
+ my $sql = <<"ENDSQL";
+ SELECT email, count(distinct(tagId)) AS count
+ FROM assetVersionTag
+ JOIN assetData USING (tagId)
+ JOIN userProfileData ON assetVersionTag.createdBy = userProfileData.userId
+ WHERE isCommitted = 0
+ AND DATE_ADD(FROM_UNIXTIME(creationDate), INTERVAL $daysLeftOpen DAY) < NOW()
+ GROUP BY userId
+ENDSQL
+
+ my $dataArrayRef = $self->session->db->buildArrayRefOfHashRefs($sql);
+
+ for my $userHashRef (@$dataArrayRef) {
+ $self->_notify($userHashRef, $i18n);
+ }
+
+ return $self->COMPLETE;
+}
+
+# send an email to an admin about their open version tags
+sub _notify {
+ my $self = shift;
+ my $dataHashRef = shift;
+ my $i18n = shift;
+
+ my $hostname = $self->session->config->get('sitename')->[0];
+ my($from) = $self->session->db->quickScalar(" SELECT email FROM userProfileData WHERE userId = 3 ");
+
+ my $s = $dataHashRef->{count} > 1 ? 's' : '';
+ my $subject = sprintf($i18n->get('email subject'), $s, $hostname);
+ my $mail = WebGUI::Mail::Send->create($self->session, {
+ from => $from,
+ to => $dataHashRef->{email},
+ subject => $subject,
+ });
+
+ my $html = sprintf $i18n->get('email message'), $dataHashRef->{count}, $s, $hostname, $hostname;
+ $mail->addHtml($html);
+ $mail->send();
+}
+
+1;
+
+
diff --git a/lib/WebGUI/i18n/English/Asset_Collaboration.pm b/lib/WebGUI/i18n/English/Asset_Collaboration.pm
index f0cd24e9e..5ea3bb52c 100644
--- a/lib/WebGUI/i18n/English/Asset_Collaboration.pm
+++ b/lib/WebGUI/i18n/English/Asset_Collaboration.pm
@@ -645,6 +645,11 @@ our $I18N = {
lastUpdated => 1109698614,
},
+ 'who threads' => {
+ message => q|Who can post a thread?|,
+ lastUpdated => 1109698614,
+ },
+
'threads/page' => {
message => q|Threads Per Page|,
lastUpdated => 1109698614,
@@ -1106,11 +1111,26 @@ properties listed below:
lastUpdated => 0,
},
+ 'thread approval workflow description' => {
+ message => q|Choose a workflow to be executed on each thread as it gets submitted.|,
+ lastUpdated => 0,
+ },
+
+ 'thread approval workflow' => {
+ message => q|Thread Approval Workflow|,
+ lastUpdated => 0,
+ },
+
'who posts description' => {
message => q|The group allowed to submit posts to this Asset.|,
lastUpdated => 1119070429,
},
+ 'who threads description' => {
+ message => q|The group allowed to start a thread in this Asset.|,
+ lastUpdated => 1119070429,
+ },
+
'threads/page description' => {
message => q|The number of threads displayed on each page in the system template.
Setting this number very high can slow the generation of the page.|,
diff --git a/lib/WebGUI/i18n/English/Workflow_Activity_NotifyAdminsWithOpenVersionTags.pm b/lib/WebGUI/i18n/English/Workflow_Activity_NotifyAdminsWithOpenVersionTags.pm
new file mode 100644
index 000000000..b596b8940
--- /dev/null
+++ b/lib/WebGUI/i18n/English/Workflow_Activity_NotifyAdminsWithOpenVersionTags.pm
@@ -0,0 +1,40 @@
+package WebGUI::i18n::English::Workflow_Activity_NotifyAdminsWithOpenVersionTags; ##Be sure to change the package name to match the filename
+
+our $I18N = { ##hashref of hashes
+ 'days left open label' => {
+ message => q|Days Left Open|,
+ lastUpdated => 0,
+ context => q||,
+ },
+
+ 'days left open hoverhelp' => {
+ message => q|The number of days a version tag needs to be left open before a notification is sent to its user.|,
+ lastUpdated => 0,
+ context => q||,
+ },
+
+ 'email subject' => {
+ message => q|Uncommitted version tag%s on %s|,
+ lastUpdated => 0,
+ context => q||,
+ },
+
+ 'email message' => {
+ message => q|You have %d uncommitted version tag%s on %s.Please process them.Thank you.|,
+ lastUpdated => 0,
+ context => q||,
+ },
+
+ #If the help file documents an Asset, it must include an assetName key
+ #If the help file documents an Macro, it must include an macroName key
+ #If the help file documents a Workflow Activity, it must include an activityName key
+ #If the help file documents a Template Parser, it must include an templateParserName key
+ #For all other types, use topicName
+ 'activityName' => {
+ message => q|Notify Admins of Old Version Tags|,
+ lastUpdated => 1131394072,
+ },
+
+};
+
+1;