From: Chris W. <la...@us...> - 2005-03-04 15:22:58
|
Update of /cvsroot/openinteract/OpenInteract2/pkg/comments/OpenInteract2/Action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7846/OpenInteract2/Action Modified Files: Comments.pm Added Files: CommentAdmin.pm Log Message: OIN-119: be able to disable comments for an individual object or for an entire class of objects -- new action (comment_admin) as well as SPOPS object (comment_disable) --- NEW FILE: CommentAdmin.pm --- package OpenInteract2::Action::CommentAdmin; # $Id: CommentAdmin.pm,v 1.1 2005/03/04 15:22:10 lachoy Exp $ use strict; use base qw( OpenInteract2::Action ); $OpenInteract2::Action::CommentAdmin::VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/); sub list { my ( $self ) = @_; my $disabled = OpenInteract2::CommentDisable->fetch_group({ order => 'disabled_on DESC', }); return $self->generate_content({ disabled_list => $disabled }); } sub disable { my ( $self ) = @_; $self->param_from_request( 'class', 'object_id' ); my $c_class = $self->param( 'class' ); if ( $c_class ) { my $id = $self->param( 'object_id' ); eval { OpenInteract2::CommentDisable->disable( $c_class, $id ) }; if ( $@ ) { $self->add_error_key( 'comments.error.add_disable', "$@" ); } else { $id ||= 'ALL'; $self->add_status_key( 'comments.status.add_disable_ok', $c_class, $id ); } } else { $self->add_error_key( 'comments.error.disable_no_class' ); } return $self->execute({ task => 'list' }); } sub enable { my ( $self ) = @_; my $disable_id = $self->param( 'disable_id' ); my ( $c_class, $c_id, $error ); if ( $disable_id ) { eval { my $disable = OpenInteract2::CommentDisable->fetch( $disable_id ); $c_class = $disable->{class}; $c_id = $disable->{object_id}; $disable->remove(); }; if ( $@ ) { $error = $@; } } else { $self->param_from_request( 'class', 'object_id' ); $c_class = $self->param( 'class' ); if ( $c_class ) { $c_id = $self->param( 'object_id' ); eval { OpenInteract2::CommentDisable->enable( $c_class, $c_id ) }; if ( $@ ) { $error = $@; } else { $self->add_error_key( 'comments..error.remove_disable_no_class' ); } } } if ( $error ) { $self->add_error_key( 'comments.error.remove_disable', "$@" ); } elsif ( $c_class ) { $c_id ||= 'ALL'; $self->add_status_key( 'comments.status.remove_disable_ok', $c_class, $c_id ); } return $self->execute({ task => 'list' }); } 1; Index: Comments.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/pkg/comments/OpenInteract2/Action/Comments.pm,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Comments.pm 3 Mar 2005 13:08:57 -0000 1.14 --- Comments.pm 4 Mar 2005 15:22:10 -0000 1.15 *************** *** 26,34 **** $log ||= get_logger( LOG_APP ); ! my $object = $self->param( 'object' ); ! my $obj_class = $self->param( 'class' ); ! my $obj_id = $self->param( 'object_id' ); ! ! unless ( $object and ! ( $obj_class and $obj_id ) ) { $log->warn( "Cannot display summary: no object or ", "object class + ID given" ); --- 26,31 ---- $log ||= get_logger( LOG_APP ); ! my ( $obj_class, $obj_id ) = $self->_get_class_and_id; ! unless ( $obj_class and $obj_id ) { $log->warn( "Cannot display summary: no object or ", "object class + ID given" ); *************** *** 38,46 **** my %params = (); - # This doesn't HAVE to be a commentable object, so... - - $obj_class ||= ref $object; - $obj_id ||= $object->id; - $log->is_debug && $log->debug( "Fetching summary for '$obj_class: $obj_id'" ); --- 35,38 ---- *************** *** 48,52 **** OpenInteract2::CommentSummary->fetch_group({ where => 'class = ? AND object_id = ?', ! value => [ $obj_class, scalar $obj_id ], }) }; --- 40,44 ---- OpenInteract2::CommentSummary->fetch_group({ where => 'class = ? AND object_id = ?', ! value => [ $obj_class, $obj_id ], }) }; *************** *** 66,72 **** num_comments => 0, class => $obj_class, ! obj_id => $obj_id }); ! $object = eval { $obj_class->fetch( $obj_id ) }; if ( $@ ) { $log->error( "FAILURE: Cannot fetch for summary object ", --- 58,64 ---- num_comments => 0, class => $obj_class, ! object_id => $obj_id }); ! my $object = eval { $obj_class->fetch( $obj_id ) }; if ( $@ ) { $log->error( "FAILURE: Cannot fetch for summary object ", *************** *** 151,175 **** $log ||= get_logger( LOG_APP ); ! my $object = $self->param( 'object' ); ! my $request = CTX->request; ! if ( $object ) { ! $log->is_debug && ! $log->debug( "Object passed in to display comments: ", ! "[", ref( $object ), ": ", $object->id, "]" ); } ! else { ! $log->is_debug && ! $log->debug( "Object not passed in, using class and object_id ", ! "from action or request params" ); ! my $obj_class = $self->param( 'class' ) || ! $request->param( 'class' ); ! my $obj_id = $self->param( 'object_id' ) || ! $request->param( 'object_id' ); ! unless ( $obj_class and $obj_id ) { ! $log->error( 'Class/object_id not given to find object' ); ! return $self->_msg( 'comments.error.list_for_object_data_missing' ); ! } ! $object = eval { $obj_class->fetch( $obj_id ) }; if ( $@ ) { --- 143,157 ---- $log ||= get_logger( LOG_APP ); ! $self->param_from_request( 'class', 'object_id' ); ! my ( $obj_class, $obj_id ) = $self->_get_class_and_id(); ! unless ( $obj_class and $obj_id ) { ! $log->error( 'Class/object_id not given to find object' ); ! return $self->_msg( 'comments.error.list_for_object_data_missing' ); } ! $log->is_debug && ! $log->debug( "Will display comments for [$obj_class: $obj_id]" ); ! my $object = $self->param( 'object' ); ! unless ( $object ) { $object = eval { $obj_class->fetch( $obj_id ) }; if ( $@ ) { *************** *** 186,190 **** OpenInteract2::Comment->fetch_group({ where => 'class = ? and object_id = ?', ! value => [ ref $object, scalar( $object->id ) ], order => 'posted_on ASC' }) --- 168,172 ---- OpenInteract2::Comment->fetch_group({ where => 'class = ? and object_id = ?', ! value => [ $obj_class, $obj_id ], order => 'posted_on ASC' }) *************** *** 301,313 **** sub show_empty_form { my ( $self ) = @_; ! my $comment = $self->_fill_in_default_comment(); ! my $has_cookie = $self->_has_cookie(); ! my $is_subscribed = ( $has_cookie ) ! ? $self->_is_subscribed( $comment ) : 0; ! my %params = ( ! comment => $comment, ! remember_poster => $has_cookie ? 'yes' : '', ! is_subscribed => $is_subscribed ? 'yes' : 'no', ); return $self->generate_content( \%params, { name => 'comments::comment_form' } ); --- 283,308 ---- sub show_empty_form { my ( $self ) = @_; ! $log ||= get_logger( LOG_APP ); ! my ( $object_class, $object_id ) = $self->_get_class_and_id(); ! my %params = (); ! $params{is_disabled} = OpenInteract2::CommentDisable->is_disabled( ! $object_class, $object_id, ); + if ( $params{is_disabled} ) { + $log->is_info && + $log->info( "Comments are disabled for [$object_class $object_id] ", + "(may be all objects in class are disabled)" ); + } + else { + $params{comment} = $self->_fill_in_default_comment(); + $params{has_cookie} = $self->_has_cookie() ? 'yes' : 'no'; + if ( $params{has_cookie} ) { + $params{is_subscribed} = + $self->_is_subscribed( $params{comment} ) ? 'yes' : 'no'; + } + else { + $params{is_subscribed} = 'no'; + } + } return $self->generate_content( \%params, { name => 'comments::comment_form' } ); *************** *** 343,358 **** } my $object = $self->param( 'object' ); if ( $object ) { ! $comment->{class} = ref $object; ! $comment->{object_id} = $object->id; } else { ! $comment->{class} = $self->param( 'class' ); ! $comment->{object_id} = $self->param( 'object_id' ); } ! return $comment; } sub _get_cookie_name { my ( $self ) = @_; --- 338,363 ---- } + my ( $o_class, $o_id ) = $self->_get_class_and_id(); + $comment->{class} = $o_class; + $comment->{object_id} = $o_id; + return $comment; + } + + sub _get_class_and_id { + my ( $self ) = @_; my $object = $self->param( 'object' ); + my ( $o_class, $o_id ); if ( $object ) { ! $o_class = ref $object; ! $o_id = $object->id; } else { ! $o_class = $self->param( 'class' ); ! $o_id = $self->param( 'object_id' ); } ! return ( $o_class, $o_id ); } + sub _get_cookie_name { my ( $self ) = @_; |