Added scratch filter to groups.
This commit is contained in:
parent
13e1a253dd
commit
4f3859724b
7 changed files with 90 additions and 28 deletions
|
|
@ -79,6 +79,8 @@ Tie::CPHash..........................Christopher J. Madsen
|
|||
|
||||
Tie::IxHash..........................Gurusamy Sarathy
|
||||
|
||||
Tree::DAG_Node.......................Sean M. Burke
|
||||
|
||||
XML::RSSLite.........................Jerrad Pierce
|
||||
Scott Thomason
|
||||
|
||||
|
|
@ -86,6 +88,7 @@ Midas................................The Mozilla Development Team
|
|||
Mike Kaply
|
||||
|
||||
HTML Area............................interactivetools.com
|
||||
The Open Source Community
|
||||
|
||||
Classic Rich Edit....................Bratta
|
||||
|
||||
|
|
|
|||
|
|
@ -457,4 +457,8 @@ insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (3, 'DataForm'
|
|||
INSERT INTO template VALUES (1,'Mail Form','<tmpl_if displayTitle>\n <h1><tmpl_var title></h1>\n</tmpl_if>\n\n<tmpl_loop error_loop>\n <li><b><tmpl_var error.message></b>\n</tmpl_loop>\n\n\n<tmpl_if description>\n <tmpl_var description><p />\n</tmpl_if>\n\n<tmpl_if session.var.adminOn><tmpl_if canEdit>\n <a href=\"<tmpl_var addField.url>\"><tmpl_var addField.label></a>\n · <a href=\"<tmpl_var export.tab.url>\"><tmpl_var export.tab.label></a>\n <p /> \n</tmpl_if></tmpl_if>\n\n<tmpl_var form.start>\n<table>\n<tmpl_loop field_loop>\n <tmpl_unless field.isHidden>\n <tr><td class=\"formDescription\" valign=\"top\">\n <tmpl_if session.var.adminOn><tmpl_if canEdit><tmpl_var field.controls></tmpl_if></tmpl_if>\n <tmpl_var field.label>\n </td><td class=\"tableData\" valign=\"top\">\n <tmpl_if field.isDisplayed>\n <tmpl_var field.value>\n <tmpl_else>\n <tmpl_var field.form>\n </tmpl_if>\n <tmpl_if field.required>*</tmpl_if>\n <span class=\"formSubtext\"><br /><tmpl_var field.subtext></span>\n </td></tr>\n </tmpl_unless>\n</tmpl_loop>\n<tr><td></td><td><tmpl_var form.send></td></tr>\n</table>\n\n<tmpl_var form.end>\n','DataForm');
|
||||
INSERT INTO template VALUES (2,'Default Email','<tmpl_var edit.url>\n\n<tmpl_loop field_loop><tmpl_unless field.isMailField><tmpl_var field.label>: <tmpl_var field.value>\n</tmpl_unless></tmpl_loop>','DataForm');
|
||||
INSERT INTO template VALUES (3,'Default Acknowlegement','<tmpl_var acknowlegement>\n<p />\n<table border=\"0\">\n<tmpl_loop field_loop>\n<tmpl_unless field.isMailField><tmpl_unless field.hidden>\n <tr><td class=\"tableHeader\"><tmpl_var field.label></td>\n <td class=\"tableData\"><tmpl_var field.value></td></tr>\n</tmpl_unless></tmpl_unless>\n</tmpl_loop>\n</table>\n<p />\n<a href=\"<tmpl_var back.url>\"><tmpl_var back.label></a>','DataForm');
|
||||
alter table groups add column scratchFilter text;
|
||||
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (945,1,'WebGUI','Scratch Filter', 1052560369,'There is a type of session variable called a "scratch" variable. So a scratch filter allows you to add someone to a group based upon a scratch variable.');
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ This package provides an object-oriented way of managing WebGUI groups and group
|
|||
$string = $g->ipFilter("10.;192.168.1.");
|
||||
$epoch = $g->lastUpdated;
|
||||
$string = $g->name("Nerds");
|
||||
$string = $g->scratchFilter("www_location=International;somesetting=1");
|
||||
|
||||
$g->addGroups(\@arr);
|
||||
$g->deleteGroups(\@arr);
|
||||
|
|
@ -457,6 +458,34 @@ sub new {
|
|||
bless {_groupId => $groupId, _group => \%group }, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 scratchFilter ( [ value ] )
|
||||
|
||||
Returns the name of this group.
|
||||
|
||||
=over
|
||||
|
||||
=item value
|
||||
|
||||
If specified, the name is set to this value.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub scratchFilter {
|
||||
my ($class, $value);
|
||||
$class = shift;
|
||||
$value = shift;
|
||||
if (defined $value) {
|
||||
$class->{_group}{"scratchFilter"} = $value;
|
||||
WebGUI::SQL->write("update groups set scratchFilter=".quote($value).",
|
||||
lastUpdated=".time()." where groupId=$class->{_groupId}");
|
||||
}
|
||||
return $class->{_group}{"scratchFilter"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ sub getGroupsForGroup {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getGroupsForUser ( userId )
|
||||
=head2 getGroupsForUser ( userId [ , withoutExpired ] )
|
||||
|
||||
Returns an array reference containing a list of groups the specified user is in.
|
||||
|
||||
|
|
@ -214,12 +214,17 @@ Returns an array reference containing a list of groups the specified user is in.
|
|||
|
||||
A unique identifier for the user.
|
||||
|
||||
=item withoutExpired
|
||||
|
||||
If set to "1" then the listing will not include expired groupings. Defaults to "0".
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub getGroupsForUser {
|
||||
return WebGUI::SQL->buildArrayRef("select groupId from groupings where userId=$_[0]");
|
||||
my $clause = "and expireDate>".time() if ($_[1]);
|
||||
return WebGUI::SQL->buildArrayRef("select groupId from groupings where userId=$_[0] $clause");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -252,9 +257,8 @@ sub getGroupsInGroup {
|
|||
push(@groupsOfGroups, @$gog);
|
||||
}
|
||||
return \@groupsOfGroups;
|
||||
} else {
|
||||
return $groups;
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -141,6 +141,11 @@ sub www_editGroup {
|
|||
-value=>$g->ipFilter,
|
||||
-label=>WebGUI::International::get(857)
|
||||
);
|
||||
$f->textarea(
|
||||
-name=>"scratchFilter",
|
||||
-value=>$g->scratchFilter,
|
||||
-label=>WebGUI::International::get(945)
|
||||
);
|
||||
$f->submit;
|
||||
$output .= $f->print;
|
||||
return _submenu($output);
|
||||
|
|
@ -155,6 +160,7 @@ sub www_editGroupSave {
|
|||
$g->expireOffset(WebGUI::DateTime::intervalToSeconds($session{form}{expireOffset_interval},$session{form}{expireOffset_units}));
|
||||
$g->karmaThreshold($session{form}{karmaThreshold});
|
||||
$g->ipFilter($session{form}{ipFilter});
|
||||
$g->scratchFilter($session{form}{scratchFilter});
|
||||
$g->expireNotify($session{form}{expireNotify});
|
||||
$g->expireNotifyOffset($session{form}{expireNotifyOffset});
|
||||
$g->expireNotifyMessage($session{form}{expireNotifyMessage});
|
||||
|
|
|
|||
|
|
@ -19,12 +19,14 @@ our @EXPORT = qw(&www_setScratch &www_deleteScratch);
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteScratch {
|
||||
WebGUI::Session::deleteScratch("www_".$session{user}{scratchName});
|
||||
WebGUI::Session::deleteScratch("www_".$session{form}{scratchName});
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_setScratch {
|
||||
WebGUI::Session::setScratch("www_".$session{form}{scratchName},$session{form}{scratchValue});
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ package WebGUI::Privilege;
|
|||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Group;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Operation::Account ();
|
||||
use WebGUI::Session;
|
||||
|
|
@ -197,7 +199,7 @@ The user that you wish to verify against the group. Defaults to the currently lo
|
|||
=cut
|
||||
|
||||
sub isInGroup {
|
||||
my ($gid, $uid, @data, %group, %user, $groupId);
|
||||
my ($gid, $uid, @data, %group, $groupId);
|
||||
($gid, $uid) = @_;
|
||||
$uid = $session{user}{userId} if ($uid eq "");
|
||||
### The "Everyone" group automatically returns true.
|
||||
|
|
@ -221,18 +223,18 @@ sub isInGroup {
|
|||
return 1;
|
||||
} elsif ($session{isInGroup}{$gid} eq "0") {
|
||||
return 0;
|
||||
} else {
|
||||
$session{isInGroup}{$gid} = 0;
|
||||
}
|
||||
### Lookup the actual grouping.
|
||||
@data = WebGUI::SQL->quickArray("select count(*) from groupings where groupId='$gid' and userId='$uid' and expireDate>".time());
|
||||
if ($data[0] > 0 && $uid != 1) {
|
||||
$session{isInGroup}{$gid} = 1;
|
||||
### Lookup the actual groupings.
|
||||
my $groups = WebGUI::Grouping::getGroupsForUser($uid,1);
|
||||
foreach (@{$groups}) {
|
||||
$session{isInGroup}{$_} = 1;
|
||||
}
|
||||
if ($session{isInGroup}{$gid} || $session{isInGroup}{3}) {
|
||||
return 1;
|
||||
}
|
||||
### Get data for auxillary checks.
|
||||
tie %group, 'Tie::CPHash';
|
||||
%group = WebGUI::SQL->quickHash("select karmaThreshold,ipFilter from groups where groupId='$gid'");
|
||||
%group = WebGUI::SQL->quickHash("select karmaThreshold,ipFilter,scratchFilter from groups where groupId='$gid'");
|
||||
### Check IP Address
|
||||
if ($group{ipFilter} ne "") {
|
||||
$group{ipFilter} =~ s/\t//g;
|
||||
|
|
@ -247,32 +249,44 @@ sub isInGroup {
|
|||
}
|
||||
}
|
||||
}
|
||||
### Check Scratch Variables
|
||||
if ($group{scratchFilter} ne "") {
|
||||
$group{scratchFilter} =~ s/\t//g;
|
||||
$group{scratchFilter} =~ s/\r//g;
|
||||
$group{scratchFilter} =~ s/\n//g;
|
||||
$group{scratchFilter} =~ s/\s//g;
|
||||
my @vars = split(";",$group{scratchFilter});
|
||||
foreach my $var (@vars) {
|
||||
my ($name, $value) = split(/\=/,$var);
|
||||
if ($session{scratch}{$name} eq $value) {
|
||||
$session{isInGroup}{$gid} = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
### Check karma levels.
|
||||
if ($session{setting}{useKarma}) {
|
||||
tie %user, 'Tie::CPHash';
|
||||
%user = WebGUI::SQL->quickHash("select karma from users where userId='$uid'");
|
||||
if ($user{karma} >= $group{karmaThreshold}) {
|
||||
my $karma;
|
||||
if ($uid == $session{user}{userId}) {
|
||||
$karma = $session{user}{karma};
|
||||
} else {
|
||||
($karma) = WebGUI::SQL->quickHash("select karma from users where userId='$uid'");
|
||||
}
|
||||
if ($karma >= $group{karmaThreshold}) {
|
||||
$session{isInGroup}{$gid} = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
### Admins can do anything!
|
||||
if ($gid != 3 && $session{isInGroup}{3} eq "") {
|
||||
$session{isInGroup}{3} = isInGroup(3, $uid);
|
||||
if ($session{isInGroup}{3}) {
|
||||
$session{isInGroup}{$gid} = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
### Check for groups of groups.
|
||||
@data = WebGUI::SQL->buildArray("select groupId from groupGroupings where inGroup='$gid'");
|
||||
foreach $groupId (@data) {
|
||||
$session{isInGroup}{$groupId} = isInGroup($groupId, $uid);
|
||||
if ($session{isInGroup}{$groupId}) {
|
||||
my $groups = WebGUI::Grouping::getGroupsInGroup($gid,1);
|
||||
foreach (@{$groups}) {
|
||||
$session{isInGroup}{$_} = isInGroup($_, $uid);
|
||||
if ($session{isInGroup}{$_}) {
|
||||
$session{isInGroup}{$gid} = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
$session{isInGroup}{$gid} = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue