[vhffs-dev] [884] vhffs-moderate is now using the new moderation API

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


Revision: 884
Author:   gradator
Date:     2007-09-09 03:13:03 +0000 (Sun, 09 Sep 2007)

Log Message:
-----------
vhffs-moderate is now using the new moderation API

Modified Paths:
--------------
    trunk/vhffs-tools/src/vhffs-moderate


Modified: trunk/vhffs-tools/src/vhffs-moderate
===================================================================
--- trunk/vhffs-tools/src/vhffs-moderate	2007-09-09 03:06:55 UTC (rev 883)
+++ trunk/vhffs-tools/src/vhffs-moderate	2007-09-09 03:13:03 UTC (rev 884)
@@ -7,379 +7,48 @@
 use Data::Dumper;
 
 use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Group;
 use Vhffs::Main;
-use Vhffs::Services::Web;
-use Vhffs::Acl;
 use Vhffs::Constants;
 use Vhffs::Note;
+use Vhffs::Object;
+use Vhffs::ObjectFactory;
 
-
 my $vhffs = init Vhffs::Main;
 	
+
 sub list_moderation
 {
-	#Treat Groups to moderate
-	use Vhffs::Panel::Group;
-	print "Groups to validate: \n";
-	my $groups = Vhffs::Group::getall( $vhffs , Vhffs::Constants::WAITING_FOR_VALIDATION );
-	my $temp;
-	
-	if( defined $groups )
-	{
-		foreach $temp ( @{$groups} )
-		{
-            if( $vhffs->get_users->{'use_notation'} eq 'yes' )
-            {
-                print "owner: " . $temp->get_user->get_username;
-				print "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ") " ;
-            }
-            else
-            {
-                print "owner: " . $temp->get_user->get_username;
-            }
-			print "\t";
-		
-			
-			print "group: " . $temp->get_groupname . "\t";
-			print "oid: " . $temp->get_oid . "\t";
-			print "description: " . Vhffs::Functions::stripslashes( $temp->get_description );
-			print "\n";
-		}
+	my $objects = Vhffs::Object::getall( $vhffs, undef, Vhffs::Constants::WAITING_FOR_VALIDATION );
 
+	unless( defined $objects )  {
+		print "There is nothing to moderate\n";
 	}
-	else
-	{
-		print "\tNo group to moderate\n"	
-	}
-	print "\n";
-	print "\n";
+	else {
+		foreach ( @{$objects} ) {
+			my $user = $_->get_user;
+			my $group = $_->get_group;
+			my $object = Vhffs::ObjectFactory::fetch_object( $vhffs , $_->{object_id} );
 
-
-
-	if( $vhffs->get_config->get_service_availability('web') == 1 )
-	{
-		#Treat Website to moderate
-		use Vhffs::Services::Web;
-		print "Webarea to validate: \n";
-		my $webs = Vhffs::Services::Web::getall( $vhffs , Vhffs::Constants::WAITING_FOR_VALIDATION);
-	
-		if( defined $webs )
-		{
-			foreach $temp ( @{$webs} )
-			{
-				print "Servername: " .  $temp->get_servername;
-
-				if( $vhffs->get_users->{'use_notation'} eq 'yes' )
-				{
-                	print "\towner: " . $temp->get_user->get_username;
-					print "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ") " ;
-				}
-				else
-				{
-                	print "\towner: " . $temp->get_user->get_username;
-				}
-
-				print "\tgroup: " .  $temp->get_group->get_groupname;
-				print "\toid: " . $temp->get_oid;
-				print "\tdescription: " . $temp->get_description;
-			}
 			print "\n";
-	
+			print "oid: \t\t".$_->{object_id}."\n";
+			print "type: \t\t".Vhffs::Functions::type_string_from_type_id( $_->{type} )."\n";
+			print "name: \t\t".$object->get_label."\n";
+			print "user: \t\t".$user->get_username."\n";
+			print "group: \t\t".$group->get_groupname."\n";
+			print "description: \t".$_->get_description."\n";
+			print "\n";
 		}
-		else
-		{
-			print "No Web Area to moderate\n";
-		}
 	}
-
-
-	print "\n";
-	print "\n";
-
-
-	if( $vhffs->get_config->get_service_availability('dns') == 1 )
-	{
-		use Vhffs::Services::DNS;
-		print "DNS to validate\n";
-		my $nss = Vhffs::Services::DNS::getall( $vhffs , Vhffs::Constants::WAITING_FOR_VALIDATION );
-	
-		if( defined $nss )
-		{
-			foreach $temp ( @{$nss} )
-			{
-				print "Domain: " .  $temp->get_domain;
-
-				if( $vhffs->get_users->{'use_notation'} eq 'yes' )
-				{
-                	print "\towner: " . $temp->get_user->get_username;
-					print "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ") " ;
-            	}
-            	else
-            	{
-                	print "\towner: " . $temp->get_user->get_username;
-            	}
-
-				print "\tgroup: " .  $temp->get_group->get_groupname;
-				print "\toid: " . $temp->get_oid;
-				print "\tdescription: " . $temp->get_description;
-				print "\n";
-			}
-	
-		}
-		else
-		{
-			print "No DNS to moderate\n";
-		}
-	}
-
-	print "\n";
-	print "\n";
-
-	if( $vhffs->get_config->get_service_availability('cvs') == 1 )
-	{
-		use Vhffs::Services::Cvs;
-		print "CVS Repository to validate\n";
-		my $repos = Vhffs::Services::Cvs::getall( $vhffs , Vhffs::Constants::WAITING_FOR_VALIDATION );
-	
-		if( defined $repos )
-		{
-			foreach $temp ( @{$repos} )
-			{
-				print "Root: " .  $temp->get_cvsroot;
-    	        if( $vhffs->get_users->{'use_notation'} eq 'yes' )
-				{
-                	print "\towner: " . $temp->get_user->get_username;
-					print "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ") " ;
-            	}
-            	else
-            	{
-                	print "\towner: " . $temp->get_user->get_username;
-            	}
-				print "\tgroup: " .  $temp->get_group->get_groupname;
-				print "\toid: " . $temp->get_oid;
-				print "\tdescription: " . $temp->get_description;
-				print "\n";
-			}
-		}
-		else
-		{
-			print "No repository to moderate\n";
-		}
-	}
-
-	print "\n";
-	print "\n";
-
-
-	if( $vhffs->get_config->get_service_availability('mailinglist') == 1 )
-	{
-		use Vhffs::Panel::Mailinglist;
-		print "List to validate\n";
-		my $mls = Vhffs::Services::Mailing::getall( $vhffs , Vhffs::Constants::WAITING_FOR_VALIDATION );
-	
-		if( defined $mls )
-		{
-			foreach $temp ( @{$mls} )
-			{
-				print "Name: " . $temp->get_localpart ."\@". $temp->get_domain;
-		        
-				if( $vhffs->get_users->{'use_notation'} eq 'yes' )
-                {
-                	print "\towner: " . $temp->get_user->get_username;
-					print "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ") " ;
-                }
-                else
-                {
-                	print "\towner: " . $temp->get_user->get_username;
-                }	
-				print "\tgroup: " .  $temp->get_group->get_groupname;
-				print "\toid: " . $temp->get_oid;
-				print "\tdescription: " . $temp->get_description;
-				print "\n";
-			}
-		}
-		else
-		{
-			print "No list to moderate\n";
-		}
-	}
-
-	print "\n";
-	print "\n";
-
-
-	if( $vhffs->get_config->get_service_availability('svn') == 1 )
-	{
-		use Vhffs::Services::Svn;
-		use Vhffs::Constants;
-		print "Subversion Repository to validate\n";
-		my $repos = Vhffs::Services::Svn::getall( $vhffs , Vhffs::Constants::WAITING_FOR_VALIDATION );
-		my $svn;
-		if( defined $repos )
-		{
-			foreach $svn ( @{$repos} )
-			{
-				print "Root: " .  $svn->get_reponame;
-				
-                if( $vhffs->get_users->{'use_notation'} eq 'yes' )
-                {
-                	print "\towner: " . $svn->get_user->get_username;
-					print "(" .  Vhffs::Note::get_note( $vhffs , $svn->get_user ) . ") " ;
-                }
-                else
-                {
-                	print "\towner: " . $svn->get_user->get_username;
-                }
-
-				print "\tgroup: " .  $svn->get_group->get_groupname;
-				print "\toid: " . $svn->get_oid;
-				print "\tdescription: " . $svn->get_description;
-				print "\n";
-			}
-		}
-		else
-		{
-			print "No repository to moderate\n";
-		}
-	}
-
-
-	print "\n";
-	print "\n";
-
-
-	if( $vhffs->get_config->get_service_availability('mail') == 1 )
-	{
-		use Vhffs::Panel::Mail;
-		print "Mail Area to validate\n";
-		my $mails = Vhffs::Services::Mail::getall( $vhffs , Vhffs::Constants::WAITING_FOR_VALIDATION );
-	
-		if( defined $mails )
-		{
-			foreach $temp ( @{$mails} )
-			{
-				print "Domain: " .  $temp->get_domain;
-
-                if( $vhffs->get_users->{'use_notation'} eq 'yes' )
-                {
-                	print "\towner: " . $temp->get_user->get_username;
-					print "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ") " ;
-                }
-                else
-                {
-                	print "\towner: " . $temp->get_user->get_username;
-                }
-
-				print "\tgroup: " .  $temp->get_group->get_groupname;
-				print "\toid: " . $temp->get_oid;
-				print "\tdescription: " . $temp->get_description;
-				print "\n";
-			}
-	
-		}
-		else
-		{
-			print "No Mail Area to moderate\n";
-		}
-	}
-
-	print "\n";
-	print "\n";
-
-
-	if( $vhffs->get_config->get_service_availability('mysql') == 1 )
-	{
-		use Vhffs::Services::Mysql;
-		print gettext("MySQL database awaiting validation") . "\n";
-		my $dbs = Vhffs::Services::Mysql::getall( $vhffs , Vhffs::Constants::WAITING_FOR_VALIDATION );
-	
-		if( defined $dbs )
-		{
-			foreach $temp ( @{$dbs} )
-			{
-				print "Dbname: " .  $temp->get_dbname;
-
-                if( $vhffs->get_users->{'use_notation'} eq 'yes' )
-                {
-                	print "\towner: " . $temp->get_user->get_username;
-					print "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ") " ;
-                }
-                else
-                {
-                	print "\towner: " . $temp->get_user->get_username;
-                }
-				
-				print "\tgroup: " .  $temp->get_group->get_groupname;
-				print "\toid: " . $temp->get_oid;
-				print "\tdescription: " . $temp->get_description;
-				print "\n";
-			}
-	
-		}
-		else
-		{
-			print gettext("No database to moderate\n");
-		}
-	}
-
-	print "\n";
-	print "\n";
-
-	if( $vhffs->get_config->get_service_availability('pgsql') == 1 )
-	{
-		use Vhffs::Services::Postgres;
-		print gettext("Postgres database to validate") . "\n";
-		my $dbs = Vhffs::Services::Postgres::getall( $vhffs , Vhffs::Constants::WAITING_FOR_VALIDATION );
-	
-		if( defined @{$dbs} )
-		{
-			foreach $temp ( @{$dbs} )
-			{
-				print "Dbname: " . $temp->get_dbname;
-
-                if( $vhffs->get_users->{'use_notation'} eq 'yes' )
-                {
-                	print "\towner: " . $temp->get_user->get_username;
-					print "(" .  Vhffs::Note::get_note( $vhffs , $temp->get_user ) . ") " ;
-                }
-                else
-                {
-                	print "\towner: " . $temp->get_user->get_username;
-                }
-				print "\tgroup: " .  $temp->get_group->get_groupname;
-				print "\toid: " . $temp->get_oid;
-				print "\tdescription: " . $temp->get_description;
-				print "\n";
-
-			}
-	
-		}
-		else
-		{
-			print gettext("No database to moderate");
-		}
-	}
-
-	print "\n";
-	
 }
 
 
-
-
-
 sub moderate
 {
-	my $oid;
-	my $status; # 0 = refuse , 1 = accept
 	my $object;
 	my $vhffs;
 
-	$oid	=	shift;
-	$status	=	shift;
-	$vhffs	= init Vhffs::Main;
+	my $oid = shift;
+	my $status = shift;
 
 	$object	= Vhffs::Object::get_by_oid( $vhffs , $oid );
 
@@ -420,10 +89,11 @@
 
 sub help
 {
-	print "Use as it : \tvhffs-moderate list - list all objects to moderate\n";
-	print "\t\tvhffs-moderate accept 1220 - accept an object (1220 is here the OID, object identifier)\n";
-	print "\t\tvhffs-moderate refuse 1220 - refuse an object (1220 is here the OID, object identifier)\n";
-	print "\t\tvhffs-moderate help - display help\n";
+	print "Usage :\n";
+	print "  vhffs-moderate list - list all objects to moderate\n";
+	print "  vhffs-moderate accept <oid> - accept an object\n";
+	print "  vhffs-moderate refuse <oid> - refuse an object\n";
+	print "  vhffs-moderate help - display help\n";
 }
 
 
@@ -440,7 +110,6 @@
 	my $arg;
 	my $oid;
 
-
 	$arg = $ARGV[0];
 	$oid = $ARGV[1];
 
@@ -450,28 +119,32 @@
 	}
 	elsif( $arg =~ /^accept$/ )
 	{
-		if( moderate( $oid , 1 ) == 0 )
+		my $object = Vhffs::Object::get_by_oid( $vhffs , $oid );
+
+		if( ! defined $object  ||  $object->moderate_accept < 0 )
 		{
-			print "Successfully moderate\n";
-			exit( 0 );
+			print "Error while moderation\n";
+			exit( 1 );
 		}
 		else
 		{
-			print "Error while moderate\n";
-			exit( 1 );
+			print "Successfully moderated\n";
+			exit( 0 );
 		}
 	}
 	elsif( $arg =~ /^refuse$/ )
 	{
-		if( moderate( $oid , 0 ) == 0 )
+		my $object = Vhffs::Object::get_by_oid( $vhffs , $oid );
+
+		if( ! defined $object  ||  $object->moderate_refuse('') < 0 )
 		{
-			print "Succesfully moderate\n";
-			exit( 0 );
+			print "Error while moderation\n";
+			exit( 1 );
 		}
 		else
 		{
-			print "Error while moderate\n";
-			exit( 1 );
+			print "Successfully moderated\n";
+			exit( 0 );
 		}
 	}
 	elsif( $arg =~ /^help$/ )
@@ -481,7 +154,7 @@
 	}
 	else
 	{
-		print "Error, bad number of arguments or bad argument\n";
+		print "Error, bad number of arguments or bad arguments\n";
 		help();
 		exit( 1 );
 	}


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