[interchange-cvs] interchange - heins modified 6 files
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Tue Jul 9 13:43:00 2002
User: heins
Date: 2002-07-09 17:42:13 GMT
Modified: lib/Vend DbSearch.pm Scan.pm
Modified: lib/Vend/Table Common.pm DBI.pm LDAP.pm Shadow.pm
Log:
* Add new HIDE_FIELD capability to DbSearch. It provides automatic
hiding of records accessed via search (and NOT query).
-When the following configuration is added:
Database products HIDE_FIELD inactive
-It adds automatically the qualification to every search:
WHERE inactive !=3D 1
-To use, you should have a field of char(1) or int type.
Database products COLUMN_DEF "inactive=3Dint default 0"
-This has the side-effect of hiding fields with NULL in the
field, so be careful. You should probably set "default 0"
as shown above.
-Works for DBM types too.
-Does NOT work for TextSearch.
-If you want to show all records, you can pass mv_no_hide=3D1
in the search parameters. Obviously, this makes this not a
security feature.
Revision Changes Path
2.14 +15 -17 interchange/lib/Vend/DbSearch.pm
rev 2.14, prev_rev 2.13
Index: DbSearch.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/DbSearch.pm,v
retrieving revision 2.13
retrieving revision 2.14
diff -u -r2.13 -r2.14
--- DbSearch.pm 23 Jun 2002 01:20:10 -0000 2.13
+++ DbSearch.pm 9 Jul 2002 17:42:12 -0000 2.14
@@ -1,6 +1,6 @@
# Vend::DbSearch - Search indexes with Interchange
#
-# $Id: DbSearch.pm,v 2.13 2002/06/23 01:20:10 jon Exp $
+# $Id: DbSearch.pm,v 2.14 2002/07/09 17:42:12 mheins Exp $
#
# Adapted for use with Interchange from Search::TextSearch
#
@@ -26,7 +26,7 @@
=20
@ISA =3D qw(Vend::Search);
=20
-$VERSION =3D substr(q$Revision: 2.13 $, 10);
+$VERSION =3D substr(q$Revision: 2.14 $, 10);
=20
use Search::Dict;
use strict;
@@ -131,15 +131,11 @@
s:.*/::;
s/\..*//;
}
-#::logDebug ("searching: searchfiles=3D'@searchfiles', obj=3D" . ::uneval(=
$s));
my $dbref =3D $s->{table} || undef;
-#::logDebug("before db mapping: self=3D" . ::Vend::Util::uneval_it({%$s}));
=20
-#::logDebug("searching $searchfiles[0], keys Database before=3D" . join ",=
", grep /backup/, keys %{$Vend::Cfg->{Database}});
if( ! $dbref ) {
$s->{dbref} =3D $dbref =3D Vend::Data::database_exists_ref($searchfiles[=
0]);
}
-#::logDebug("searching $searchfiles[0], keys after=3D" . join ",", grep /=
backup/, keys %{$Vend::Cfg->{Database}});
if(! $dbref) {
return $s->search_error(
"search file '$searchfiles[0]' is not a valid database reference."
@@ -186,11 +182,9 @@
$@ and return $s->search_error("Function creation: $@");
=20
if(ref $s->{mv_like_field} and ref $s->{mv_like_spec}) {
-#::logDebug("Entering like_spec");
my $ary =3D [];
for(my $i =3D 0; $i < @{$s->{mv_like_field}}; $i++) {
my $col =3D $s->{mv_like_field}[$i];
-#::logDebug("Checking column '$col'");
next unless length($col);
my $val =3D $s->{mv_like_spec}[$i];
length($val) or next;
@@ -213,20 +207,18 @@
$s->{eq_specs_sql} =3D [] if ! $s->{eq_specs_sql};
push @{$s->{eq_specs_sql}}, @$ary;
}
-#::logDebug("like_spec: " . join ",", @$ary);
}
=20
my $qual;
if($s->{eq_specs_sql}) {
$qual =3D ' WHERE ';
- my $joiner =3D ' AND ';
- $joiner =3D ' OR ' if $s->{mv_orsearch}[0];
+ my $joiner =3D $s->{mv_orsearch}[0] ? ' OR ' : ' AND ';
$qual .=3D join $joiner, @{$s->{eq_specs_sql}};
}
=20
$s->save_specs();
-#::logDebug("searchfiles=3D@searchfiles");
foreach $searchfile (@searchfiles) {
+ my $lqual =3D $qual || '';
$searchfile =3D~ s/\..*//;
my $db;
if (! $s->{mv_one_sql_table} ) {
@@ -237,8 +229,16 @@
), next;
=20=09=09=09
$dbref =3D $s->{dbref} =3D $db->ref();
+ $dbref->reset();
@fn =3D $dbref->columns();
}
+
+ if(! $s->{mv_no_hide} and my $hf =3D $dbref->config('HIDE_FIELD')) {
+#::logDebug("found hide_field $hf");
+ $lqual =3D~ s/^\s*WHERE\s+/ WHERE $hf !=3D 1 /
+ or $lqual =3D " WHERE $hf !=3D 1";
+#::logDebug("lqual now '$lqual'");
+ }
$s->hash_fields(\@fn);
my $prospect;
eval {
@@ -253,12 +253,11 @@
=20
$@ and return $s->search_error("Return subroutine creation: $@");
=20
-#::logDebug("qual=3D$qual");
if(! defined $f and defined $limit_sub) {
#::logDebug("no f, limit, dbref=3D$dbref");
local($_);
my $ref;
- while($ref =3D $dbref->each_nokey($qual) ) {
+ while($ref =3D $dbref->each_nokey($lqual) ) {
next unless $limit_sub->($ref);
push @out, $return_sub->($ref);
}
@@ -267,7 +266,7 @@
#::logDebug("f and limit, dbref=3D$dbref");
local($_);
my $ref;
- while($ref =3D $dbref->each_nokey($qual) ) {
+ while($ref =3D $dbref->each_nokey($lqual) ) {
$_ =3D join "\t", @$ref;
next unless &$f();
next unless $limit_sub->($ref);
@@ -281,7 +280,7 @@
#::logDebug("f and no limit, dbref=3D$dbref");
local($_);
my $ref;
- while($ref =3D $dbref->each_nokey($qual) ) {
+ while($ref =3D $dbref->each_nokey($lqual) ) {
#::logDebug("f and no limit, ref=3D$ref");
$_ =3D join "\t", @$ref;
next unless &$f();
@@ -366,7 +365,6 @@
$#out =3D $s->{mv_matchlimit} - 1;
}
#::logDebug("after hash fields: self=3D" . ::Vend::Util::uneval_it({%$s}));
-#::logDebug("after delayed return: self=3D" . ::Vend::Util::uneval_it({%$s=
}));
=20
if(! $s->{mv_return_reference}) {
$s->{mv_results} =3D \@out;
2.12 +5 -2 interchange/lib/Vend/Scan.pm
rev 2.12, prev_rev 2.11
Index: Scan.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Scan.pm,v
retrieving revision 2.11
retrieving revision 2.12
diff -u -r2.11 -r2.12
--- Scan.pm 23 Jun 2002 01:20:10 -0000 2.11
+++ Scan.pm 9 Jul 2002 17:42:12 -0000 2.12
@@ -1,6 +1,6 @@
# Vend::Scan - Prepare searches for Interchange
#
-# $Id: Scan.pm,v 2.11 2002/06/23 01:20:10 jon Exp $
+# $Id: Scan.pm,v 2.12 2002/07/09 17:42:12 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -29,7 +29,7 @@
perform_search
);
=20
-$VERSION =3D substr(q$Revision: 2.11 $, 10);
+$VERSION =3D substr(q$Revision: 2.12 $, 10);
=20
use strict;
use Vend::Util;
@@ -76,6 +76,7 @@
mv_more_id
mv_min_string
mv_max_matches
+ mv_no_hide
mv_orsearch
mv_range_min
mv_range_max
@@ -146,6 +147,7 @@
ms mv_min_string
ne mv_negate
ng mv_negate
+ nh mv_no_hide
np mv_nextpage
ns mv_next_search
nu mv_numeric
@@ -195,6 +197,7 @@
mv_substring_match =3D> \&_yes_array,
mv_column_op =3D> \&_array,
mv_coordinate =3D> \&_yes,
+ mv_no_hide =3D> \&_yes,
=20
mv_field_names =3D> \&_array,
mv_spelling_errors =3D> sub { my $n =3D int($_[1]); $n < 8 ? $n : 1=
; },
2.17 +27 -11 interchange/lib/Vend/Table/Common.pm
rev 2.17, prev_rev 2.16
Index: Common.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/Common.pm,v
retrieving revision 2.16
retrieving revision 2.17
diff -u -r2.16 -r2.17
--- Common.pm 9 Jul 2002 01:59:59 -0000 2.16
+++ Common.pm 9 Jul 2002 17:42:12 -0000 2.17
@@ -1,6 +1,6 @@
# Vend::Table::Common - Common access methods for Interchange databases
#
-# $Id: Common.pm,v 2.16 2002/07/09 01:59:59 jon Exp $
+# $Id: Common.pm,v 2.17 2002/07/09 17:42:12 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -22,7 +22,7 @@
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.
=20
-$VERSION =3D substr(q$Revision: 2.16 $, 10);
+$VERSION =3D substr(q$Revision: 2.17 $, 10);
use strict;
=20
package Vend::Table::Common;
@@ -557,19 +557,27 @@
my $sup;
my $restrict;
my $rfield;
+my $hfield;
my $rsession;
=20
sub each_nokey {
- my ($s) =3D @_;
+ my ($s, $qual) =3D @_;
$s =3D $s->import_db() if ! defined $s->[$TIE_HASH];
my ($key);
=20
- if (
- ! defined $restrict
- and=20
- $restrict =3D ($Vend::Cfg->{TableRestrict}{$s->config('name')} || 0)
- )
- {
+ if (! defined $restrict) {
+ # Support hide_field
+ if($qual) {
+#::logDebug("Found qual=3D$qual");
+ $hfield =3D $qual;
+ if($hfield =3D~ s/^\s+WHERE\s+(\w+)\s*!=3D\s*1($|\s+)//) {
+ my $hf =3D $1;
+#::logDebug("Found hf=3D$hf");
+ $s->test_column($hf) and $hfield =3D $s->column_index($hf);
+ }
+#::logDebug("hf index=3D$hfield");
+ }
+ if($restrict =3D ($Vend::Cfg->{TableRestrict}{$s->config('name')} || 0))=
{
#::logDebug("restricted?");
$sup =3D ! defined $Global::SuperUserFunction
||
@@ -584,6 +592,8 @@
$rsession =3D $Vend::Session->{$rsession};
}
}
+ $restrict =3D 1 if $hfield and $s->[$CONFIG]{HIDE_FIELD} eq $hfield;
+ }
=20
for (;;) {
$key =3D each %{$s->[$TIE_HASH]};
@@ -595,8 +605,10 @@
$key =3D~ s/^k// or next;
if($restrict) {
my (@row) =3D $s->row($key);
-##::logDebug("each_nokey: '$row[$rfield]' eq '$rsession' ??");
- next if $row[$rfield] ne $rsession;
+#::logDebug("each_nokey: rfield=3D'$row[$rfield]' eq '$rsession' ??") if d=
efined $rfield;
+#::logDebug("each_nokey: hfield=3D'$row[$hfield]'") if defined $hfield;
+ next if defined $hfield and $row[$hfield];
+ next if defined $rfield and $row[$rfield] ne $rsession;
return \@row;
}
return [ $s->row($key) ];
@@ -1404,6 +1416,10 @@
}
$expect and push @a, '';
return @a;
+}
+
+sub reset {
+ undef $restrict;
}
=20
1;
2.22 +3 -2 interchange/lib/Vend/Table/DBI.pm
rev 2.22, prev_rev 2.21
Index: DBI.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/DBI.pm,v
retrieving revision 2.21
retrieving revision 2.22
diff -u -r2.21 -r2.22
--- DBI.pm 9 Jul 2002 00:03:20 -0000 2.21
+++ DBI.pm 9 Jul 2002 17:42:12 -0000 2.22
@@ -1,6 +1,6 @@
# Vend::Table::DBI - Access a table stored in an DBI/DBD database
#
-# $Id: DBI.pm,v 2.21 2002/07/09 00:03:20 jon Exp $
+# $Id: DBI.pm,v 2.22 2002/07/09 17:42:12 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -20,7 +20,7 @@
# MA 02111-1307 USA.
=20
package Vend::Table::DBI;
-$VERSION =3D substr(q$Revision: 2.21 $, 10);
+$VERSION =3D substr(q$Revision: 2.22 $, 10);
=20
use strict;
=20
@@ -1790,6 +1790,7 @@
return wantarray ? ($ref, \%nh, \@na) : $ref;
}
=20
+*reset =3D \&Vend::Table::Common::reset;
*autonumber =3D \&Vend::Table::Common::autonumber;
=20
1;
2.4 +3 -2 interchange/lib/Vend/Table/LDAP.pm
rev 2.4, prev_rev 2.3
Index: LDAP.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/LDAP.pm,v
retrieving revision 2.3
retrieving revision 2.4
diff -u -r2.3 -r2.4
--- LDAP.pm 27 Jun 2002 22:24:10 -0000 2.3
+++ LDAP.pm 9 Jul 2002 17:42:12 -0000 2.4
@@ -1,6 +1,6 @@
# Vend::Table::LDAP - Interchange LDAP pseudo-table access
#
-# $Id: LDAP.pm,v 2.3 2002/06/27 22:24:10 jon Exp $
+# $Id: LDAP.pm,v 2.4 2002/07/09 17:42:12 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -24,7 +24,7 @@
=20
package Vend::Table::LDAP;
@ISA =3D qw/Vend::Table::Common/;
-$VERSION =3D substr(q$Revision: 2.3 $, 10);
+$VERSION =3D substr(q$Revision: 2.4 $, 10);
use strict;
=20
use vars qw(
@@ -663,6 +663,7 @@
*column_exists =3D \&Vend::Table::Common::column_exists;
*numeric =3D \&Vend::Table::Common::numeric;
*isopen =3D \&Vend::Table::Common::isopen;
+*reset =3D \&Vend::Table::Common::reset;
*suicide =3D \&Vend::Table::Common::suicide;
*test_column =3D \&Vend::Table::Common::test_column;
=20
1.4 +8 -2 interchange/lib/Vend/Table/Shadow.pm
rev 1.4, prev_rev 1.3
Index: Shadow.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/Shadow.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Shadow.pm 27 May 2002 12:52:43 -0000 1.3
+++ Shadow.pm 9 Jul 2002 17:42:12 -0000 1.4
@@ -1,6 +1,6 @@
# Vend::Table::Shadow - Access a virtual "Shadow" table
#
-# $Id: Shadow.pm,v 1.3 2002/05/27 12:52:43 racke Exp $
+# $Id: Shadow.pm,v 1.4 2002/07/09 17:42:12 mheins Exp $
#
# Copyright (C) 2002 Stefan Hornburg (Racke) <racke@linuxia.de>
#
@@ -20,7 +20,7 @@
# MA 02111-1307 USA.
=20
package Vend::Table::Shadow;
-$VERSION =3D substr(q$Revision: 1.3 $, 10);
+$VERSION =3D substr(q$Revision: 1.4 $, 10);
=20
# TODO
#
@@ -117,6 +117,12 @@
$s =3D $s->import_db() unless defined $s->[$OBJ];
::logDebug('COLUMNS: ' . $s->columns());
return $s->[$OBJ]->each_nokey($qual);
+}
+
+sub reset {
+ my ($s, $key) =3D @_;
+ $s =3D $s->import_db() unless defined $s->[$OBJ];
+ $s->[$OBJ]->reset();
}
=20
1;