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,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");

View file

@ -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','<style type=\"text/css\">\r\nTD { font: 8pt \'MS Shell Dlg\', Helvetica, sans-serif; }\r\nTD.delete { font: italic 7pt \'MS Shell Dlg\', Helvetica, sans-serif; }\r\nTD.label { font: 8pt \'MS Shell Dlg\', Helvetica, sans-serif; background-color: #c0c0c0; }\r\nTD.none { font: italic 12pt \'MS Shell Dlg\', Helvetica, sans-serif; }\r\n\r\n</style>\r\n','<script language=\"javascript\">\r\nfunction findAncestor(element, name, type) {\r\n while(element != null && (element.name != name || element.tagName != type))\r\n element = element.parentElement;\r\n return element;\r\n}\r\n</script>\r\n<script language=\"javascript\">\r\n\r\nfunction actionComplete(action, path, error, info) {\r\n var manager = findAncestor(window.frameElement, \'manager\', \'TABLE\');\r\n var wrapper = findAncestor(window.frameElement, \'wrapper\', \'TABLE\');\r\n\r\n if(manager) {\r\n if(error.length < 1) {\r\n manager.all.actions.reset();\r\n if(action == \'upload\') {\r\n manager.all.actions.image.value = \'\';\r\n manager.all.actions.name.value = \'\';\r\n manager.all.actions.thumbnailSize.value = \'\';\r\n\r\n }\r\n if(action == \'create\')\r\n manager.all.actions.folder.value = \'\';\r\n if(action == \'delete\')\r\n manager.all.txtFileName.value = \'\';\r\n }\r\n manager.all.actions.DPI.value = 96;\r\n manager.all.actions.path.value = path;\r\n }\r\n if(wrapper)\r\n wrapper.all.viewer.contentWindow.navigate(\'/?op=htmlAreaviewCollateral\');\r\n if(error.length > 0)\r\n alert(error);\r\n else if(info.length > 0)\r\n alert(info);\r\n}\r\n</script>\r\n\r\n<script language=\"javascript\">\r\nfunction deleteCollateral(options) {\r\n var lister = findAncestor(window.frameElement, \'lister\', \'IFRAME\');\r\n\r\n if(lister && confirm(\"Are you sure you want to delete this item ?\"))\r\n lister.contentWindow.navigate(\'^/;?op=htmlAreaDelete&\' + options);\r\n}\r\n</script>\r\n</head>\r\n<body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">\r\n^-;\r\n</body>');
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<p/>\r\n\r\n<b>&#94;a; or &#94;a(); - My Account Link</b><br>\r\nA link to your account information. In addition you can change the link text by creating a macro like this <b>&#94;a("Account Info");</b>. \r\n<p>\r\n\r\n<b>NOTES:</b> You can also use the special case &#94;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<p>\r\n\r\n\r\n<b>&#94;AdminText();</b><br>\r\nDisplays a small text message to a user who is in admin mode. Example: &#94;AdminText("You are in admin mode!");\r\n<p>\r\n\r\n<b>&#94;AdminToggle; or &#94;AdminToggle();</b><br>\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: &#94;AdminToggle("Edit On","Edit Off");\r\n<p>\r\n\r\n<b>&#94;CanEditText();</b><br>\r\nDisplay a message to a user that can edit the current page.\r\n<p>\r\n<i>Example:</i> &#94;CanEditText(^AdminToggle;);\r\n<p>\r\n\r\n<b>&#94;EditableToggle; or &#94;EditableToggle();</b><br>\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<p>\r\n\r\n<b>&#94;GroupText();</b><br>\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<p>\r\n<i>Example:</i> &#94;GroupText("Visitors","You need an account to do anything cool on this site!","We value our registered users!");\r\n<p>\r\n\r\n<b>&#94;L; or &#94;L(); - Login Box</b><br>\r\nA small login form. You can also configure this macro. You can set the width of the login box like this &#94;L(20);. You can also set the message displayed after the user is logged in like this &#94;L(20,Hi &#94;a(&#94;@;);. Click %here% if you wanna log out!)\r\n<p>\r\n\r\n<b>NOTE:</b> The .loginBox style sheet class is tied to this macro.\r\n<p>\r\n\r\n<b>&#94;LoginToggle; or &#94;LoginToggle();</b><br>\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: &#94;LoginToggle("Click here to log in.","Click here to log out.");. You can also use the special case &#94;LoginToggle(linkonly); to return only the URL with no label.\r\n<p>\r\n\r\n<b>&#94;@; - Username</b><br>\r\nThe username of the currently logged in user.\r\n<p>\r\n\r\n\r\n<b>&#94;#; - User ID</b><br>\r\nThe user id of the currently logged in user.\r\n<p>\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 <i>Manage Group</i> for a description of grouping functions and the default groups.\r\n<p>\r\n\r\n<b>Group Name</b><br>\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<p>\r\n\r\n<b>Description</b><br>\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<p>\r\n\r\n<b>Expire Offset</b><br>\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<p>\r\n<b>NOTE:</b> This can be overridden on a per-user basis.\r\n<p>\r\n\r\n<b>Notify user about expiration?</b><br>\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<p>\r\n\r\n<b>Expire Notification Offset</b><br>\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 <b>before</b> the grouping expires. Set it to "7" if you wish the notification to be sent 7 days after the expiration.\r\n<p>\r\n\r\n<b>Expire Notification Message</b><br>\r\nType the message you wish to be sent to the user telling them about the expiration.\r\n<p>\r\n\r\n<b>Delete Offset</b><br>\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 <b>before</b> the grouping expires. Set it to "7" if you wish the grouping to be deleted 7 days after the expiration.\r\n<p>\r\n\r\n<b>IP Address</b><br>\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<p>\r\n<i>IP Mask Example:</i> 10.;192.168.;101.42.200.142\r\n<p>\r\n\r\n<b>Karma Threshold</b><br>\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<p>\r\n\r\n\r\n<b>Users can add themselves?</b><br>\r\nDo you wish to let users add themselves to this group? See the GroupAdd macro for more info.\r\n<p>\r\n\r\n<b>Users can remove themselves?</b><br>\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<p/>\r\n\r\n<b>&#94;a; or &#94;a(); - My Account Link</b><br>\r\nA link to your account information. In addition you can change the link text by creating a macro like this <b>&#94;a("Account Info");</b>. \r\n<p>\r\n\r\n<b>NOTES:</b> You can also use the special case &#94;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<p>\r\n\r\n\r\n<b>&#94;AdminText();</b><br>\r\nDisplays a small text message to a user who is in admin mode. Example: &#94;AdminText("You are in admin mode!");\r\n<p>\r\n\r\n<b>&#94;AdminToggle; or &#94;AdminToggle();</b><br>\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: &#94;AdminToggle("Edit On","Edit Off");\r\n<p>\r\n\r\n<b>&#94;CanEditText();</b><br>\r\nDisplay a message to a user that can edit the current page.\r\n<p>\r\n<i>Example:</i> &#94;CanEditText(^AdminToggle;);\r\n<p>\r\n\r\n<b>&#94;EditableToggle; or &#94;EditableToggle();</b><br>\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<p>\r\n\r\n<b>&#94;GroupAdd();</b><br>\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<p>\r\n<b>NOTE:</b> 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<p>\r\n\r\n\r\n<b>&#94;GroupDelete();</b><br>\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<p>\r\n<b>NOTE:</b> 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<p>\r\n\r\n<b>&#94;GroupText();</b><br>\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<p>\r\n<i>Example:</i> &#94;GroupText("Visitors","You need an account to do anything cool on this site!","We value our registered users!");\r\n<p>\r\n\r\n<b>&#94;L; or &#94;L(); - Login Box</b><br>\r\nA small login form. You can also configure this macro. You can set the width of the login box like this &#94;L(20);. You can also set the message displayed after the user is logged in like this &#94;L(20,Hi &#94;a(&#94;@;);. Click %here% if you wanna log out!)\r\n<p>\r\n\r\n<b>NOTE:</b> The .loginBox style sheet class is tied to this macro.\r\n<p>\r\n\r\n<b>&#94;LoginToggle; or &#94;LoginToggle();</b><br>\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: &#94;LoginToggle("Click here to log in.","Click here to log out.");. You can also use the special case &#94;LoginToggle(linkonly); to return only the URL with no label.\r\n<p>\r\n\r\n<b>&#94;@; - Username</b><br>\r\nThe username of the currently logged in user.\r\n<p>\r\n\r\n\r\n<b>&#94;#; - User ID</b><br>\r\nThe user id of the currently logged in user.\r\n<p>\r\n\r\n', 1053779917,NULL);

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();
}

View file

@ -89,6 +89,8 @@ function returnSelected(in_values) {
<option value='^a("Account Info");'>My Account Link</option>
<option value='^CanEditText("You can edit this page.");'>Can Edit Page Message</option>
<option value='^AdminText("You are in admin mode!");'>Admin Mode Message</option>
<option value='GroupAdd("Newsletter","Click here to join our newsletter.");
<option value='GroupDelete("Newsletter","Click here to unsubscribe from our newsletter.");
<option value='^GroupText("Visitors","You need an account to do anything cool on this site!");'>Group Message</option>
<option value='^EditableToggle;'>Page Editable Toggle</option>
<option value='^AdminToggle;'>Admin Toggle</option>