[vhffs-dev] [1484] Added information in history about wich user generated wich entry ( visible for moderators/admins in the group history)

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


Revision: 1484
Author:   beuss
Date:     2009-07-30 07:41:20 +0200 (Thu, 30 Jul 2009)

Log Message:
-----------
Added information in history about wich user generated wich entry (visible for moderators/admins in the group history)

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Group.pm
    trunk/vhffs-api/src/Vhffs/Main.pm
    trunk/vhffs-api/src/Vhffs/Object.pm
    trunk/vhffs-api/src/Vhffs/Panel/Main.pm
    trunk/vhffs-irc/modobot.pl
    trunk/vhffs-panel/group/history.pl
    trunk/vhffs-panel/templates/group/history.tmpl
    trunk/vhffs-panel/templates/group/history_part.tmpl


Modified: trunk/vhffs-api/src/Vhffs/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Group.pm	2009-07-30 05:35:48 UTC (rev 1483)
+++ trunk/vhffs-api/src/Vhffs/Group.pm	2009-07-30 05:41:20 UTC (rev 1484)
@@ -633,7 +633,7 @@
 {
 	my $self = shift;
 
-	my $sql = 'SELECT o.object_id,o.type,h.history_id,h.date,h.message FROM vhffs_history h INNER JOIN vhffs_object o ON o.object_id=h.object_id WHERE o.owner_gid=? ORDER BY date DESC';
+	my $sql = 'SELECT o.object_id,o.type,h.history_id,h.date,h.message,source.username as source FROM vhffs_history h INNER JOIN vhffs_object o ON o.object_id=h.object_id LEFT JOIN vhffs_users source ON source.uid = h.source_uid WHERE o.owner_gid=? ORDER BY date DESC';
     my $dbh = $self->get_db_object;
     return $dbh->selectall_arrayref($sql, {Slice => {}}, $self->{gid});
 }

Modified: trunk/vhffs-api/src/Vhffs/Main.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Main.pm	2009-07-30 05:35:48 UTC (rev 1483)
+++ trunk/vhffs-api/src/Vhffs/Main.pm	2009-07-30 05:41:20 UTC (rev 1484)
@@ -42,8 +42,11 @@
     VHFFSCONFPATH => "/etc/vhffs/vhffs.conf"
 };
 
+# Current user UID. On the panel it would be
+# the currently logged user, on IRC moderation
+# the user who talk to the bot.
+my $current_user_uid;
 
-
 sub init
 {
 	my $self;
@@ -128,6 +131,12 @@
     }
 }
 
+sub current_user_uid
+{
+	$current_user_uid = $_[0] if(defined $_[0]);
+	return $current_user_uid;
+}
+
 1;
 
 __END__
@@ -164,6 +173,7 @@
 
 is_valid() : returns 1 if the object is valid (good database connection, ...), 0 otherwise
 
+current_user_uid([$uid]): get or set the current user's UID.
 
 =head1 SEE ALSO
 Vhffs::User, Vhffs::Group

Modified: trunk/vhffs-api/src/Vhffs/Object.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Object.pm	2009-07-30 05:35:48 UTC (rev 1483)
+++ trunk/vhffs-api/src/Vhffs/Object.pm	2009-07-30 05:41:20 UTC (rev 1484)
@@ -347,13 +347,15 @@
 
 sub add_history
 {
+	use Vhffs::Main;
 	my $self = shift;
 	my $message = shift;
+	my $source = Vhffs::Main::current_user_uid;
 	$message = $message;
 
-	my $query = 'INSERT INTO vhffs_history(object_id, date, message)  VALUES(?, ?, ?)';
+	my $query = 'INSERT INTO vhffs_history(object_id, date, message, source_uid)  VALUES(?, ?, ?, ?)';
 	my $request = $self->{'db'}->prepare( $query );
-	$request->execute( $self->{'object_id'}, time(), $message ) or return -2;
+	$request->execute( $self->{'object_id'}, time(), $message, $source ) or return -2;
 
 	return $self->{'db'}->last_insert_id(undef, undef, 'vhffs_history', undef);;
 }

Modified: trunk/vhffs-api/src/Vhffs/Panel/Main.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Main.pm	2009-07-30 05:35:48 UTC (rev 1483)
+++ trunk/vhffs-api/src/Vhffs/Panel/Main.pm	2009-07-30 05:41:20 UTC (rev 1484)
@@ -385,6 +385,7 @@
 
 	$panel->{session} = $session;
 	$panel->{user} = $user;
+	Vhffs::Main::current_user_uid($uid);
 	return $session;
 }
 

Modified: trunk/vhffs-irc/modobot.pl
===================================================================
--- trunk/vhffs-irc/modobot.pl	2009-07-30 05:35:48 UTC (rev 1483)
+++ trunk/vhffs-irc/modobot.pl	2009-07-30 05:41:20 UTC (rev 1484)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!%PERL%
 
 # modobot is an IRC bot which allow you to validate
 # VHFFS objects through IRC
@@ -12,7 +12,7 @@
 use Locale::gettext;
 use Encode;
 
-use lib '/usr/share/vhffs/api';
+use lib '%VHFFS_LIB_DIR%';
 use Vhffs::User;
 use Vhffs::Group;
 use Vhffs::Main;
@@ -204,8 +204,7 @@
 
 sub is_modo
 {
-    my $user = Vhffs::User::get_by_username( $vhffs, shift );
-    return ( (defined $user) && ($user->is_moderator == 1 || $user->is_admin == 1) );
+	return (defined $_[0] && ($_[0]->is_moderator || $_[0]->is_admin ) )
 } # is_modo
 
 sub get_desc
@@ -357,28 +356,30 @@
     my ($self, $event)=@_;
     my ($nick, $mynick)=($event->nick, $self->nick);
     my $texte=$event->{args}[0];
+    my $user = Vhffs::User::get_by_username($vhffs, $nick);
 
     if ($texte =~ m/^${mynick}: accept [0-9]+.*$/)
     {
-        if (is_modo ($nick) == 1)
-	{
-	    my $oid = $texte;
-	    my $raison = $texte;
-	    $raison =~ s/^${mynick}: accept [0-9]+ //;
-	    $oid =~ s/^${mynick}: accept ([0-9]+).*$/$1/;
-            moderate( $oid , 1 , $raison);
-	}
+        if (is_modo ($user) == 1)
+		{
+		    my $oid = $texte;
+		    my $raison = $texte;
+			Vhffs::Main::current_user_uid($user->get_uid);
+		    $raison =~ s/^${mynick}: accept [0-9]+ //;
+		    $oid =~ s/^${mynick}: accept ([0-9]+).*$/$1/;
+       	    moderate( $oid , 1 , $raison);
+		}
     }
     elsif ($texte =~ m/^${mynick}: refuse [0-9]+ .*$/)
     {
-        if (is_modo ($nick) == 1)
-	{
-	    my $oid = $texte;
-	    my $raison = $texte;
-	    $raison =~ s/^${mynick}: refuse [0-9]+ //;
-	    $oid =~ s/^${mynick}: refuse ([0-9]+) .*$/$1/;
-            moderate( $oid , 0 , $raison);
-	}
+        if (is_modo ($user) == 1) {
+			my $oid = $texte;
+			my $raison = $texte;
+			Vhffs::Main::current_user_uid($user->get_uid);
+			$raison =~ s/^${mynick}: refuse [0-9]+ //;
+			$oid =~ s/^${mynick}: refuse ([0-9]+) .*$/$1/;
+			moderate( $oid , 0 , $raison);
+		}
     }
     elsif ($texte =~ m/^${mynick}: help$/)
     {
@@ -444,10 +445,11 @@
 
     elsif ($texte =~ m/^${mynick}: setquota [a-z0-9]+ .*$/)
     {
-        if (is_modo ($nick) == 1)
+        if (is_modo ($user) == 1)
         {
             my $groupname = $texte;
             my $quotavalue = $texte;
+			Vhffs::Main::current_user_uid($user->get_uid);
             $quotavalue =~ s/^${mynick}: setquota [a-z0-9]+ //;
             $groupname =~ s/^${mynick}: setquota ([a-z0-9]+) .*$/$1/;
             set_quota($groupname,$quotavalue);

Modified: trunk/vhffs-panel/group/history.pl
===================================================================
--- trunk/vhffs-panel/group/history.pl	2009-07-30 05:35:48 UTC (rev 1483)
+++ trunk/vhffs-panel/group/history.pl	2009-07-30 05:41:20 UTC (rev 1484)
@@ -79,6 +79,7 @@
 	$template->param( HTYPE => gettext('Type') );
 	$template->param( HNAME => gettext('Name') );
 	$template->param( HEVENT => gettext('Event') );
+        $template->param( MODERATOR => $user->is_moderator || $user->is_admin );
 
 	unless(@{$history}) {
 		$template->param( HISTORY_PART => gettext('No event about this group') );
@@ -96,6 +97,9 @@
             my $object = Vhffs::ObjectFactory::fetch_object( $vhffs , $_->{object_id} );
             $history_tmpl->param( NAME => $object->get_label );
             $history_tmpl->param( EVENT => $_->{message} );
+            $history_tmpl->param( MODERATOR => $user->is_moderator || $user->is_admin );
+            $history_tmpl->param( SOURCE => $_->{source} );
+
             $output .= $history_tmpl->output;
         }
 		$template->param( HISTORY_PART => $output );

Modified: trunk/vhffs-panel/templates/group/history.tmpl
===================================================================
--- trunk/vhffs-panel/templates/group/history.tmpl	2009-07-30 05:35:48 UTC (rev 1483)
+++ trunk/vhffs-panel/templates/group/history.tmpl	2009-07-30 05:41:20 UTC (rev 1484)
@@ -13,6 +13,11 @@
 		<th>
 			<TMPL_VAR ESCAPE=1 NAME="HEVENT">
 		</th>
+<TMPL_IF NAME="MODERATOR">
+		<th>
+			Author
+		</th>
+</TMPL_IF>
 	</tr>
 </thead>
 <tbody>

Modified: trunk/vhffs-panel/templates/group/history_part.tmpl
===================================================================
--- trunk/vhffs-panel/templates/group/history_part.tmpl	2009-07-30 05:35:48 UTC (rev 1483)
+++ trunk/vhffs-panel/templates/group/history_part.tmpl	2009-07-30 05:41:20 UTC (rev 1484)
@@ -11,5 +11,14 @@
 		</td>
 		<td>
 			<TMPL_VAR ESCAPE=1 NAME="EVENT">
+		</td
+<TMPL_IF NAME="MODERATOR">
+		<td>
+<TMPL_IF NAME="SOURCE">
+			<TMPL_VAR ESCAPE=1 NAME="SOURCE">
+<TMPL_ELSE>
+			N/A
+</TMPL_IF>
 		</td>
+</TMPL_IF>
 	</tr>


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