workflow activity to notify admins of old version tags; start thread group in CS

This commit is contained in:
James Tolley 2007-07-09 20:02:09 +00:00
parent 6e0470771e
commit e1de42261d
8 changed files with 330 additions and 2 deletions

View file

@ -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;

View file

@ -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',

View file

@ -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;

View file

@ -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:</p>
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.|,

View file

@ -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.<p/>Please <a href="http://%s/?op=manageVersions">process them</a>.<p/>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;