[vhffs-dev] [882] Moved accept/refuse code from panel code to API code

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 882
Author:   gradator
Date:     2007-09-09 02:31:37 +0000 (Sun, 09 Sep 2007)

Log Message:
-----------
Moved accept/refuse code from panel code to API code

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Object.pm
    trunk/vhffs-panel/admin/moderation_submit.pl


Modified: trunk/vhffs-api/src/Vhffs/Object.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Object.pm	2007-09-09 01:46:20 UTC (rev 881)
+++ trunk/vhffs-api/src/Vhffs/Object.pm	2007-09-09 02:31:37 UTC (rev 882)
@@ -53,6 +53,9 @@
 package Vhffs::Object;
 
 use Vhffs::Constants;
+use POSIX qw(locale_h);
+use locale;
+use Locale::gettext;
 
 sub new
 {
@@ -381,6 +384,62 @@
 }
 
 
+# Accept this object
+sub moderate_accept
+{
+	my $self = shift;
+	my $user = shift;
+	my $vhffs = $self->{main};
+
+	$self->set_status( Vhffs::Constants::WAITING_FOR_CREATION );
+
+	my $mail = sprintf(
+		gettext( "Hello,\n\nYour request for a %s (%s) on %s was accepted.\nPlease wait while we are creating your object.\n\nCheers,\n\nThe Moderator and Admin Team\n\n---------\n%s\n%s" ) ,
+		Vhffs::Functions::type_string_from_type_id( $self->get_type ),
+		$self->get_label,
+		$vhffs->get_config->get_host_name,
+		$vhffs->get_config->get_host_name,
+		$vhffs->get_config->get_panel->{url}
+		);
+
+	my $subject = sprintf(
+		gettext('Your request on %s platform') , 
+		$vhffs->get_config->get_host_name
+		);
+
+	Vhffs::Functions::send_mail( $vhffs->get_config->get_moderator_mail , $user->get_mail , $subject , $mail );
+
+	if( $vhffs->get_config->get_users->{'use_notation'} eq 'yes' )
+	{
+		use Vhffs::Note;
+		Vhffs::Note::inc_note( $vhffs , $user , 1 );
+	}
+
+	return $self->commit;
+}
+
+
+# Refuse this object
+sub moderate_refuse
+{
+	my $self = shift;
+	my $user = shift;
+	my $reason = shift;
+	my $vhffs = $self->{main};
+
+	$self->set_status( Vhffs::Constants::VALIDATION_REFUSED );
+
+	$self->set_description( $reason );
+	if( $vhffs->get_config->get_users->{'use_notation'} eq 'yes' )
+	{
+		use Vhffs::Note;
+		Vhffs::Note::inc_note( $vhffs , $user , -1 );
+	}
+
+	return $self->commit;
+}
+
+
 #Get all objects of the database.
 #If $name is undefined, the functions returns ALL objects.
 #Else, it returns objects like the name. It searchs in oid, user and description

Modified: trunk/vhffs-panel/admin/moderation_submit.pl
===================================================================
--- trunk/vhffs-panel/admin/moderation_submit.pl	2007-09-09 01:46:20 UTC (rev 881)
+++ trunk/vhffs-panel/admin/moderation_submit.pl	2007-09-09 02:31:37 UTC (rev 882)
@@ -38,16 +38,9 @@
 use CGI::Session;
 use strict;
 
-
 use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Group;
-use Vhffs::Main;
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Menu;
-use Vhffs::Services::Web;
-use Vhffs::Acl;
-use Vhffs::Constants;
 use Vhffs::ObjectFactory;
 
 my $panel = new Vhffs::Panel::Main();
@@ -55,35 +48,28 @@
 my $session = $panel->get_session;
 exit 0 unless $session;
 
-my $template;
-
 my $cgi          = $panel->{'cgi'};
 my $vhffs        = $panel->{'vhffs'};
-my $maintemplate = $panel->{'template'};
 my $user         = $panel->{'user'};
-my $group        = $panel->{'group'};
+my $templatedir  = $panel->{'templatedir'};
 
-my $projectname = $session->param("project");
+my $accept       = $cgi->param('ACCEPT');
+my $reason       = $cgi->param('reason');
 
+my $template     = new HTML::Template( filename => $templatedir.'/panel/admin/misc/moderation_applied.tmpl' );
 
-my $accept       = $cgi->param("ACCEPT");
-my $reason       = $cgi->param("reason");
-
-my $templatedir  = $vhffs->get_config->get_templatedir;
-
-$template        = new HTML::Template( filename => $templatedir."/panel/admin/misc/moderation_applied.tmpl" );
-
 #Use is not allowed to see this page, only MODERATOR and ADMIN
-if( ($user->is_moderator != 1 ) && ( $user->is_admin ) != 1 ) 
+unless( $user->is_moderator || $user->is_admin )
 {
-	my $message = gettext("You're not allowed to do this (ACL rights)");
+	my $message = gettext('You\'re not allowed to do this (ACL rights)');
 	$template->param( MESSAGE => $message );
 }
 else
 {
 	use Vhffs::Object;
-	my $oid = $cgi->param("OID");
-	my $uidasker = $cgi->param("UID_ASKER");
+	my $oid = $cgi->param('OID');
+	my $uidasker = $cgi->param('UID_ASKER');
+	my $userasker = Vhffs::User::get_by_uid( $vhffs , $uidasker );
 	my $object = Vhffs::ObjectFactory::fetch_object( $vhffs , $oid );
 
 	if( ( ! defined $oid ) || ( ! defined $object ) || ( ! defined $accept ) )
@@ -92,56 +78,28 @@
 	}
 	else
 	{
+		my $ok;
+
 		if( $accept == 1 )
 		{
-			$object->set_status( Vhffs::Constants::WAITING_FOR_CREATION );
-			my $userbis = Vhffs::User::get_by_uid( $vhffs , $object->get_owner_uid );
-			if( defined $userbis )
-			{
-			    my $mail = gettext("Hello,\n\nYour request for a %s (%s) on %s was accepted.\nPlease wait while we are creating your object.\n\nCheers,\n\nThe Moderator and Admin Team\n\n---------\n%s\n%s");
-                my $subject = gettext('Your request on %s platform');
-                $mail = sprintf($mail,
-                    Vhffs::Functions::type_string_from_type_id($object->get_type()),
-                    $object->get_label(),
-                    $vhffs->get_config->get_host_name(),
-                    $vhffs->get_config->get_host_name(),
-                    $vhffs->get_config->get_panel->{'url'});
-
-			    $subject = sprintf($subject,
-                                        $vhffs->get_config->get_host_name());
-			    Vhffs::Functions::send_mail( $vhffs->get_config->get_moderator_mail , $userbis->get_mail , $subject , $mail );
-
-		                if( $vhffs->get_config->get_users->{'use_notation'} eq 'yes' )
-				{
-					use Vhffs::Note;
-					Vhffs::Note::inc_note( $vhffs , $userbis , 1 );
-				}
-
-			}
+			$ok = $object->moderate_accept( $userasker );
 		}
 		else
 		{
-            my $askeruser = Vhffs::User::get_by_uid($vhffs, $uidasker),
-		    $object->set_description( $reason );
-		    $object->set_status( Vhffs::Constants::VALIDATION_REFUSED );
-		        if( $vhffs->get_config->get_users->{'use_notation'} eq 'yes' )
-			{
-				use Vhffs::Note;
-				Vhffs::Note::inc_note( $vhffs , $askeruser , -1 );
-			}
+			$ok = $object->moderate_refuse( $userasker , $reason );
 		}
 		
-		if( $object->commit < 0 )
+		if( $ok < 0 )
 		{
-		    $template->param( MESSAGE  => gettext("Cannot apply modifications") );
+			$template->param( MESSAGE  => gettext("Cannot apply modifications") );
 		}
 		else
 		{
-		    $template->param( MESSAGE  => gettext("Modifications applied successfully") );
+			$template->param( MESSAGE  => gettext("Modifications applied successfully") );
 		}
 	}
 }
 
-$panel->set_refresh_url( "/admin/moderation.pl" );
+$panel->set_refresh_url( '/admin/moderation.pl' );
 $panel->build( $template );
 $panel->display;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/