Added group expiration notifications.
This commit is contained in:
parent
3f2d2c63f9
commit
226ed9abcf
10 changed files with 241 additions and 31 deletions
|
|
@ -28,6 +28,21 @@ INSERT INTO userProfileField VALUES ('publicEmail','WebGUI::International::get(8
|
|||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (862,1,'WebGUI','This user\'s profile is not public.', 1043881275);
|
||||
alter table groups add column dateCreated int not null default 997938000;
|
||||
alter table groups add column lastUpdated int not null default 997938000;
|
||||
alter table groups add column deleteOffset int not null default 14;
|
||||
alter table groups add column expireNotifyOffset int not null default -14;
|
||||
alter table groups add column expireNotifyMessage text;
|
||||
alter table groups add column expireNotify int not null default 0;
|
||||
alter table groups change expireAfter expireOffset int not null default 314496000;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (866,1,'WebGUI','Expire Notifcation Message', 1044127055);
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (865,1,'WebGUI','Notify user about expiration?', 1044126938);
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (864,1,'WebGUI','Expire Notification Offset', 1044126838);
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (863,1,'WebGUI','Delete Offset', 1044126633);
|
||||
delete from international where languageId=1 and namespace='WebGUI' and internationalId=367;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (367,1,'WebGUI','Expire Offset', 1044126611);
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (867,1,'WebGUI','Loss of Privilege', 1044133143);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,14 +34,18 @@ This package provides an object-oriented way of managing WebGUI groups and group
|
|||
use WebGUI::Group;
|
||||
$g = WebGUI::Group->new(3); or $g = WebGUI::User->new("new");
|
||||
|
||||
$dateCreated = $g->dateCreated;
|
||||
$description = $g->description("Those really smart dudes.");
|
||||
$expireAfter = $g->expireAfter(360000);
|
||||
$groupId = $g->groupId;
|
||||
$karmaThreshold = $g->karmaThreshold(5000);
|
||||
$ipFilter = $g->ipFilter("10.;192.168.1.");
|
||||
$lastUpdated = $g->lastUpdated;
|
||||
$name = $g->name("Nerds");
|
||||
$epoch = $g->dateCreated;
|
||||
$integer = $g->deleteOffset(14);
|
||||
$text = $g->description("Those really smart dudes.");
|
||||
$integer = $g->expireNotify(1);
|
||||
$integer = $g->expireNotifyMessage("You're outta here!");
|
||||
$integer = $g->expireNotifyOffset(-14);
|
||||
$integer = $g->expireOffset(360000);
|
||||
$integer = $g->groupId;
|
||||
$integer = $g->karmaThreshold(5000);
|
||||
$string = $g->ipFilter("10.;192.168.1.");
|
||||
$epoch = $g->lastUpdated;
|
||||
$string = $g->name("Nerds");
|
||||
|
||||
$g->addGroups(\@arr);
|
||||
$g->deleteGroups(\@arr);
|
||||
|
|
@ -57,7 +61,7 @@ These methods are available from this class:
|
|||
#-------------------------------------------------------------------
|
||||
sub _create {
|
||||
my $groupId = getNextId("groupId");
|
||||
WebGUI::SQL->write("insert into groups (groupId,dateCreated,expireAfter,karmaThreshold) values
|
||||
WebGUI::SQL->write("insert into groups (groupId,dateCreated,expireOffset,karmaThreshold) values
|
||||
($groupId,".time().",314496000,1000000000)");
|
||||
return $groupId;
|
||||
}
|
||||
|
|
@ -130,6 +134,35 @@ sub deleteGroups {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 deleteOffset ( [ value ] )
|
||||
|
||||
Returns the number of days after the expiration to delete the grouping.
|
||||
|
||||
=over
|
||||
|
||||
=item value
|
||||
|
||||
If specified, deleteOffset is set to this value. Defaults to "-14".
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub deleteOffset {
|
||||
my ($class, $value);
|
||||
$class = shift;
|
||||
$value = shift;
|
||||
if (defined $value) {
|
||||
$class->{_group}{"deleteOffset"} = $value;
|
||||
WebGUI::SQL->write("update groups set deleteOffset=$value,
|
||||
lastUpdated=".time()." where groupId=$class->{_groupId}");
|
||||
}
|
||||
return $class->{_group}{"deleteOffset"};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 description ( [ value ] )
|
||||
|
|
@ -161,7 +194,95 @@ sub description {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 expireAfter ( [ value ] )
|
||||
=head2 expireNotify ( [ value ] )
|
||||
|
||||
Returns a boolean value whether or not to notify the user of the group expiry.
|
||||
|
||||
=over
|
||||
|
||||
=item value
|
||||
|
||||
If specified, expireNotify is set to this value.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub expireNotify {
|
||||
my ($class, $value);
|
||||
$class = shift;
|
||||
$value = shift;
|
||||
if (defined $value) {
|
||||
$class->{_group}{"expireNotify"} = $value;
|
||||
WebGUI::SQL->write("update groups set expireNotify=$value,
|
||||
lastUpdated=".time()." where groupId=$class->{_groupId}");
|
||||
}
|
||||
return $class->{_group}{"expireNotify"};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 expireNotifyMessage ( [ value ] )
|
||||
|
||||
Returns the message to send to the user about expiration.
|
||||
|
||||
=over
|
||||
|
||||
=item value
|
||||
|
||||
If specified, expireNotifyMessage is set to this value.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub expireNotifyMessage {
|
||||
my ($class, $value);
|
||||
$class = shift;
|
||||
$value = shift;
|
||||
if (defined $value) {
|
||||
$class->{_group}{"expireNotifyMessage"} = $value;
|
||||
WebGUI::SQL->write("update groups set expireNotifyMessage=".quote($value).",
|
||||
lastUpdated=".time()." where groupId=$class->{_groupId}");
|
||||
}
|
||||
return $class->{_group}{"expireNotifyMessage"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 expireNotifyOffset ( [ value ] )
|
||||
|
||||
Returns the number of days after the expiration to notify the user.
|
||||
|
||||
=over
|
||||
|
||||
=item value
|
||||
|
||||
If specified, expireNotifyOffset is set to this value.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub expireNotifyOffset {
|
||||
my ($class, $value);
|
||||
$class = shift;
|
||||
$value = shift;
|
||||
if (defined $value) {
|
||||
$class->{_group}{"expireNotifyOffset"} = $value;
|
||||
WebGUI::SQL->write("update groups set expireNotifyOffset=$value,
|
||||
lastUpdated=".time()." where groupId=$class->{_groupId}");
|
||||
}
|
||||
return $class->{_group}{"expireNotifyOffset"};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 expireOffset ( [ value ] )
|
||||
|
||||
Returns the number of seconds any grouping with this group should expire after.
|
||||
|
||||
|
|
@ -169,22 +290,22 @@ Returns the number of seconds any grouping with this group should expire after.
|
|||
|
||||
=item value
|
||||
|
||||
If specified, expireAfter is set to this value.
|
||||
If specified, expireOffset is set to this value.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub expireAfter {
|
||||
sub expireOffset {
|
||||
my ($class, $value);
|
||||
$class = shift;
|
||||
$value = shift;
|
||||
if (defined $value) {
|
||||
$class->{_group}{"expireAfter"} = $value;
|
||||
WebGUI::SQL->write("update groups set expireAfter=".quote($value).",
|
||||
$class->{_group}{"expireOffset"} = $value;
|
||||
WebGUI::SQL->write("update groups set expireOffset=".quote($value).",
|
||||
lastUpdated=".time()." where groupId=$class->{_groupId}");
|
||||
}
|
||||
return $class->{_group}{"expireAfter"};
|
||||
return $class->{_group}{"expireOffset"};
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -324,9 +445,12 @@ sub new {
|
|||
$groupId = shift;
|
||||
$groupId = _create() if ($groupId eq "new");
|
||||
if ($groupId eq "") {
|
||||
$group{expireAfter} = 314496000;
|
||||
$group{expireOffset} = 314496000;
|
||||
$group{karmaThreshold} = 1000000000;
|
||||
$group{groupName} = "New Group";
|
||||
$group{expireNotifyOffset} = -14;
|
||||
$group{deleteOffset} = 14;
|
||||
$group{expireNotify} = 0;
|
||||
} else {
|
||||
%group = WebGUI::SQL->quickHash("select * from groups where groupId='$groupId'");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,18 +103,17 @@ An array reference containing a list of groups.
|
|||
|
||||
sub addUsersToGroups {
|
||||
foreach my $gid (@{$_[1]}) {
|
||||
my ($expireAfter) = WebGUI::SQL->quickArray("select expireAfter from groups where groupId=$gid");
|
||||
my ($expireOffset) = WebGUI::SQL->quickArray("select expireOffset from groups where groupId=$gid");
|
||||
foreach my $uid (@{$_[0]}) {
|
||||
my ($isIn) = WebGUI::SQL->quickArray("select count(*) from groupings where groupId=$gid and userId=$uid");
|
||||
unless ($isIn) {
|
||||
WebGUI::SQL->write("insert into groupings (groupId,userId,expireDate)
|
||||
values ($gid, $uid, ".(time()+$expireAfter).")");
|
||||
values ($gid, $uid, ".(time()+$expireOffset).")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 deleteGroupsFromGroups ( groups, fromGroups )
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ sub send {
|
|||
#body
|
||||
$message .= $_[2]."\n";
|
||||
#footer
|
||||
$message .= "\n".$session{setting}{mailFooter}
|
||||
$message .= "\n".$session{setting}{mailFooter};
|
||||
#process macros on message
|
||||
$message = WebGUI::Macro::process($message);
|
||||
if ($session{setting}{smtpServer} =~ /\/sendmail/) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package WebGUI::MessageLog;
|
|||
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::Mail;
|
||||
|
|
@ -126,7 +127,8 @@ sub addEntry {
|
|||
foreach $user (@users) {
|
||||
$u = WebGUI::User->new($user);
|
||||
if ($u->userId ne "") {
|
||||
WebGUI::SQL->write("insert into messageLog values ($messageLogId,".$u->userId.",
|
||||
WebGUI::SQL->write("insert into messageLog (messageLogId, userId, message, url, dateOfEntry,
|
||||
subject, status) values ($messageLogId,".$u->userId.",
|
||||
".quote($message).",".quote($url).",".time().",".quote($subject).", ".quote($status).")");
|
||||
if ($url ne "") {
|
||||
$message .= "\n".WebGUI::URL::append('http://'.$session{env}{HTTP_HOST}.$url,'mlog='.$messageLogId);
|
||||
|
|
|
|||
|
|
@ -108,7 +108,27 @@ sub www_editGroup {
|
|||
$f->readOnly($g->groupId,WebGUI::International::get(379));
|
||||
$f->text("groupName",WebGUI::International::get(84),$g->name);
|
||||
$f->textarea("description",WebGUI::International::get(85),$g->description);
|
||||
$f->interval("expireAfter",WebGUI::International::get(367), WebGUI::DateTime::secondsToInterval($g->expireAfter));
|
||||
$f->interval("expireOffset",WebGUI::International::get(367), WebGUI::DateTime::secondsToInterval($g->expireOffset));
|
||||
$f->yesNo(
|
||||
-name=>"expireNotify",
|
||||
-value=>$g->expireNotify,
|
||||
-label=>WebGUI::International::get(865)
|
||||
);
|
||||
$f->integer(
|
||||
-name=>"expireNotifyOffset",
|
||||
-value=>$g->expireNotifyOffset,
|
||||
-label=>WebGUI::International::get(864)
|
||||
);
|
||||
$f->textarea(
|
||||
-name=>"expireNotifyMessage",
|
||||
-value=>$g->expireNotifyMessage,
|
||||
-label=>WebGUI::International::get(866)
|
||||
);
|
||||
$f->integer(
|
||||
-name=>"deleteOffset",
|
||||
-value=>$g->deleteOffset,
|
||||
-label=>WebGUI::International::get(863)
|
||||
);
|
||||
if ($session{setting}{useKarma}) {
|
||||
$f->integer("karmaThreshold",WebGUI::International::get(538),$g->karmaThreshold);
|
||||
}
|
||||
|
|
@ -128,9 +148,13 @@ sub www_editGroupSave {
|
|||
my $g = WebGUI::Group->new($session{form}{gid});
|
||||
$g->description($session{form}{description});
|
||||
$g->name($session{form}{groupName});
|
||||
$g->expireAfter(WebGUI::DateTime::intervalToSeconds($session{form}{expireAfter_interval},$session{form}{expireAfter_units}));
|
||||
$g->expireOffset(WebGUI::DateTime::intervalToSeconds($session{form}{expireOffset_interval},$session{form}{expireOffset_units}));
|
||||
$g->karmaThreshold($session{form}{karmaThreshold});
|
||||
$g->ipFilter($session{form}{ipFilter});
|
||||
$g->expireNotify($session{form}{expireNotify});
|
||||
$g->expireNotifyOffset($session{form}{expireNotifyOffset});
|
||||
$g->expireNotifyMessage($session{form}{expireNotifyMessage});
|
||||
$g->deleteOffset($session{form}{deleteOffset});
|
||||
return www_listGroups();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ sub www_addUser {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_addUserSave {
|
||||
my (@groups, $uid, $u, $gid, $encryptedPassword, $expireAfter, $cmd);
|
||||
my (@groups, $uid, $u, $gid, $encryptedPassword, $cmd);
|
||||
return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3));
|
||||
($uid) = WebGUI::SQL->quickArray("select userId from users where username=".quote($session{form}{username}));
|
||||
unless ($uid) {
|
||||
|
|
|
|||
|
|
@ -17,9 +17,14 @@ use WebGUI::SQL;
|
|||
|
||||
#-----------------------------------------
|
||||
sub process {
|
||||
if ($session{config}{DeleteExpiredGroupings_offset} ne "") {
|
||||
WebGUI::SQL->write("delete from groupings where expireDate < "
|
||||
.(time()-(86400*$session{config}{DeleteExpiredGroupings_offset})));
|
||||
my @date = WebGUI::DateTime::localtime();
|
||||
if ($date[4] == 3) { # only occurs at 3am on the day in question.
|
||||
my $sth = WebGUI::SQL->read("select groupId,deleteOffset from groups");
|
||||
while (my $data = $sth->hashRef) {
|
||||
WebGUI::SQL->write("delete from groupings where groupId=$data->{groupId} and expireDate < "
|
||||
.(time()-(86400*$data->{deleteOffset})));
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
41
sbin/Hourly/NotifyExpiredGroupings.pm
Normal file
41
sbin/Hourly/NotifyExpiredGroupings.pm
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package Hourly::NotifyExpiredGroupings;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2002 Plain Black LLC.
|
||||
#-------------------------------------------------------------------
|
||||
# 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
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::International;
|
||||
use WebGUI::MessageLog;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
#-----------------------------------------
|
||||
sub process {
|
||||
my @date = WebGUI::DateTime::localtime();
|
||||
if ($date[4] == 1) { # only occurs at 1am on the day in question.
|
||||
my $now = time();
|
||||
my $a = WebGUI::SQL->read("select groupId,expireNotifyOffset,expireNotifyMessage from groups
|
||||
where expireNotify=1");
|
||||
while (my $group = $a->hashRef) {
|
||||
my $start = $now + (86400 * $group->{expireNotifyOffset});
|
||||
my $end = $start + 86400;
|
||||
my $b = WebGUI::SQL->read("select userId from groupings where expireDate>=".$start." and expireDate<=".$end);
|
||||
while (my ($userId) = $b->array) {
|
||||
WebGUI::MessageLog::addEntry($userId,"",WebGUI::International::get(867),$group->{expireNotifyMessage});
|
||||
}
|
||||
$b->finish;
|
||||
}
|
||||
$a->finish;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ $|=1;
|
|||
|
||||
print "Starting...\n";
|
||||
|
||||
my ($i, $dbh, @row, %user, @field, $userId, $first, $dup, $lineNumber, $expireAfter, @group);
|
||||
my ($i, $dbh, @row, %user, @field, $userId, $first, $dup, $lineNumber, $expireOffset, @group);
|
||||
$first = 1;
|
||||
$dbh = connectToDb();
|
||||
open(FILE,"<".$usersFile);
|
||||
|
|
@ -109,13 +109,13 @@ while(<FILE>) {
|
|||
values ($user{userId},'LDAP','$_',".$dbh->quote($user{$_}).")");
|
||||
}
|
||||
}
|
||||
($expireAfter) = WebGUI::SQL->quickArray("select expireAfter from groups where groupId=2",$dbh);
|
||||
($expireOffset) = WebGUI::SQL->quickArray("select expireOffset from groups where groupId=2",$dbh);
|
||||
$user{groups} =~ s/ //g;
|
||||
@group = split(/,/,$user{groups});
|
||||
foreach (@group) {
|
||||
($expireAfter) = WebGUI::SQL->quickArray("select expireAfter from groups where groupId=$_",$dbh);
|
||||
($expireOffset) = WebGUI::SQL->quickArray("select expireOffset from groups where groupId=$_",$dbh);
|
||||
WebGUI::SQL->write("insert into groupings (groupId,userId,expireDate) values
|
||||
($user{userId},$_,".(time()+$expireAfter).")",$dbh);
|
||||
($user{userId},$_,".(time()+$expireOffset).")",$dbh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue