|
From: Chris W. <la...@us...> - 2001-10-24 16:35:52
|
Update of /cvsroot/openinteract/OpenInteract/pkg/base_error/OpenInteract/Handler
In directory usw-pr-cvs1:/tmp/cvs-serv16508/OpenInteract/Handler
Modified Files:
Error.pm
Log Message:
rewrite entirely the handler to display and manipulate errors, to work with OI::CommonHandler
Index: Error.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/pkg/base_error/OpenInteract/Handler/Error.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Error.pm 2001/10/24 02:49:19 1.10
--- Error.pm 2001/10/24 16:35:49 1.11
***************
*** 4,11 ****
use strict;
use SPOPS::Secure qw( :level );
use Text::Wrap qw();
! @OpenInteract::Handler::Error::ISA = qw( OpenInteract::Handler::GenericDispatcher SPOPS::Secure );
$OpenInteract::Handler::Error::VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
--- 4,13 ----
use strict;
+ use OpenInteract::CommonHandler;
+ use OpenInteract::Handler::GenericDispatcher qw( DEFAULT_SECURITY_KEY );
use SPOPS::Secure qw( :level );
use Text::Wrap qw();
! @OpenInteract::Handler::Error::ISA = qw( OpenInteract::CommonHandler SPOPS::Secure );
$OpenInteract::Handler::Error::VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
***************
*** 14,243 ****
@OpenInteract::Handler::Error::forbidden_methods = ();
%OpenInteract::Handler::Error::security = (
! listing => SEC_LEVEL_READ,
! show => SEC_LEVEL_READ,
! remove => SEC_LEVEL_WRITE,
! notify => SEC_LEVEL_READ,
! );
- use constant MAIN_SCRIPT => '/Error';
! sub listing {
! my ( $class, $p ) = @_;
my $R = OpenInteract::Request->instance;
my $apr = $R->apache;
-
- # See if we were passed any sort directives
-
my $order = $apr->param( 'sort' ) || 'error_time';
! my $db_order = ( $order eq 'error_time' ) ? 'error_time DESC' : $order;
!
! # See if we were passed any filtering directives -- if so process
! # them so we can determine which error objects to display
!
! my $where = undef;
! my @value = ();
! my %filter = ();
!
! # See if they asked for a particular code
!
! if ( my $filter_code = $apr->param( 'filter_code' ) ) {
! $filter{code} = $filter_code;
! $where = ' AND code = ?';
! push @value, $filter_code;
! }
!
! # See if they asked for a particular type
!
! if ( my $filter_type = $apr->param( 'filter_type' ) ) {
! $filter{type} = $filter_type;
! $where = ' AND type = ?';
! push @value, $filter_type;
! }
! # Figure out the date stuff
! if ( my $filter_from_year = $apr->param( 'filter_date_from_year' ) ) {
! my $from_date = $class->date_read( 'filter_date_from' );
! ( $filter{from_year}, $filter{from_month}, $filter{from_day} ) = split /\-/, $from_date;
! $where .= ' AND error_time > ?';
! push @value, $from_date;
}
! if ( my $filter_to_year = $apr->param( 'filter_date_to_year' ) ) {
! my $to_date = $class->date_read( 'filter_date_to' );
! ( $filter{to_year}, $filter{to_month}, $filter{to_day} ) = split /\-/, $to_date;
! $where .= ' AND error_time < ?';
! push @value, $to_date;
}
- $where =~ s/^ AND //;
! my $params = { main_script => MAIN_SCRIPT,
! sort => $order,
! filterby => \%filter,
! error_msg => $p->{error_msg} };
!
! # Now actually retrieve the errors
!
! $params->{error_iterator} = eval { $R->error_object->fetch_iterator({
! order => $db_order,
! where => $where,
! value => \@value }) };
! if ( $@ ) {
! OpenInteract::Error->set( SPOPS::Error->get );
! $OpenInteract::Error::user_msg = 'Cannot retrieve list of errors.';
! $R->throw( { code => 403 } );
! $params->{error_msg} .= "Error retrieving list of errors $OpenInteract::Error::system_msg";
! }
- # Set the template and title and we're done.
! $R->{page}->{title} = 'Listing of Errors';
! return $R->template->handler( {}, $params,
! { db => 'error_list',
! package => 'base_error' } );
}
- sub show {
- my ( $class, $p ) = @_;
- my $params = { main_script => MAIN_SCRIPT };
- my $R = OpenInteract::Request->instance;
- my $error = $p->{error};
- $error ||= eval { $R->error_object->fetch( $R->apache->param( 'error_id' ) ) };
- if ( $@ ) {
- my $ei = SPOPS::Error->get;
- if ( $ei->{type} ne 'security' ) {
- $R->throw( { code => 404 } );
- $params->{error_msg} = "Could not retrieve Error object. Error logged.";
- }
- else {
- $params->{error_msg} = "You do not have permission to view this error object.";
- }
- }
! # Grab the user here since sometimes the user might be 'superuser'
! # who cannot be seen by mere mortals. This throws an error if you
! # do in the template [% error_user = err.user %] and rather than a
! # TRY/CATCH block we'll just do it here.
!
! $params->{error_user} = eval { $error->user };
! local $Text::Wrap::columns = 60;
! $error->{system_msg} = Text::Wrap::wrap( '', '', $error->{system_msg} );
! $error->{user_msg} = Text::Wrap::wrap( '', '', $error->{user_msg} );
! $R->{page}->{title} = 'Detail of Error';
! $params->{err} = $error;
! return $R->template->handler( {}, $params,
! { db => 'error_detail',
! package => 'base_error' } );
}
sub remove {
my ( $class, $p ) = @_;
my $R = OpenInteract::Request->instance;
my @error_id = $R->apache->param( 'error_id' );
my ( @error_items );
foreach my $eid ( @error_id ) {
$R->DEBUG && $R->scrib( 1, "Removing error: $eid" );
my $error = eval { $R->error_object->fetch( $eid ); };
if ( $@ or ! $error ) {
! push @error_items, "Could not retrieve error $eid to remove: $SPOPS::Error::system_msg" if ( $@ );
! push @error_items, "Error $eid apparently does not exist, so it was not removed." if ( ! $@ );;
next;
}
! eval { $error->remove; };
! push @error_items, SPOPS::Error->get if ( $@ );
! }
! $p->{error_msg} = join "\n\n", map { $_->{system_msg} } @error_items if ( scalar @error_items );
! return $class->listing( $p );
! }
!
!
! sub notify {
! my ( $class ) = @_;
! my $R = OpenInteract::Request->instance;
! my @error_id = $R->apache->param( 'error_id' );
! my $email = $R->apache->param( 'email' );
! if ( ! $email or ! scalar @error_id ) {
! return '<h2 align="center">Error</h2>' .
! '<p>Error: Cannot notify anyone about an object when no ID/email is given.</p>';
! }
! my @error_list = ();
! foreach my $eid ( @error_id ) {
! my $error = eval { $R->error_object->fetch( $eid ) };
! push @error_list, $error if ( $error );
! }
! if ( $R->error_object->notify({ email => $email,
! subject => 'Error object notification',
! object => \@error_list,
! type => 'error' } ) ) {
! return '<h2 align="center">Success!</h2>' .
! '<p>Notification sent properly!</p>';
}
! return '<h2 align="center">Error</h2>' .
! '<p>Error sending email. Please check error logs!</p>';
}
1;
-
- __END__
-
- =pod
-
- =head1 NAME
-
- OpenInteract::Handler::Error - Browse the error logs
-
- =head1 SYNOPSIS
-
- =head1 DESCRIPTION
-
- This module has four simple handlers to deal with error messages
- currently logged:
-
- =over 4
-
- =item *
-
- B<list>: Display all messages, or those that fit the filter
-
- =item *
-
- B<show>: Display detail regarding a particular message
-
- =item *
-
- B<remove>: Delete one or more messages from the system
-
- =item *
-
- B<notify>: Send via email one or more messages
-
- =back
-
- =head1 TO DO
-
- B<Page?>
-
- Should we page results?
-
- B<Change initial page?>
-
- Should the initial page be just the filter component so people can
- browse by date without seeing ALL the errors?
-
- =head1 BUGS
-
- =head1 COPYRIGHT
-
- Copyright (c) 2001 intes.net, inc.. All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the same terms as Perl itself.
-
- =head1 AUTHORS
-
- Chris Winters <ch...@cw...>
-
- =cut
--- 16,118 ----
@OpenInteract::Handler::Error::forbidden_methods = ();
%OpenInteract::Handler::Error::security = (
! DEFAULT_SECURITY_KEY() => SEC_LEVEL_READ, remove => SEC_LEVEL_WRITE );
! sub MY_PACKAGE { return 'base_error' }
! sub MY_HANDLER_PATH { return '/Error' }
! sub MY_OBJECT_TYPE { return 'error' }
! sub MY_OBJECT_CLASS { return OpenInteract::Request->instance->error }
! sub MY_SEARCH_FIELDS { return qw( code type) }
! sub MY_SEARCH_FORM_TITLE { return 'Search for Errors' }
! sub MY_SEARCH_FORM_TEMPLATE { return 'error_search_form' }
! sub MY_SEARCH_RESULTS_TITLE { return 'Error Search Results' }
! sub MY_SEARCH_RESULTS_TEMPLATE { return 'error_search_results' }
! sub MY_OBJECT_FORM_TITLE { return 'Error Detail' }
! sub MY_OBJECT_FORM_TEMPLATE { return 'error_detail' }
! sub MY_ALLOW_SEARCH_FORM { return 1 }
! sub MY_ALLOW_SEARCH { return 1 }
! sub MY_ALLOW_SHOW { return 1 }
! sub MY_ALLOW_REMOVE { return 1 }
! sub MY_ALLOW_NOTIFY { return 1 }
!
! sub MY_SEARCH_RESULTS_ORDER {
my $R = OpenInteract::Request->instance;
my $apr = $R->apache;
my $order = $apr->param( 'sort' ) || 'error_time';
! return ( $order eq 'error_time' ) ? 'error_time DESC' : $order;
! }
! sub _search_build_where_customize {
! my ( $class, $from, $where, $value ) = @_;
! my $R = OpenInteract::Request->instance;
! my $apr = $R->apache;
! if ( my $from_date = $class->_read_field_date( 'filter_date_from' ) ) {
! push @{ $where }, 'error_time >= ?';
! push @{ $value }, $from_date;
}
! if ( my $to_date = $class->_read_field_date( 'filter_date_to' ) ) {
! push @{ $where }, 'error_time <= ?';
! push @{ $value }, $to_date;
}
! }
! sub _search_customize {
! my ( $class, $params ) = @_;
! my $apr = OpenInteract::Request->instance->apache;
! my %filter = (
! sort => $apr->param( 'sort' ),
! code => $apr->param( 'code' ),
! type => $apr->param( 'type' ),
! date_from => $class->_read_field_date_object( 'filter_date_from' ),
! date_to => $class->_read_field_date_object( 'filter_date_to' ),
! );
! $params->{filterby} = \%filter;
}
! # Grab the user here since sometimes the user might be 'superuser'
! # who cannot be seen by mere mortals. This throws an error if you
! # do in the template [% error_user = err.user %] and rather than a
! # TRY/CATCH block we'll just do it here.
! sub _show_customize {
! my ( $class, $params ) = @_;
! $params->{error_user} = eval { $params->{error}->user };
}
+ # Override 'remove()' so we can delete multiple objects at once
sub remove {
my ( $class, $p ) = @_;
my $R = OpenInteract::Request->instance;
+ unless ( $class->MY_ALLOW_REMOVE ) {
+ $R->scrib( 0, "User tried to remove error object - not allowed." );
+ return '<h2>Error</h2><p>Removal of error objects has been disallowed.</p>';
+ }
+
my @error_id = $R->apache->param( 'error_id' );
my ( @error_items );
+ my $success = 0;
foreach my $eid ( @error_id ) {
$R->DEBUG && $R->scrib( 1, "Removing error: $eid" );
my $error = eval { $R->error_object->fetch( $eid ); };
if ( $@ or ! $error ) {
! push @error_items, "Could not retrieve error ($eid) to remove: $SPOPS::Error::system_msg" if ( $@ );
! push @error_items, "Error ($eid) apparently does not exist, so it was not removed." if ( ! $@ );;
next;
}
! eval { $error->remove };
! if ( $@ ) { push @error_items, SPOPS::Error->get }
! else { $success++ }
}
! $p->{error_msg} = join "\n\n", map { $_->{system_msg} } @error_items if ( scalar @error_items );
! $p->{status_msg} = "$success objects removed successfully";
! return $class->search_form( $p );
}
1;
|