From b7512be8332e9c2754da4859ba820d6c6f8fc168 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sat, 24 May 2003 21:07:42 +0000 Subject: [PATCH] Added the ability for users to add/remove themseleves to/from groups. --- docs/upgrades/upgrade_5.2.6-5.3.0.pl | 2 + docs/upgrades/upgrade_5.2.6-5.3.0.sql | 14 ++++- lib/WebGUI/Group.pm | 83 ++++++++++++++++++++++++++ lib/WebGUI/Macro/GroupAdd.pm | 33 ++++++++++ lib/WebGUI/Macro/GroupDelete.pm | 33 ++++++++++ lib/WebGUI/Operation/Group.pm | 39 +++++++++++- www/extras/htmlArea/popups/macros.html | 2 + 7 files changed, 201 insertions(+), 5 deletions(-) create mode 100644 lib/WebGUI/Macro/GroupAdd.pm create mode 100644 lib/WebGUI/Macro/GroupDelete.pm diff --git a/docs/upgrades/upgrade_5.2.6-5.3.0.pl b/docs/upgrades/upgrade_5.2.6-5.3.0.pl index 724ddc03e..b02a97eec 100644 --- a/docs/upgrades/upgrade_5.2.6-5.3.0.pl +++ b/docs/upgrades/upgrade_5.2.6-5.3.0.pl @@ -33,6 +33,8 @@ $macros->{LastModified} = "LastModified"; $macros->{PreviousDropMenu} = "PreviousDropMenu"; $macros->{TopDropMenu} = "TopDropMenu"; $macros->{EditableToggle} = "EditableToggle"; +$macros->{GroupAdd} = "GroupAdd"; +$macros->{GroupDelete} = "GroupDelete"; $macros->{SI} = "SI_scaledImage"; $conf->set("macros"=>$macros); my $wobjects = $conf->get("wobjects"); diff --git a/docs/upgrades/upgrade_5.2.6-5.3.0.sql b/docs/upgrades/upgrade_5.2.6-5.3.0.sql index 033730167..02a057757 100644 --- a/docs/upgrades/upgrade_5.2.6-5.3.0.sql +++ b/docs/upgrades/upgrade_5.2.6-5.3.0.sql @@ -545,8 +545,6 @@ insert into international (internationalId,languageId,namespace,message,lastUpda delete from international where languageId=1 and namespace='WobjectProxy' and internationalId=7; insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (7,1,'WobjectProxy','Override title?', 1053183682,'Asking the user if s/he would like to use the title specified in the wobject proxy or the original title of the original wobject.'); INSERT INTO style VALUES (-10,'htmlArea Image Manager','\r\n','\r\n\r\n\r\n\r\n\r\n\r\n^-;\r\n'); -delete from international where languageId=1 and namespace='WebGUI' and internationalId=844; -insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (844,1,'WebGUI','These macros have to do with users and logins.\r\n

\r\n\r\n^a; or ^a(); - My Account Link
\r\nA link to your account information. In addition you can change the link text by creating a macro like this ^a("Account Info");. \r\n

\r\n\r\nNOTES: You can also use the special case ^a(linkonly); to return only the URL to the account page and nothing more. Also, the .myAccountLink style sheet class is tied to this macro.\r\n

\r\n\r\n\r\n^AdminText();
\r\nDisplays a small text message to a user who is in admin mode. Example: ^AdminText("You are in admin mode!");\r\n

\r\n\r\n^AdminToggle; or ^AdminToggle();
\r\nPlaces a link on the page which is only visible to content managers and adminstrators. The link toggles on/off admin mode. You can optionally specify other messages to display like this: ^AdminToggle("Edit On","Edit Off");\r\n

\r\n\r\n^CanEditText();
\r\nDisplay a message to a user that can edit the current page.\r\n

\r\nExample: ^CanEditText(^AdminToggle;);\r\n

\r\n\r\n^EditableToggle; or ^EditableToggle();
\r\nExactly the same as AdminToggle, except that the toggle is only displayed if the user has the rights to edit the current page.\r\n

\r\n\r\n^GroupText();
\r\nDisplays a small text message to the user if they belong to the specified group. And you can specify an alternate message to those who are not in the group.\r\n

\r\nExample: ^GroupText("Visitors","You need an account to do anything cool on this site!","We value our registered users!");\r\n

\r\n\r\n^L; or ^L(); - Login Box
\r\nA small login form. You can also configure this macro. You can set the width of the login box like this ^L(20);. You can also set the message displayed after the user is logged in like this ^L(20,Hi ^a(^@;);. Click %here% if you wanna log out!)\r\n

\r\n\r\nNOTE: The .loginBox style sheet class is tied to this macro.\r\n

\r\n\r\n^LoginToggle; or ^LoginToggle();
\r\nDisplays a "Login" or "Logout" message depending upon whether the user is logged in or not. You can optionally specify other labels like this: ^LoginToggle("Click here to log in.","Click here to log out.");. You can also use the special case ^LoginToggle(linkonly); to return only the URL with no label.\r\n

\r\n\r\n^@; - Username
\r\nThe username of the currently logged in user.\r\n

\r\n\r\n\r\n^#; - User ID
\r\nThe user id of the currently logged in user.\r\n

\r\n\r\n', 1053114197,NULL); delete from international where languageId=1 and namespace='WebGUI' and internationalId=972; insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (972,1,'WebGUI','Date and Time', 1053278234,'A field that holds a calendar date and clock time.'); delete from international where languageId=1 and namespace='WebGUI' and internationalId=971; @@ -567,6 +565,18 @@ insert into international (internationalId,languageId,namespace,message,lastUpda delete from international where languageId=1 and namespace='Auth/LDAP' and internationalId=9; insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (9,1,'Auth/LDAP','User RDN', 1053777552,'Specifying the relative distinguished name to authenticate a user against an LDAP directory.'); insert into settings values ("ldapUserRDN","cn"); +alter table groups add column autoAdd integer not null default 0; +alter table groups add column autoDelete integer not null default 0; +delete from international where languageId=1 and namespace='WebGUI' and internationalId=622; +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (622,1,'WebGUI','See Manage Group for a description of grouping functions and the default groups.\r\n

\r\n\r\nGroup Name
\r\nA name for the group. It is best if the name is descriptive so you know what it is at a glance.\r\n

\r\n\r\nDescription
\r\nA longer description of the group so that other admins and content managers (or you if you forget) will know what the purpose of this group is.\r\n

\r\n\r\nExpire Offset
\r\nThe amount of time that a user will belong to this group before s/he is expired (or removed) from it. This is very useful for membership sites where users have certain privileges for a specific period of time. \r\n

\r\nNOTE: This can be overridden on a per-user basis.\r\n

\r\n\r\nNotify user about expiration?
\r\nSet this value to yes if you want WebGUI to contact the user when they are about to be expired from the group.\r\n

\r\n\r\nExpire Notification Offset
\r\nThe difference in the number of days from the expiration to the notification. You may set this to any valid integer. For instance, set this to "0" if you wish the notification to be sent on the same day that the grouping expires. Set it to "-7" if you want the notification to go out 7 days before the grouping expires. Set it to "7" if you wish the notification to be sent 7 days after the expiration.\r\n

\r\n\r\nExpire Notification Message
\r\nType the message you wish to be sent to the user telling them about the expiration.\r\n

\r\n\r\nDelete Offset
\r\nThe difference in the number of days from the expiration to the grouping being deleted from the system. You may set this to any valid integer. For instance, set this to "0" if you wish the grouping to be deleted on the same day that the grouping expires. Set it to "-7" if you want the grouping to be deleted 7 days before the grouping expires. Set it to "7" if you wish the grouping to be deleted 7 days after the expiration.\r\n

\r\n\r\nIP Address
\r\nSpecify an IP address or an IP mask to match. If the user\'s IP address matches, they\'ll automatically be included in this group. An IP mask is simply the IP address minus an octet or two. You may also specify multiple IP masks separated by semicolons.\r\n

\r\nIP Mask Example: 10.;192.168.;101.42.200.142\r\n

\r\n\r\nKarma Threshold
\r\nIf you\'ve enabled Karma, then you\'ll be able to set this value. Karma Threshold is the amount of karma a user must have to be considered part of this group.\r\n

\r\n\r\n\r\nUsers can add themselves?
\r\nDo you wish to let users add themselves to this group? See the GroupAdd macro for more info.\r\n

\r\n\r\nUsers can remove themselves?
\r\nDo you wish to let users remove themselves from this group? See the GroupDelete macro for more info.', 1053779630,NULL); +delete from international where languageId=1 and namespace='WebGUI' and internationalId=975; +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (975,1,'WebGUI','Users can remove themselves?', 1053778962,'Determines whether users can delete themselves from this group.'); +delete from international where languageId=1 and namespace='WebGUI' and internationalId=974; +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (974,1,'WebGUI','Users can add themselves?', 1053778912,'Determines whether users can add themselves to this group.'); +delete from international where languageId=1 and namespace='WebGUI' and internationalId=844; +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (844,1,'WebGUI','These macros have to do with users and logins.\r\n

\r\n\r\n^a; or ^a(); - My Account Link
\r\nA link to your account information. In addition you can change the link text by creating a macro like this ^a("Account Info");. \r\n

\r\n\r\nNOTES: You can also use the special case ^a(linkonly); to return only the URL to the account page and nothing more. Also, the .myAccountLink style sheet class is tied to this macro.\r\n

\r\n\r\n\r\n^AdminText();
\r\nDisplays a small text message to a user who is in admin mode. Example: ^AdminText("You are in admin mode!");\r\n

\r\n\r\n^AdminToggle; or ^AdminToggle();
\r\nPlaces a link on the page which is only visible to content managers and adminstrators. The link toggles on/off admin mode. You can optionally specify other messages to display like this: ^AdminToggle("Edit On","Edit Off");\r\n

\r\n\r\n^CanEditText();
\r\nDisplay a message to a user that can edit the current page.\r\n

\r\nExample: ^CanEditText(^AdminToggle;);\r\n

\r\n\r\n^EditableToggle; or ^EditableToggle();
\r\nExactly the same as AdminToggle, except that the toggle is only displayed if the user has the rights to edit the current page.\r\n

\r\n\r\n^GroupAdd();
\r\nUsing this macro you can allow users to add themselves to a group. The first parameter is the name of the group this user should be added to. The second parameter is a text string for the user to click on to add themselves to this group.\r\n

\r\nNOTE: If the user is not logged in, or or already belongs to the group, or the group is not set to allow auto adds, then no link will be displayed.\r\n

\r\n\r\n\r\n^GroupDelete();
\r\nUsing this macro you can allow users to delete themselves from a group. The first parameter is the name of the group this user should be deleted from. The second parameter is a text string for the user to click on to delete themselves from this group.\r\n

\r\nNOTE: If the user is not logged in or the user does not belong to the group, or the group is not set to allow auto deletes, then no link will be displayed.\r\n

\r\n\r\n^GroupText();
\r\nDisplays a small text message to the user if they belong to the specified group. And you can specify an alternate message to those who are not in the group.\r\n

\r\nExample: ^GroupText("Visitors","You need an account to do anything cool on this site!","We value our registered users!");\r\n

\r\n\r\n^L; or ^L(); - Login Box
\r\nA small login form. You can also configure this macro. You can set the width of the login box like this ^L(20);. You can also set the message displayed after the user is logged in like this ^L(20,Hi ^a(^@;);. Click %here% if you wanna log out!)\r\n

\r\n\r\nNOTE: The .loginBox style sheet class is tied to this macro.\r\n

\r\n\r\n^LoginToggle; or ^LoginToggle();
\r\nDisplays a "Login" or "Logout" message depending upon whether the user is logged in or not. You can optionally specify other labels like this: ^LoginToggle("Click here to log in.","Click here to log out.");. You can also use the special case ^LoginToggle(linkonly); to return only the URL with no label.\r\n

\r\n\r\n^@; - Username
\r\nThe username of the currently logged in user.\r\n

\r\n\r\n\r\n^#; - User ID
\r\nThe user id of the currently logged in user.\r\n

\r\n\r\n', 1053779917,NULL); + + diff --git a/lib/WebGUI/Group.pm b/lib/WebGUI/Group.pm index 5ba194db3..f760c0c3c 100755 --- a/lib/WebGUI/Group.pm +++ b/lib/WebGUI/Group.pm @@ -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 ( ) diff --git a/lib/WebGUI/Macro/GroupAdd.pm b/lib/WebGUI/Macro/GroupAdd.pm new file mode 100644 index 000000000..a95c917f4 --- /dev/null +++ b/lib/WebGUI/Macro/GroupAdd.pm @@ -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 'groupId).'">'.$param[1].''; +} + + +1; + diff --git a/lib/WebGUI/Macro/GroupDelete.pm b/lib/WebGUI/Macro/GroupDelete.pm new file mode 100644 index 000000000..c2d648824 --- /dev/null +++ b/lib/WebGUI/Macro/GroupDelete.pm @@ -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 'groupId).'">'.$param[1].''; +} + + +1; + diff --git a/lib/WebGUI/Operation/Group.pm b/lib/WebGUI/Operation/Group.pm index 0b062426c..c1a9b978d 100644 --- a/lib/WebGUI/Operation/Group.pm +++ b/lib/WebGUI/Operation/Group.pm @@ -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(); } diff --git a/www/extras/htmlArea/popups/macros.html b/www/extras/htmlArea/popups/macros.html index 8363577d1..9e922cb7c 100644 --- a/www/extras/htmlArea/popups/macros.html +++ b/www/extras/htmlArea/popups/macros.html @@ -89,6 +89,8 @@ function returnSelected(in_values) { +