- added: Inbox is now pruned after 1 year

- Added about a hundred tests for Collaboration system, Post, and Thread 
permissions
- Cleaned up code tested by the aforementioned tests
- Fixed all Test::WWW::Mechanize tests and updated the skeleton. Should be 
usable now.
This commit is contained in:
Doug Bell 2008-04-26 02:23:10 +00:00
parent ea1dac4064
commit 98992b8920
16 changed files with 742 additions and 120 deletions

View file

@ -92,13 +92,36 @@ sub canAdd {
#-------------------------------------------------------------------
sub canEdit {
my $self = shift;
return (($self->session->form->process("func") eq "add" || ($self->session->form->process("assetId") eq "new" && $self->session->form->process("func") eq "editSave" && $self->session->form->process("class","className") eq "WebGUI::Asset::Post")) && $self->getThread->getParent->canPost) || # account for new posts
my $self = shift;
my $userId = shift || $self->session->user->userId;
my $session = $self->session;
my $form = $self->session->form;
my $user = WebGUI::User->new( $session, $userId );
($self->isPoster && $self->getThread->getParent->get("editTimeout") > ($self->session->datetime->time() - $self->get("revisionDate"))) ||
$self->session->user->isInGroup($self->getThread->getParent->get('groupToEditPost')) ||
$self->getThread->getParent->canEdit;
# Handle adding new posts
if (
( $form->get("func") eq "add"
|| ( $form->get("func") eq "editSave" && $form->get("assetId") eq "new" )
)
&& $form->get("class") eq "WebGUI::Asset::Post"
) {
return $self->getThread->getParent->canPost;
}
# User who posted can edit their own post
if ( $self->isPoster( $userId ) ) {
my $editTimeout = $self->getThread->getParent->get( 'editTimeout' );
if ( $editTimeout > time - $self->get( "revisionDate" ) ) {
return 1;
}
}
# Users in groupToEditPost of the Collab can edit any post
if ( $user->isInGroup( $self->getThread->getParent->get('groupToEditPost') ) ) {
return 1;
}
return $self->getThread->getParent->canEdit( $userId );
}
#-------------------------------------------------------------------
@ -690,15 +713,16 @@ sub isNew {
#-------------------------------------------------------------------
=head2 isPoster ( )
=head2 isPoster ( userId )
Returns a boolean that is true if the current user created this post and is not a visitor.
=cut
sub isPoster {
my $self = shift;
return ($self->session->user->userId ne "1" && $self->session->user->userId eq $self->get("ownerUserId"));
my $self = shift;
my $userId = shift || $self->session->user->userId;
return ( $userId ne "1" && $userId eq $self->get("ownerUserId") );
}

View file

@ -47,14 +47,19 @@ sub canAdd {
#-------------------------------------------------------------------
sub canReply {
my $self = shift;
return !$self->isThreadLocked && $self->getParent->get("allowReplies") && $self->getParent->canPost;
my $self = shift;
my $userId = shift || $self->session->user->userId;
return !$self->isThreadLocked
&& $self->getParent->get("allowReplies")
&& $self->getParent->canPost( $userId )
;
}
#-------------------------------------------------------------------
sub canSubscribe {
my $self = shift;
return ($self->session->user->userId ne "1" && $self->canView);
my $self = shift;
my $userId = shift || $self->session->user->userId;
return ($userId ne "1" && $self->canView( $userId ) );
}
#-------------------------------------------------------------------

View file

@ -248,7 +248,8 @@ sub appendTemplateLabels {
#-------------------------------------------------------------------
sub canEdit {
my $self = shift;
my $self = shift;
my $userId = shift || $self->session->user->userId;
return (
(
(
@ -259,85 +260,109 @@ sub canEdit {
$self->session->form->process("class") eq "WebGUI::Asset::Post::Thread"
)
) &&
$self->canPost
) || # account for new posts
$self->SUPER::canEdit()
$self->canStartThread( $userId )
) || # account for new threads
$self->SUPER::canEdit( $userId )
);
}
#-------------------------------------------------------------------
sub canModerate {
my $self = shift;
return $self->SUPER::canEdit;
my $self = shift;
my $userId = shift || $self->session->user->userId;
return $self->SUPER::canEdit( $userId );
}
#-------------------------------------------------------------------
sub canPost {
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("postGroupId"))
|| $self->SUPER::canEdit
)
);
my $self = shift;
my $userId = shift;
my $session = $self->session;
my $user = $userId
? WebGUI::User->new( $session, $userId )
: $self->session->user
;
# checks to make sure that the cs has been committed at least once
if ( $self->get("status") ne "approved" && $self->getTagCount <= 1 ) {
return 0;
}
# Users in the postGroupId can post
elsif ( $user->isInGroup( $self->get("postGroupId") ) ) {
return 1;
}
# Users who can edit the collab can post
else {
return $self->SUPER::canEdit( $userId );
}
}
#-------------------------------------------------------------------
sub canSubscribe {
my $self = shift;
return ($self->session->user->userId ne "1" && $self->canView);
my $self = shift;
my $userId = shift;
my $session = $self->session;
my $user = $userId
? WebGUI::User->new( $session, $userId )
: $self->session->user
;
return ($user->userId ne "1" && $self->canView( $userId ) );
}
#-------------------------------------------------------------------
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
)
);
my $self = shift;
my $userId = shift;
my $session = $self->session;
my $user = $userId
? WebGUI::User->new( $session, $userId )
: $self->session->user
;
return (
(
$self->get("status") eq "approved" ||
$self->getTagCount > 1 # checks to make sure that the cs has been committed at least once
) && (
$user->isInGroup($self->get("canStartThreadGroupId"))
|| $self->SUPER::canEdit( $userId )
)
);
}
#-------------------------------------------------------------------
sub canView {
my $self = shift;
return $self->SUPER::canView || $self->canPost;
my $userId = shift || $self->session->user->userId;
return $self->SUPER::canView( $userId ) || $self->canPost( $userId );
}
#-------------------------------------------------------------------
sub commit {
my $self = shift;
$self->SUPER::commit;
my $cron = undef;
if ($self->get("getMailCronId")) {
$cron = WebGUI::Workflow::Cron->new($self->session, $self->get("getMailCronId"));
}
my $i18n = WebGUI::International->new($self->session, "Asset_Collaboration");
unless (defined $cron) {
$cron = WebGUI::Workflow::Cron->create($self->session, {
title=>$self->getTitle." ".$i18n->get("mail"),
minuteOfHour=>"*/".($self->get("getMailInterval")/60),
className=>(ref $self),
methodName=>"new",
parameters=>$self->getId,
workflowId=>"csworkflow000000000001"
});
$self->update({getMailCronId=>$cron->getId});
}
if ($self->get("getMail")) {
$cron->set({enabled=>1,title=>$self->getTitle." ".$i18n->get("mail"), minuteOfHour=>"*/".($self->get("getMailInterval")/60)});
} else {
$cron->set({enabled=>0,title=>$self->getTitle." ".$i18n->get("mail"), minuteOfHour=>"*/".($self->get("getMailInterval")/60)});
}
my $self = shift;
$self->SUPER::commit;
my $cron = undef;
if ($self->get("getMailCronId")) {
$cron = WebGUI::Workflow::Cron->new($self->session, $self->get("getMailCronId"));
}
my $i18n = WebGUI::International->new($self->session, "Asset_Collaboration");
unless (defined $cron) {
$cron = WebGUI::Workflow::Cron->create($self->session, {
title=>$self->getTitle." ".$i18n->get("mail"),
minuteOfHour=>"*/".($self->get("getMailInterval")/60),
className=>(ref $self),
methodName=>"new",
parameters=>$self->getId,
workflowId=>"csworkflow000000000001"
});
$self->update({getMailCronId=>$cron->getId});
}
if ($self->get("getMail")) {
$cron->set({enabled=>1,title=>$self->getTitle." ".$i18n->get("mail"), minuteOfHour=>"*/".($self->get("getMailInterval")/60)});
} else {
$cron->set({enabled=>0,title=>$self->getTitle." ".$i18n->get("mail"), minuteOfHour=>"*/".($self->get("getMailInterval")/60)});
}
}
#-------------------------------------------------------------------

View file

@ -0,0 +1,124 @@
package WebGUI::Workflow::Activity::PurgeOldInboxMessages;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2008 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::Asset;
=head1 NAME
Package WebGUI::Workflow::Activity::PurgeOldInboxMessages
=head1 DESCRIPTION
Removes old, completed inbox messages from the database
=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_PurgeOldInboxMessages");
push @{$definition}, {
name => $i18n->get("activityName"),
properties => {
purgeAfter => {
fieldType => "interval",
defaultValue => 60 * 60 * 24 * 365,
label => $i18n->get("editForm purgeAfter label"),
hoverHelp => $i18n->get("editForm purgeAfter description"),
},
},
};
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my ($self, $nothing, $instance) = @_;
my $session = $self->session;
my $log = $session->errorHandler;
# keep track of how much time it's taking
my $start = time;
# Only purge this many per operation to prevent MySQL returning
# a half-million rows (which will take longer than the time we have)
my $limit = 2_500;
my $sth
= $session->db->read(
"SELECT messageId FROM inbox WHERE completedOn IS NOT NULL AND dateStamp < ? ORDER BY dateStamp ASC LIMIT $limit",
[ $start - $self->get('purgeAfter') ],
);
while ( ( my $messageId ) = $sth->array ) {
$session->db->write(
"DELETE FROM inbox WHERE messageId = ?",
[ $messageId ],
);
# give up if we're taking too long
if (time - $start > 120) {
$sth->finish;
return $self->WAITING;
}
}
# If there are more messages waiting to be purged, return WAITING
if ( $sth->rows >= $limit ) {
return $self->WAITING;
}
else {
return $self->COMPLETE;
}
}
1;

View file

@ -0,0 +1,25 @@
package WebGUI::i18n::English::Workflow_Activity_PurgeOldInboxMessages;
use strict;
our $I18N = {
'activityName' => {
message => q{Purge Old Inbox Messages},
lastUpdated => 0,
context => 'Title of workflow activity',
},
'editForm purgeAfter label' => {
message => q{Purge After},
lastUpdated => 0,
context => 'Label for workflow property',
},
'editForm purgeAfter description' => {
message => q{The length of time a message is allowed to remain in the inbox after it has been set to "completed"},
lastUpdated => 0,
context => 'Description of workflow property',
},
};
1;