Merge commit 'v7.10.21' into WebGUI8. Also, add POD and fix broken tests.
This commit is contained in:
commit
4855816a29
72 changed files with 1357 additions and 82 deletions
|
|
@ -1126,10 +1126,12 @@ sub getEditForm {
|
|||
|
||||
###
|
||||
# Properties
|
||||
my $overrides = $session->config->get("assets/".$self->className) || {};
|
||||
foreach my $property ( $self->getProperties ) {
|
||||
my $fieldHash = $self->getFieldData( $property );
|
||||
next if $fieldHash->{noFormPost};
|
||||
|
||||
$fieldHash = $self->setupFormField($property, $fieldHash, $overrides);
|
||||
# Create tabs to have labels added later
|
||||
if ( !$f->getTab( $fieldHash->{tab} ) ) {
|
||||
$f->addTab( name => $fieldHash->{tab}, label => $fieldHash->{tab} );
|
||||
|
|
@ -1167,22 +1169,37 @@ sub getEditForm {
|
|||
return $f;
|
||||
} ## end sub getEditForm
|
||||
|
||||
=head2 setupFormField ( $fieldName, $fieldHash, $overrides )
|
||||
|
||||
Applies overrides from the WebGUI config file to a set of field data. The overridden
|
||||
and updated field data is returned.
|
||||
|
||||
=head3 $fieldName
|
||||
|
||||
The name of the field.
|
||||
|
||||
=head3 $fieldHash
|
||||
|
||||
A hash reference of field data for $fieldName.
|
||||
|
||||
=head3 $overrides
|
||||
|
||||
A hash reference of overrides from the config file. This is passed in instead of
|
||||
looking it up each time as a speed optimization.
|
||||
|
||||
=cut
|
||||
|
||||
sub setupFormField {
|
||||
my ( $self, $tabform, $fieldName, $extraFields, $overrides ) = @_;
|
||||
my %params = %{ $extraFields->{$fieldName} };
|
||||
my $tab = delete $params{tab};
|
||||
my ( $self, $fieldName, $fieldHash, $overrides ) = @_;
|
||||
|
||||
if ( exists $overrides->{fields}{$fieldName} ) {
|
||||
my %overrideParams = %{ $overrides->{fields}{$fieldName} };
|
||||
my $overrideTab = delete $overrideParams{tab};
|
||||
$tab = $overrideTab if defined $overrideTab;
|
||||
foreach my $key ( keys %overrideParams ) {
|
||||
$params{"-$key"} = $overrideParams{$key};
|
||||
}
|
||||
return $fieldHash unless exists $overrides->{fields}->{$fieldName};
|
||||
my %overrideParams = %{ $overrides->{fields}->{$fieldName} };
|
||||
foreach my $key ( keys %overrideParams ) {
|
||||
(my $canon = $key) =~ s/^-//;
|
||||
$fieldHash->{$canon} = $overrideParams{$key};
|
||||
}
|
||||
return $fieldHash;
|
||||
|
||||
$tab ||= 'properties';
|
||||
return $tabform->getTab($tab)->addField( delete $params{fieldType}, %params);
|
||||
} ## end sub setupFormField
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1289,6 +1289,7 @@ sub getTemplateVars {
|
|||
url => $storage->getUrl($filename),
|
||||
icon => $storage->getFileIconUrl($filename),
|
||||
filename => $filename,
|
||||
extension => WebGUI::Storage->getFileExtension($filename),
|
||||
thumbnail => $storage->getThumbnailUrl($filename),
|
||||
isImage => $storage->isImage($filename),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -622,6 +622,7 @@ sub view {
|
|||
$var{fileUrl} = $self->getFileUrl;
|
||||
$var{fileIcon} = $self->getFileIconUrl;
|
||||
$var{fileSize} = Number::Format::format_bytes($self->get("assetSize"));
|
||||
$var{extension} = WebGUI::Storage->getFileExtension( $self->get("filename"));
|
||||
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
|
||||
if (!$self->session->isAdminOn && $self->get("cacheTimeout") > 10) {
|
||||
$self->session->cache->set($self->getViewCacheKey, $out, $self->get("cacheTimeout"));
|
||||
|
|
|
|||
|
|
@ -1092,6 +1092,7 @@ sub getTemplateVars {
|
|||
url => $fileUrl,
|
||||
icon => $storage->getFileIconUrl($filename),
|
||||
filename => $filename,
|
||||
extension => WebGUI::Storage->getFileExtension($filename),
|
||||
thumbnail => $isImage ? $storage->getThumbnailUrl($filename) : '',
|
||||
isImage => $isImage,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -340,6 +340,7 @@ sub view {
|
|||
}
|
||||
push(@{$var{attachment_loop}}, {
|
||||
filename => $file,
|
||||
extension => WebGUI::Storage->getFileExtension($file),
|
||||
isImage => $storage->isImage($file),
|
||||
url=> $storage->getUrl($file),
|
||||
thumbnailUrl => $storage->getThumbnailUrl($file),
|
||||
|
|
|
|||
|
|
@ -296,6 +296,7 @@ sub view {
|
|||
"icon.small" => $child->getIcon(1),
|
||||
"icon.big" => $child->getIcon,
|
||||
type => $child->getName,
|
||||
extension => WebGUI::Storage->getFileExtension( $child->get("filename")),
|
||||
url => $child->getUrl,
|
||||
canEdit => $child->canEdit,
|
||||
controls => $child->getToolbar,
|
||||
|
|
|
|||
|
|
@ -635,6 +635,10 @@ sub editThingDataSave {
|
|||
if ($self->field_isa($fieldType, 'WebGUI::Form::File')) {
|
||||
$field->{ defaultValue } = $thingData{ "field_" . $field->{ fieldId } };
|
||||
}
|
||||
elsif ($fieldType eq 'Date' or $fieldType eq 'DateTime') { ##Must be in epoch format to be stored in the db.
|
||||
my $wdt = WebGUI::DateTime->new($session, $field->{defaultValue})->cloneToUserTimeZone;
|
||||
$field->{defaultValue} = $wdt->epoch;
|
||||
}
|
||||
$fieldValue = $thingData->{$fieldName} || $session->form->process($fieldName,$fieldType,$field->{defaultValue},$field);
|
||||
}
|
||||
if ($field->{status} eq "required" && ($fieldValue =~ /^\s$/x || $fieldValue eq "" || !(defined $fieldValue))) {
|
||||
|
|
@ -1042,12 +1046,12 @@ sub getFieldValue {
|
|||
|
||||
my $fieldType = lc $field->{fieldType};
|
||||
if ($fieldType eq "date"){
|
||||
my $dt = WebGUI::DateTime->new($session, $value);
|
||||
$processedValue = $dt->webguiDate($dateFormat);
|
||||
my $wdt = WebGUI::DateTime->new($session, $value);
|
||||
$processedValue = $wdt->cloneToUserTimeZone->webguiDate($dateFormat);
|
||||
}
|
||||
elsif ($fieldType eq "datetime"){
|
||||
my $dt = WebGUI::DateTime->new($session, $value);
|
||||
$processedValue = $dt->webguiDate($dateTimeFormat);
|
||||
my $wdt = WebGUI::DateTime->new($session, $value);
|
||||
$processedValue = $wdt->cloneToUserTimeZone->webguiDate($dateTimeFormat);
|
||||
}
|
||||
# TODO: The otherThing field type is probably also handled by getFormPlugin, so the elsif below can probably be
|
||||
# safely removed. However, this requires more testing than I can provide right now, so for now this stays the
|
||||
|
|
@ -3069,7 +3073,6 @@ sub www_exportThing {
|
|||
|
||||
### Loop through the returned structure and put it through Text::CSV
|
||||
# Column heads
|
||||
$self->session->log->warn("field labels: ". join ' ', @fieldLabels);
|
||||
my $csv_filename = 'export_'.$thingProperties->{label}.'.csv';
|
||||
open my $CSV, '>', $tempStorage->getPath($csv_filename);
|
||||
print $CSV WebGUI::Text::joinCSV( @fieldLabels );
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use WebGUI::User;
|
|||
use WebGUI::Form::Captcha;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::Deprecate;
|
||||
use Scope::Guard qw(guard);
|
||||
use Encode ();
|
||||
use Tie::IxHash;
|
||||
|
||||
|
|
@ -679,12 +680,28 @@ sub www_createAccountSave {
|
|||
$properties->{ identifier } = $self->hashPassword($password);
|
||||
$properties->{ passwordLastUpdated } = time();
|
||||
$properties->{ passwordTimeout } = $setting->get("webguiPasswordTimeout");
|
||||
$properties->{ status } = 'Deactivated' if ($setting->get("webguiValidateEmail"));
|
||||
|
||||
my $afterCreateMessage = $self->SUPER::createAccountSave($username,$properties,$password,$profile);
|
||||
|
||||
my $sendEmail = $setting->get('webguiValidateEmail');
|
||||
|
||||
# We need to deactivate the user and log him out if there are additional
|
||||
# things that need to be done before he should be logged in.
|
||||
my $cleanupUser;
|
||||
if ($sendEmail || !$setting->get('enableUsersAfterAnonymousRegistration')) {
|
||||
$cleanupUser = guard {
|
||||
$self->user->status('Deactivated');
|
||||
$session->var->end($session->var->get('sessionId'));
|
||||
$session->var->start(1, $session->getId);
|
||||
my $u = WebGUI::User->new($session, 1);
|
||||
$self->{user} = $u;
|
||||
$self->logout;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
# Send validation e-mail if required
|
||||
if ($setting->get("webguiValidateEmail")) {
|
||||
if ($sendEmail) {
|
||||
my $key = $session->id->generate;
|
||||
$self->update(emailValidationKey=>$key);
|
||||
my $mail = WebGUI::Mail::Send->create($self->session, {
|
||||
|
|
@ -700,12 +717,6 @@ WebGUI::Asset::Template->newById($self->session,$self->getSetting('accountActiva
|
|||
$mail->addText($text);
|
||||
$mail->addFooter;
|
||||
$mail->queue;
|
||||
$self->user->status("Deactivated");
|
||||
$session->end();
|
||||
$session->start(1, $session->getId);
|
||||
my $u = WebGUI::User->new($session, 1);
|
||||
$self->{user} = $u;
|
||||
$self->logout;
|
||||
return $self->www_displayLogin($i18n->get('check email for validation','AuthWebGUI'));
|
||||
}
|
||||
return $afterCreateMessage;
|
||||
|
|
|
|||
145
lib/WebGUI/Content/PDFGenerator.pm
Normal file
145
lib/WebGUI/Content/PDFGenerator.pm
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
package WebGUI::Content::PDFGenerator;
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use List::Util qw(first);
|
||||
use Scope::Guard qw(guard);
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Content::Asset;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
WebGUI::Content::PDFGenerator
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Generates a PDF of the requested URL when op=generatePdf.
|
||||
|
||||
=head1 PREREQUISITES
|
||||
|
||||
This handler depends on wkpdftohtml, which does not ship with WebGUI and is,
|
||||
as of this writing, still in active development. This handler was written for
|
||||
version 0.9.9. It is available from http://code.google.com/p/wkhtmltopdf/.
|
||||
Compiling is rather difficult, but static binaries are available for the most
|
||||
popular platforms.
|
||||
|
||||
=head1 INSTALLATION
|
||||
|
||||
Enable this content handler in your WebGUI config file, placing it somewhere
|
||||
before WebGUI::Content::Operation, and add a pdfGen section to your config
|
||||
file at the top level. This must contain the path to your wkhtmltopdf
|
||||
executable, a cache timeout (how many seconds to cache the pdf), and
|
||||
optionally the userId of a user to view the page as (defaults to Visitor). It
|
||||
can also contain additional command line arguments to pass to wkhtmltopdf.
|
||||
|
||||
"pdfGen" : {
|
||||
"exe" : "/usr/local/bin/wkhtmltopdf",
|
||||
"args" : "--orientation Landscape",
|
||||
"userId" : "_f7d61hs6djh0fjnxqw21",
|
||||
"cacheTimeout" : 3600 # 1 hour cache timeout
|
||||
},
|
||||
"contentHandlers" : [
|
||||
#...
|
||||
"WebGUI::Content::PDFGenerator",
|
||||
#...
|
||||
"WebGUI::Content::Operation",
|
||||
#...
|
||||
"WebGUI::Content::NotFound"
|
||||
],
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# Return the cached pdf, generating if necessary.
|
||||
|
||||
=head2 cache ($asset)
|
||||
|
||||
Returns the cached PDF for an asset, if necessary
|
||||
|
||||
=cut
|
||||
|
||||
sub cache {
|
||||
my $asset = shift;
|
||||
my $session = $asset->session;
|
||||
my $key = join '', 'PDFGen', $session->url->getRequestedUrl, $asset->get('revisionDate');
|
||||
my $cache = $session->cache();
|
||||
my $content = $cache->get($key);
|
||||
unless ($content) {
|
||||
$content = generate($asset);
|
||||
$cache->set($key, $content, $session->config->get('pdfGen/cacheTimeout'));
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# Generate the pdf unconditionally and return it as a string.
|
||||
|
||||
=head2 generate ($asset)
|
||||
|
||||
Generate the pdf unconditionally and return it as a string.
|
||||
|
||||
=cut
|
||||
|
||||
sub generate {
|
||||
my $asset = shift;
|
||||
my $session = $asset->session;
|
||||
my $url = $session->url;
|
||||
my $c = $session->config;
|
||||
my $o = $c->get('pdfGen');
|
||||
my $login = WebGUI::Session->open($c->getWebguiRoot, $c->getFilename);
|
||||
my $guard = guard { $login->var->end; $login->close };
|
||||
$login->user({ userId => $o->{userId} || 1 });
|
||||
my @args = (
|
||||
$o->{exe}, @{$o->{args} || []},
|
||||
'--cookie', $c->get('cookieName'), $login->getId,
|
||||
$url->getSiteURL . $url->gateway($url->getRequestedUrl),
|
||||
'-'
|
||||
);
|
||||
|
||||
# We're using backticks because trying to run external programs from a
|
||||
# mod_perl process is extremely tricky any other way, but TODO: figure out
|
||||
# use a real call and pass an array of args, as that would be safer.
|
||||
my $cmd = join ' ', @args;
|
||||
`$cmd`;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 cache ($asset)
|
||||
|
||||
Figure out which asset we need to check permissions for
|
||||
|
||||
=cut
|
||||
|
||||
sub getRequestedAsset {
|
||||
my $session = shift;
|
||||
my $assetUrl = $session->url->getRequestedUrl;
|
||||
my $perms = WebGUI::Content::Asset::getUrlPermutations($assetUrl);
|
||||
foreach my $url (@$perms) {
|
||||
if (my $asset = WebGUI::Content::Asset::getAsset($session, $url)) {
|
||||
return $asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# Top-level handler.
|
||||
|
||||
=head2 handler ($session)
|
||||
|
||||
Top-level handler
|
||||
|
||||
=cut
|
||||
|
||||
sub handler {
|
||||
my $session = shift;
|
||||
my $op = $session->form->get('op');
|
||||
return undef unless $op && $op eq 'generatePdf';
|
||||
my $asset = getRequestedAsset($session);
|
||||
return $session->privilege->noAccess unless $asset->canView;
|
||||
$session->http->setMimeType('application/pdf');
|
||||
return cache($asset);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -300,6 +300,7 @@ sub www_upload {
|
|||
title => $filename,
|
||||
url => "attachments/".$filename,
|
||||
filename => $filename,
|
||||
extension => WebGUI::Storage->getFileExtension($filename),
|
||||
ownerUserId => $owner,
|
||||
groupIdEdit => "3",
|
||||
groupIdView => "7",
|
||||
|
|
|
|||
|
|
@ -383,6 +383,7 @@ sub prepare {
|
|||
$style->setCss( $url->extras( 'yui/build/button/assets/skins/sam/button.css'));
|
||||
$style->setCss( $url->extras( 'yui/build/calendar/assets/skins/sam/calendar.css'));
|
||||
$style->setCss( $url->extras('yui/build/container/assets/skins/sam/container.css'));
|
||||
$style->setCss( $url->extras('yui-webgui/build/form/datatable.css'));
|
||||
$style->setScript( $url->extras('yui/build/container/container-min.js') );
|
||||
$style->setScript( $url->extras('yui/build/button/button-min.js') );
|
||||
$style->setScript( $url->extras('yui/build/calendar/calendar-min.js') );
|
||||
|
|
|
|||
|
|
@ -137,9 +137,9 @@ Send JS required for this plugin.
|
|||
sub headTags {
|
||||
my $self = shift;
|
||||
my ( $url, $style ) = $self->session->quick(qw( url style ));
|
||||
$style->setScript( $url->extras('yui/build/connection/connection-min.js') );
|
||||
$style->setScript( $url->extras('yui/build/yahoo-dom-event/yahoo-dom-event.js'));
|
||||
$style->setScript( $url->extras('yui/build/json/json-min.js'));
|
||||
$style->setScript( $url->extras('yui/build/connect/connect-min.js') );
|
||||
$style->setScript( $url->extras('yui-webgui/build/i18n/i18n.js') );
|
||||
$style->setScript( $url->extras('yui-webgui/build/form/jsontable.js'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,6 +201,7 @@ sub getOperations {
|
|||
'ajaxDeleteUser' => 'User',
|
||||
'ajaxUpdateUser' => 'User',
|
||||
'becomeUser' => 'User',
|
||||
'confirmUserEmail' => 'User',
|
||||
'deleteUser' => 'User',
|
||||
'editUser' => 'User',
|
||||
'editUserSave' => 'User',
|
||||
|
|
|
|||
|
|
@ -399,6 +399,15 @@ sub definition {
|
|||
hoverHelp=>$i18n->get('118 description'),
|
||||
defaultValue=>$setting->get("anonymousRegistration")
|
||||
});
|
||||
push(@fields, {
|
||||
tab => 'user',
|
||||
fieldType => 'yesNo',
|
||||
name => 'enableUsersAfterAnonymousRegistration',
|
||||
label => $i18n->get('Enable Users after Anonymous Registration?'),
|
||||
hoverHelp => $i18n->get('enableUsersAfterAnonymousRegistration help'),
|
||||
defaultValue => $setting->get('enableUsersAfterAnonymousRegistration')
|
||||
}
|
||||
);
|
||||
push(@fields, {
|
||||
tab=>"user",
|
||||
fieldType=>"yesNo",
|
||||
|
|
|
|||
|
|
@ -415,6 +415,38 @@ sub www_ajaxCreateUser {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_confirmUserEmail ( )
|
||||
|
||||
Process links clicked from mails sent out by the WaitForUserConfmration
|
||||
workflow activity.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_confirmUserEmail {
|
||||
my $session = shift;
|
||||
my $f = $session->form;
|
||||
my $instanceId = $f->get('instanceId');
|
||||
my $token = $f->get('token');
|
||||
my $actId = $f->get('activityId');
|
||||
my $activity = WebGUI::Workflow::Activity->new($session, $actId)
|
||||
or die;
|
||||
my $instance = WebGUI::Workflow::Instance->new($session, $instanceId)
|
||||
or die;
|
||||
if ($activity->confirm($instance, $token)) {
|
||||
my $msg = $activity->get('okMessage');
|
||||
unless ($msg) {
|
||||
my $i18n = WebGUI::International->new($session, 'WebGUI');
|
||||
$msg = $i18n->get('ok');
|
||||
}
|
||||
return $session->style->userStyle($msg);
|
||||
}
|
||||
else {
|
||||
return $session->privilege->noAccess;
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_ajaxDeleteUser ( )
|
||||
|
||||
Delete a user using a web service.
|
||||
|
|
|
|||
|
|
@ -19,6 +19,14 @@ Package WebGUI::Test::MockAsset
|
|||
=head1 DESCRIPTION
|
||||
|
||||
Creates fake WebGUI::Asset objects and sets them up to be returned by WebGUI::Asset's normal constructors.
|
||||
Most of the time, you'll be mocking templates to read which variables are sent to their
|
||||
templates. Here's how to do that:
|
||||
|
||||
my $mockAsset = WebGUI::Test::MockAsset->new('WebGUI::Asset::Template');
|
||||
$mockAsset->mock_id($template_id_to_mock);
|
||||
my $templateVars;
|
||||
$templateMock->mock('process', sub { $templateVars = $_[1]; } );
|
||||
$templateMock->set_true('prepare', sub { } );
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,29 @@ These methods are available from this class:
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 changeWorkflow ( $workflowId, $instance, $skipDelete )
|
||||
|
||||
Kicks a new workflow in a new instance with the same object the current
|
||||
instance has, deleting the old instance unless you say otherwise.
|
||||
|
||||
=cut
|
||||
|
||||
sub changeWorkflow {
|
||||
my ($self, $workflowId, $instance, $skipDelete) = @_;
|
||||
WebGUI::Workflow::Instance->create(
|
||||
$self->session, {
|
||||
workflowId => $workflowId,
|
||||
methodName => $instance->get('methodName'),
|
||||
className => $instance->get('className'),
|
||||
parameters => $instance->get('parameters'),
|
||||
priority => $instance->get('priority'),
|
||||
}
|
||||
)->start(1);
|
||||
$instance->delete() unless $skipDelete;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 cleanup ( )
|
||||
|
||||
Override this activity to add a cleanup routine to be run if an instance
|
||||
|
|
|
|||
270
lib/WebGUI/Workflow/Activity/WaitForUserConfirmation.pm
Normal file
270
lib/WebGUI/Workflow/Activity/WaitForUserConfirmation.pm
Normal file
|
|
@ -0,0 +1,270 @@
|
|||
package WebGUI::Workflow::Activity::WaitForUserConfirmation;
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use base 'WebGUI::Workflow::Activity';
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Inbox::Message;
|
||||
use WebGUI::Macro;
|
||||
use Kwargs;
|
||||
use Tie::IxHash;
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 confirm ( $instance, $token )
|
||||
|
||||
Returns true (and sets the workflow as done) if the token matches the one we
|
||||
generated for the email.
|
||||
|
||||
=cut
|
||||
|
||||
sub confirm {
|
||||
my ($self, $instance, $token) = @_;
|
||||
my $id = $self->getId;
|
||||
return 0 unless $token eq $instance->getScratch("$id-token");
|
||||
$instance->setScratch("$id-status", 'done');
|
||||
return 1;
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 definition ( )
|
||||
|
||||
See WebGUI::Workflow::Activity::definition for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my ($class, $session, $def) = @_;
|
||||
my $i18n = WebGUI::International->new(
|
||||
$session, 'Activity_WaitForUserConfirmation'
|
||||
);
|
||||
|
||||
tie my %props, 'Tie::IxHash', (
|
||||
emailFrom => {
|
||||
fieldType => 'user',
|
||||
defaultValue => 3,
|
||||
},
|
||||
emailSubject => {
|
||||
fieldType => 'text',
|
||||
defaultValue => 'Confirmation Email',
|
||||
},
|
||||
template => {
|
||||
fieldType => 'textarea',
|
||||
defaultValue => $i18n->get('your template goes here'),
|
||||
},
|
||||
templateParser => {
|
||||
fieldType => 'templateParser',
|
||||
defaultValue => $session->config->get('defaultTemplateParser'),
|
||||
},
|
||||
okMessage => {
|
||||
fieldType => 'HTMLArea',
|
||||
},
|
||||
waitBetween => {
|
||||
fieldType => 'interval',
|
||||
defaultValue => 60*5
|
||||
},
|
||||
expireAfter => {
|
||||
fieldType => 'interval',
|
||||
defaultValue => 60*60*24*7,
|
||||
},
|
||||
doOnExpire => {
|
||||
fieldType => 'workflow',
|
||||
type => 'WebGUI::User',
|
||||
none => 1,
|
||||
}
|
||||
);
|
||||
|
||||
for my $key (keys %props) {
|
||||
$props{$key}{label} = $i18n->get("$key label");
|
||||
$props{$key}{hoverHelp} = $i18n->get("$key hoverHelp");
|
||||
}
|
||||
|
||||
push @$def, {
|
||||
name => $i18n->get('topicName'),
|
||||
properties => \%props,
|
||||
};
|
||||
|
||||
return $class->SUPER::definition( $session, $def );
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 execute ( )
|
||||
|
||||
See WebGUI::Workflow::Activity::execute for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub execute {
|
||||
my ($self, $object, $instance) = @_;
|
||||
my $id = $self->getId;
|
||||
my $statk = "$id-status";
|
||||
my $start = "$id-started";
|
||||
my $status = $instance->getScratch($statk);
|
||||
my $subject = $self->get('emailSubject');
|
||||
my $parser = $self->get('templateParser');
|
||||
WebGUI::Macro::process(\$subject);
|
||||
my $body = WebGUI::Asset::Template->processRaw(
|
||||
$self->session,
|
||||
$self->get('template'),
|
||||
$self->getTemplateVariables($object, $instance),
|
||||
$parser,
|
||||
);
|
||||
WebGUI::Macro::process(\$body);
|
||||
unless ($status) {
|
||||
$instance->setScratch($start => $self->now);
|
||||
$self->sendEmail(
|
||||
from => $self->get('emailFrom'),
|
||||
to => $object->userId,
|
||||
subject => $subject,
|
||||
body => $body,
|
||||
);
|
||||
$instance->setScratch($statk => 'waiting');
|
||||
return $self->wait;
|
||||
}
|
||||
return $self->COMPLETE if $status eq 'done' || $status eq 'expired';
|
||||
if ($status eq 'waiting') {
|
||||
my $end = $instance->getScratch($start) + $self->get('expireAfter');
|
||||
if ($self->now > $end) {
|
||||
$self->expire($instance);
|
||||
$instance->setScratch($statk => 'expired');
|
||||
return $self->COMPLETE;
|
||||
}
|
||||
return $self->wait;
|
||||
}
|
||||
$self->session->log->error("Unknown status: $status");
|
||||
return $self->ERROR;
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 expire ( $instance )
|
||||
|
||||
Deletes the workflow instance and kicks off a configured workflow if there is
|
||||
one.
|
||||
|
||||
=cut
|
||||
|
||||
sub expire {
|
||||
my ($self, $instance) = @_;
|
||||
if (my $id = $self->get('doOnExpire')) {
|
||||
$self->changeWorkflow($id, $instance);
|
||||
}
|
||||
else {
|
||||
$instance->delete();
|
||||
}
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 getTemplateVariables ( $object, $instance )
|
||||
|
||||
Returns the variables to be used in rendering the email template.
|
||||
|
||||
=cut
|
||||
|
||||
sub getTemplateVariables {
|
||||
my ($self, $object, $instance) = @_;
|
||||
|
||||
my $user = $object->get;
|
||||
|
||||
# Kill all humans. I means references. Currently there seems to be a bug
|
||||
# in _rewriteVars in some of the template plugins that disallows us from
|
||||
# using arrayrefs with just strings in them, which is a common occurrence
|
||||
# in profile fields. When that bug gets fixed, we can (and should) take
|
||||
# this out.
|
||||
delete @{$user}{grep {ref $user->{$_} } keys %$user};
|
||||
|
||||
return {
|
||||
user => $user,
|
||||
link => $self->link($instance),
|
||||
}
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 link ( $instance )
|
||||
|
||||
Returns the URL that needs to be visited by the user.
|
||||
|
||||
=cut
|
||||
|
||||
sub link {
|
||||
my ($self, $instance) = @_;
|
||||
my $url = $self->session->url;
|
||||
my $aid = $self->getId;
|
||||
my $iid = $instance->getId;
|
||||
my $token = $instance->getScratch("$aid-token");
|
||||
$instance->setScratch("$aid-token", $token = $self->token) unless $token;
|
||||
my $path = $url->page(
|
||||
"op=confirmUserEmail;instanceId=$iid;token=$token;activityId=$aid"
|
||||
);
|
||||
return $url->getSiteURL . $url->gateway($path);
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 now ( )
|
||||
|
||||
Just returns the current time, nice for testing.
|
||||
|
||||
=cut
|
||||
|
||||
sub now { time }
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 sendEmail ( { from, to, subject, body } )
|
||||
|
||||
Takes a user to send email from, to, with a subject and a body all as
|
||||
keywords. Mostly here for testing, it just calls
|
||||
WebGUI::Inbox::Message->create() with proper arguments. 'from' and 'to' are
|
||||
userIds, not user objects.
|
||||
|
||||
=cut
|
||||
|
||||
sub sendEmail {
|
||||
my ($self, $from, $to, $subject, $body) = kwn @_, 1,
|
||||
qw(from to subject body);
|
||||
|
||||
WebGUI::Inbox::Message->create(
|
||||
$self->session, {
|
||||
message => $body,
|
||||
subject => $subject,
|
||||
status => 'pending',
|
||||
userId => $to,
|
||||
sentBy => $from,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 token ( )
|
||||
|
||||
Returns a random string to use as a token in the confirmation link
|
||||
|
||||
=cut
|
||||
|
||||
sub token {
|
||||
my $self = shift;
|
||||
$self->session->id->generate;
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 wait ( )
|
||||
|
||||
Waits for the configured waitBetween interval.
|
||||
|
||||
=cut
|
||||
|
||||
sub wait {
|
||||
my $self = shift;
|
||||
return $self->WAITING($self->get('waitBetween'));
|
||||
}
|
||||
|
||||
1;
|
||||
74
lib/WebGUI/i18n/English/Activity_WaitForUserConfirmation.pm
Normal file
74
lib/WebGUI/i18n/English/Activity_WaitForUserConfirmation.pm
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
package WebGUI::i18n::English::Activity_WaitForUserConfirmation;
|
||||
|
||||
use strict;
|
||||
|
||||
our $I18N = {
|
||||
'doOnExpire hoverHelp' => {
|
||||
message => q{Workflow to run after the waiting period has expired.},
|
||||
lastUpdated => 1311365415,
|
||||
},
|
||||
'doOnExpire label' => {
|
||||
message => q{Do On Expire},
|
||||
lastUpdated => 1311365395,
|
||||
},
|
||||
'emailFrom hoverHelp' => {
|
||||
message => q{Which user should the confirmation email be from?},
|
||||
lastUpdated => 1311363981,
|
||||
},
|
||||
'emailFrom label' => {
|
||||
message => q{Email From},
|
||||
lastUpdated => 1311363958,
|
||||
},
|
||||
'emailSubject label' => {
|
||||
message => q{Email Subject},
|
||||
lastUpdated => 1311363994,
|
||||
},
|
||||
'expireAfter hoverHelp' => {
|
||||
message => q{How long should we wait for the user to respond?},
|
||||
lastUpdated => 1311363900,
|
||||
},
|
||||
'expireAfter label' => {
|
||||
message => q{Expire After},
|
||||
lastUpdated => 1311363885,
|
||||
},
|
||||
'okMessage label' => {
|
||||
message => q{Confirmation Message},
|
||||
lastUpdated => 1311612584,
|
||||
},
|
||||
'okMessage hoverHelp' => {
|
||||
message => q{Message to display to the user when he clicks the confirm link},
|
||||
lastUpdated => 1311612632,
|
||||
},
|
||||
'template hoverHelp' => {
|
||||
message => q{Raw template code for the body of the email goes here.},
|
||||
lastUpdated => 1311364201,
|
||||
},
|
||||
'template label' => {
|
||||
message => q{Template},
|
||||
lastUpdated => 1311364181,
|
||||
},
|
||||
'templateParser label' => {
|
||||
message => q{Template Parser},
|
||||
lastUpdated => 1311364015,
|
||||
},
|
||||
'topicName' => {
|
||||
message => q{Wait For User Confirmation},
|
||||
lastUpdated => 1311364913,
|
||||
},
|
||||
'waitBetween hoverHelp' => {
|
||||
message => q{How long should we wait in between checks to see if the user has clicked the link?},
|
||||
lastUpdated => 1311363934,
|
||||
},
|
||||
'waitBetween label' => {
|
||||
message => q{Wait Interval},
|
||||
lastUpdated => 1311363920,
|
||||
},
|
||||
'your template goes here' => {
|
||||
message => q{Your template goes here!},
|
||||
lastUpdated => 1311365274,
|
||||
},
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
#vim:ft=perl
|
||||
|
|
@ -74,6 +74,18 @@ our $I18N = {
|
|||
context => q{Format for a column with a date},
|
||||
},
|
||||
|
||||
"format textarea" => {
|
||||
message => q{Textarea},
|
||||
lastUpdated => 0,
|
||||
context => q{Format for a textarea column},
|
||||
},
|
||||
|
||||
"format htmlarea" => {
|
||||
message => q{HTMLarea},
|
||||
lastUpdated => 0,
|
||||
context => q{Format for an HTMLarea column},
|
||||
},
|
||||
|
||||
"add column" => {
|
||||
message => q{Add Column},
|
||||
lastUpdated => 0,
|
||||
|
|
@ -152,6 +164,23 @@ our $I18N = {
|
|||
context => q{The name of a newly added value to a column},
|
||||
},
|
||||
|
||||
"data error" => {
|
||||
message => q{Data error.},
|
||||
lastUpdated => 0,
|
||||
context => q{Message to display when DataTable has data error},
|
||||
},
|
||||
|
||||
"sort ascending" => {
|
||||
message => q{Click to sort ascending},
|
||||
lastUpdated => 0,
|
||||
context => q{Message to display in tooltip to sort Column in ascending order},
|
||||
},
|
||||
|
||||
"sort descending" => {
|
||||
message => q{Click to sort descending},
|
||||
lastUpdated => 0,
|
||||
context => q{Message to display in tooltip to sort Column in descending order},
|
||||
},
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -4776,6 +4776,18 @@ Users may override this setting in their profile.
|
|||
context => 'Choose, as in to select from a set of options',
|
||||
},
|
||||
|
||||
'Enable Users after Anonymous Registration?' => {
|
||||
message => 'Enable Users after Anonymous Registration?',
|
||||
lastUpdated => 1311618346,
|
||||
},
|
||||
|
||||
'enableUsersAfterAnonymousRegistration help' => {
|
||||
message => 'If this is off, '
|
||||
. 'users must be manually activated by a workflow or an admin.',
|
||||
lastUpdated => 1311618419,
|
||||
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue