Added the ability for users to add/remove themseleves to/from groups.

This commit is contained in:
JT Smith 2003-05-24 21:07:42 +00:00
parent c4830a3641
commit b7512be833
7 changed files with 201 additions and 5 deletions

View file

@ -33,7 +33,10 @@ 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");
$g = WebGUI::Group->find("Registered Users");
$integer = $g->autoAdd;
$integer = $g->autoDelete;
$epoch = $g->dateCreated;
$integer = $g->deleteOffset(14);
$text = $g->description("Those really smart dudes.");
@ -87,6 +90,64 @@ sub addGroups {
WebGUI::Grouping::addGroupsToGroups($_[1],[$_[0]->{_groupId}]);
}
#-------------------------------------------------------------------
=head2 autoAdd ( [ value ] )
Returns an boolean stating whether users can add themselves to this group.
=over
=item value
If specified, the autoAdd is set to this value.
=back
=cut
sub autoAdd {
my ($class, $value);
$class = shift;
$value = shift;
if (defined $value) {
$class->{_group}{"autoAdd"} = $value;
WebGUI::SQL->write("update groups set autoAdd=".quote($value).",
lastUpdated=".time()." where groupId=$class->{_groupId}");
}
return $class->{_group}{"autoAdd"};
}
#-------------------------------------------------------------------
=head2 autoDelete ( [ value ] )
Returns an boolean stating whether users can delete themselves from this group.
=over
=item value
If specified, the autoDelete is set to this value.
=back
=cut
sub autoDelete {
my ($class, $value);
$class = shift;
$value = shift;
if (defined $value) {
$class->{_group}{"autoDelete"} = $value;
WebGUI::SQL->write("update groups set autoDelete=".quote($value).",
lastUpdated=".time()." where groupId=$class->{_groupId}");
}
return $class->{_group}{"autoDelete"};
}
#-------------------------------------------------------------------
=head2 dateCreated ( )
@ -310,6 +371,28 @@ sub expireOffset {
}
#-------------------------------------------------------------------
=head find ( name )
An alternative to the constructor "new", use find as a constructor by name rather than id.
=over
=item name
The name of the group you wish to instanciate.
=back
=cut
sub find {
my ($groupId) = WebGUI::SQL->quickArray("select groupId from groups where groupName=".quote($_[1]));
return WebGUI::Group->new($groupId);
}
#-------------------------------------------------------------------
=head2 groupId ( )

View file

@ -0,0 +1,33 @@
package WebGUI::Macro::GroupAdd;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2003 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::Group;
use WebGUI::Macro;
use WebGUI::Session;
use WebGUI::Privilege;
use WebGUI::URL;
#-------------------------------------------------------------------
sub process {
my @param = WebGUI::Macro::getParams($_[0]);
return "" if ($param[0] eq "");
my $g = WebGUI::Group->find($param[0]);
return "" if ($g->groupId eq "");
return "" unless ($g->autoAdd);
return "" if (WebGUI::Privilege::isInGroup($g->groupId));
return '<a href="'.WebGUI::URL::page("op=autoAddToGroup&groupId=".$g->groupId).'">'.$param[1].'</a>';
}
1;

View file

@ -0,0 +1,33 @@
package WebGUI::Macro::GroupDelete;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2003 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::Group;
use WebGUI::Macro;
use WebGUI::Session;
use WebGUI::Privilege;
use WebGUI::URL;
#-------------------------------------------------------------------
sub process {
my @param = WebGUI::Macro::getParams($_[0]);
return "" if ($param[0] eq "");
my $g = WebGUI::Group->find($param[0]);
return "" if ($g->groupId eq "");
return "" unless ($g->autoDelete);
return "" unless (WebGUI::Privilege::isInGroup($g->groupId));
return '<a href="'.WebGUI::URL::page("op=autoDeleteFromGroup&groupId=".$g->groupId).'">'.$param[1].'</a>';
}
1;

View file

@ -16,6 +16,7 @@ use Tie::CPHash;
use WebGUI::DateTime;
use WebGUI::Group;
use WebGUI::Grouping;
use WebGUI::FormProcessor;
use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::International;
@ -31,7 +32,7 @@ use WebGUI::Utility;
our @ISA = qw(Exporter);
our @EXPORT = qw(&www_manageUsersInGroup &www_deleteGroup &www_deleteGroupConfirm &www_editGroup
&www_editGroupSave &www_listGroups &www_emailGroup &www_emailGroupSend &www_manageGroupsInGroup
&www_addGroupsToGroupSave &www_deleteGroupGrouping);
&www_addGroupsToGroupSave &www_deleteGroupGrouping &www_autoAddToGroup &www_autoDeleteFromGroup);
#-------------------------------------------------------------------
sub _submenu {
@ -60,6 +61,26 @@ sub www_addGroupsToGroupSave {
return www_manageGroupsInGroup();
}
#-------------------------------------------------------------------
sub www_autoAddToGroup {
return WebGUI::Privilege::insufficient() unless ($session{user}{userId} != 1);
my $group = WebGUI::Group->new($session{form}{groupId});
if ($group->autoAdd) {
WebGUI::Grouping::addUsersToGroups([$session{user}{userId}],[$session{form}{groupId}]);
}
return "";
}
#-------------------------------------------------------------------
sub www_autoDeleteFromGroup {
return WebGUI::Privilege::insufficient() unless ($session{user}{userId} != 1);
my $group = WebGUI::Group->new($session{form}{groupId});
if ($group->autoDelete) {
WebGUI::Grouping::deleteUsersFromGroups([$session{user}{userId}],[$session{form}{groupId}]);
}
return "";
}
#-------------------------------------------------------------------
sub www_deleteGroup {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3));
@ -146,6 +167,16 @@ sub www_editGroup {
-value=>$g->scratchFilter,
-label=>WebGUI::International::get(945)
);
$f->yesNo(
-name=>"autoAdd",
-value=>$g->autoAdd,
-label=>WebGUI::International::get(974)
);
$f->yesNo(
-name=>"autoDelete",
-value=>$g->autoDelete,
-label=>WebGUI::International::get(975)
);
$f->submit;
$output .= $f->print;
return _submenu($output);
@ -157,14 +188,16 @@ sub www_editGroupSave {
my $g = WebGUI::Group->new($session{form}{gid});
$g->description($session{form}{description});
$g->name($session{form}{groupName});
$g->expireOffset(WebGUI::DateTime::intervalToSeconds($session{form}{expireOffset_interval},$session{form}{expireOffset_units}));
$g->expireOffset(WebGUI::FormProcessor::interval("expireOffset"));
$g->karmaThreshold($session{form}{karmaThreshold});
$g->ipFilter($session{form}{ipFilter});
$g->scratchFilter($session{form}{scratchFilter});
$g->expireNotify($session{form}{expireNotify});
$g->expireNotify(WebGUI::FormProcessor::yesNo("expireNotify"));
$g->expireNotifyOffset($session{form}{expireNotifyOffset});
$g->expireNotifyMessage($session{form}{expireNotifyMessage});
$g->deleteOffset($session{form}{deleteOffset});
$g->autoAdd(WebGUI::FormProcessor::yesNo("autoAdd"));
$g->autoDelete(WebGUI::FormProcessor::yesNo("autoDelete"));
return www_listGroups();
}