From: Chris W. <la...@us...> - 2001-12-28 15:33:10
|
Update of /cvsroot/openinteract/OpenInteract/pkg/base_security/OpenInteract In directory usw-pr-cvs1:/tmp/cvs-serv13756 Modified Files: Security.pm Log Message: first step of factoring out the SQL generation so it can be called from outside the module Index: Security.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_security/OpenInteract/Security.pm,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Security.pm 2001/09/14 03:34:31 1.11 --- Security.pm 2001/12/28 15:33:06 1.12 *************** *** 22,25 **** --- 22,27 ---- sub fetch_by_object { my ( $class, $item, $p ) = @_; + $p ||= {}; + my $R = OpenInteract::Request->instance; my $object_id = $p->{oid} || $p->{object_id}; *************** *** 34,64 **** die $msg; } - - my ( $obj_class, $oid ) = $class->_get_class_and_oid({ - %{ $p }, - object_id => $object_id, - item => $item } ); - - my $where = 'class = ? AND object_id = ? AND ( scope = ?'; - my @value = ( $obj_class, $oid, SEC_SCOPE_WORLD ); - - # Setup the group and user search clauses - - my ( $group_where, $group_value ) = $class->_build_group_sql( $p ); - if ( $group_where ) { $where .= " OR $group_where " } - if ( scalar @{ $group_value } ) { push @value, @{ $group_value } } - - my ( $user_where, $user_value ) = $class->_build_user_sql( $p ); - if ( $user_where ) { $where .= " OR $user_where " } - if ( scalar @{ $user_value } ) { push @value, @{ $user_value } } ! $where .= ')'; ! $R->DEBUG && $R->scrib( 2, "Searching clause: $where\n", ! "with values ", join( '//', @value ) ); # Fetch the objects my $sec_list = eval { $class->fetch_group({ where => $where, ! value => \@value }) }; if ( $@ ) { $SPOPS::Error::user_msg = 'Cannot retrieve security settings'; --- 36,53 ---- die $msg; } ! my ( $object_class ); ! ( $object_class, $object_id ) = ! $class->_get_class_and_oid({ %{ $p }, ! object_id => $object_id, ! item => $item }); + my ( $table, $where, $value ) = $class->build_security_sql({ %{ $p }, + object_class => $object_class, + object_id => $object_id }); # Fetch the objects my $sec_list = eval { $class->fetch_group({ where => $where, ! value => $value }) }; if ( $@ ) { $SPOPS::Error::user_msg = 'Cannot retrieve security settings'; *************** *** 88,91 **** --- 77,106 ---- return undef unless ( $found_item ); return \%items; + } + + + + sub build_security_sql { + my ( $class, $p ) = @_; + + my $R = OpenInteract::Request->instance; + + my $where = 'class = ? AND object_id = ? AND ( scope = ?'; + my @value = ( $p->{object_class}, $p->{object_id}, SEC_SCOPE_WORLD ); + + # Setup the group and user search clauses + + my ( $group_where, $group_value ) = $class->_build_group_sql( $p ); + if ( $group_where ) { $where .= " OR $group_where " } + if ( scalar @{ $group_value } ) { push @value, @{ $group_value } } + + my ( $user_where, $user_value ) = $class->_build_user_sql( $p ); + if ( $user_where ) { $where .= " OR $user_where " } + if ( scalar @{ $user_value } ) { push @value, @{ $user_value } } + + $where .= ')'; + $R->DEBUG && $R->scrib( 2, "Searching clause: $where\n", + "with values ", join( '//', @value ) ); + return ( $class->table_name, $where, \@value ); } |