[vhffs-dev] [1039] All GIT prefs are now handled by prefs.pl.

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


Revision: 1039
Author:   beuss
Date:     2007-10-27 18:06:11 +0000 (Sat, 27 Oct 2007)

Log Message:
-----------
All GIT prefs are now handled by prefs.pl.
This finishes the first part of prefs refactoring.




YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAH I DID IT! I DID IT! I DID IT! I DID IT!

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Services/Git.pm
    trunk/vhffs-panel/Makefile.am
    trunk/vhffs-panel/git/prefs.pl
    trunk/vhffs-panel/templates/git/prefs.tmpl

Removed Paths:
-------------
    trunk/vhffs-panel/git/prefs_save.pl


Modified: trunk/vhffs-api/src/Vhffs/Services/Git.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Git.pm	2007-10-27 08:34:03 UTC (rev 1038)
+++ trunk/vhffs-api/src/Vhffs/Services/Git.pm	2007-10-27 18:06:11 UTC (rev 1039)
@@ -139,22 +139,11 @@
 
 sub commit
 {
-    my $self = shift;    
-
-    my $query = "UPDATE vhffs_git SET public= '".$self->{'public'}."' WHERE git_id=$self->{'git_id'}";
-    my $request = $self->{'db'}->prepare($query);
-    $request->execute;
-
-    $self->SUPER::commit;
-}
-
-sub commit_option
-{
     my $self = shift;
 
-    my $query = "UPDATE vhffs_git SET ml_name= '".$self->{'ml_name'}."' WHERE git_id=$self->{'git_id'}";
-    my $request = $self->{'db'}->prepare($query);
-    $request->execute;
+    my $dbh = $self->get_db_object;
+    my $sql = 'UPDATE vhffs_git SET public = ?, ml_name = ? WHERE git_id = ?';
+    $dbh->do($sql, undef, $self->{public}, $self->{ml_name}, $self->{git_id});
 
     $self->SUPER::commit;
 }
@@ -171,6 +160,12 @@
     $self->{'public'} = 0;
 }
 
+sub set_ml_name {
+    my ($self, $ml_name) = @_;
+    return -1 unless(Vhffs::Functions::valid_mail($ml_name));
+    $self->{ml_name} = $ml_name;
+}
+
 sub is_public
 {
     my $self = shift;
@@ -184,6 +179,11 @@
     }
 }
 
+sub get_ml_name {
+    my $self = shift;
+    return $self->{ml_name};
+}
+
 sub get_reponame
 {
     my $self = shift;

Modified: trunk/vhffs-panel/Makefile.am
===================================================================
--- trunk/vhffs-panel/Makefile.am	2007-10-27 08:34:03 UTC (rev 1038)
+++ trunk/vhffs-panel/Makefile.am	2007-10-27 18:06:11 UTC (rev 1039)
@@ -114,7 +114,6 @@
 	git/create.pl \
 	git/delete.pl \
 	git/index.pl \
-	git/prefs_save.pl \
 	git/prefs.pl \
 	user/delete.pl \
 	user/prefs.pl \

Modified: trunk/vhffs-panel/git/prefs.pl
===================================================================
--- trunk/vhffs-panel/git/prefs.pl	2007-10-27 08:34:03 UTC (rev 1038)
+++ trunk/vhffs-panel/git/prefs.pl	2007-10-27 18:06:11 UTC (rev 1039)
@@ -46,8 +46,8 @@
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Menu;
 use Vhffs::Panel::Object;
+use Vhffs::Panel::Template;
 
-
 my $panel = new Vhffs::Panel::Main();
 exit 0 unless $panel;
 my $session = $panel->get_session;
@@ -97,11 +97,15 @@
 }
 else
 {
-    $template = new HTML::Template( filename => $templatedir."/panel/git/prefs.tmpl" );
+    if(defined $cgi->param('save_prefs_submit') ) {
+        if(save_prefs()) {
+            exit;
+        }
+    }
+    $template = new Vhffs::Panel::Template( filename => $templatedir."/panel/git/prefs.tmpl" );
 
-    $template->param( TEXT_TITLE => gettext("Admin Git Repository") );
+    $panel->set_title( gettext("Admin Git Repository") );    
     
-    
     $template->param( TEXT_REPONAME => $git->get_reponame );
     $template->param( TITLE_PUBLIC => gettext("Public") );
     $template->param( TEXT_PUBLIC => gettext("Is this a public repository ?") );
@@ -153,3 +157,49 @@
 $panel->build( $template );
 $panel->display;
 
+sub save_prefs {
+    my $public = $cgi->param('public');
+    my $ml_name = $cgi->param('ml_name');
+
+    if(!$user->can_modify($git)) {
+        $panel->add_error( gettext('You are not allowed to modify this GIT repository (ACL rights)') );
+        return 0;
+    }
+
+    if(!defined($public) || !defined($ml_name)) {
+        $panel->add_error( gettext('CGI error') );
+        return 0;
+    }
+
+    if($public != $git->is_public) {
+        if($public == 1) {
+            $git->set_public();
+        } else {
+            $git->set_private();
+        }
+        $git->set_status(Vhffs::Constants::WAITING_FOR_MODIFICATION);
+    }
+
+    if(($ml_name =~ /^\s*$/ || Vhffs::Functions::valid_mail($ml_name))) {
+        if($ml_name ne $git->get_ml_name) {
+            $git->set_ml_name($ml_name);
+            $git->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION );
+        }
+    } else {
+        $panel->add_error( gettext('Invalid mailing list address') );
+        return 0;
+    }
+
+    if($git->get_status == Vhffs::Constants::WAITING_FOR_MODIFICATION) {
+        if($git->commit < 0) {
+            $panel->add_error( gettext('Unable to apply modifications') );
+            return 0;
+        } else {
+            my $url = '/group/view.pl?project='.$panel->{groupname}.'&msg='.gettext('Modifications applied. Please wait while your repository is being updated');
+            $panel->redirect($url);
+            return 1;
+        }
+    }
+
+    return 0;
+}

Deleted: trunk/vhffs-panel/git/prefs_save.pl
===================================================================
--- trunk/vhffs-panel/git/prefs_save.pl	2007-10-27 08:34:03 UTC (rev 1038)
+++ trunk/vhffs-panel/git/prefs_save.pl	2007-10-27 18:06:11 UTC (rev 1039)
@@ -1,144 +0,0 @@
-#!%PERL% -w
-# Copyright (c) vhffs project and its contributors
-# Copyright (c) 2007 Julien Danjou <julien@xxxxxxxxxxx>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without 
-# modification, are permitted provided that the following conditions 
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright 
-#   notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in 
-#   the documentation and/or other materials provided with the 
-#   distribution.
-#3. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
-# POSSIBILITY OF SUCH DAMAGE.
-
-
-use utf8;
-use POSIX qw(locale_h);
-use HTML::Template;
-use locale;
-use Locale::gettext;
-use CGI;
-use CGI::Session;
-use strict;
-use Data::Dumper;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Main;
-use Vhffs::Group;
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
-use Vhffs::Panel::Group;
-use Vhffs::Services::Git;
-
-my $panel = new Vhffs::Panel::Main();
-exit 0 unless $panel;
-my $session = $panel->get_session;
-exit 0 unless $session;
-
-my $vhffs = $panel->{'vhffs'};
-my $maintemplate = $panel->{'template'};
-my $user = $panel->{'user'};
-my $group = $panel->{'group'};
-my $cgi = $panel->{'cgi'};
-my $message;
-my $owner = $cgi->param("PROJECT_OWNER");
-
-my $repo = $cgi->param( "REPO_NAME" );
-my $public = $cgi->param( "PUBLIC" );
-my $ml_name = $cgi->param( "ML_NAME" );
-
-
-my $git = Vhffs::Services::Git::get_by_reponame( $vhffs , $repo );
-
-my $templatedir = $vhffs->get_config->get_templatedir;
-
-if( ! defined $repo )
-{
-    $message = sprintf( gettext("CGI Error ! %s"), $repo );
-}
-elsif( ! defined($git) )
-{
-    $message = gettext( "Cannot retrieve informations about this git repository" );
-}
-elsif( ( Vhffs::Acl::what_perm_for_user( $user , $git , $vhffs ) < Vhffs::Constants::ACL_MODIFY ) && ( $user->is_admin != 1 ) )
-{
-    $message = gettext( "You're not allowed to do this (ACL rights)" );
-}
-elsif( ( $git->get_status != Vhffs::Constants::ACTIVATED ) && ( $user->is_admin != 1 ) )
-{
-    $message = gettext( "This object is not functionnal yet. Please wait creation or moderation.");
-}
-else
-{
-
-    if( defined $public )
-    {
-        if( $public == 1 )
-        {
-            $git->set_public;
-        }
-        else
-        {
-            $git->set_private;
-        }
-
-        $git->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION );
-        if( $git->commit < 0 )
-        {
-                $message = gettext("An error occured while updating the git repository");
-        }
-        else
-        {
-                $message = gettext("Repository updated");
-        }
-    }
-
-    if ( defined $ml_name ) {
-        if( $ml_name eq '' || Vhffs::Functions::valid_mail($ml_name) ) {
-            $git->{ml_name} = $ml_name;
-            if( $git->commit_option < 0 ) {
-                $message = gettext("An error occured while updating the git repository");
-            } else {
-                $message = gettext("Repository updated");
-                $git->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION );
-        	if( $git->commit < 0 )
-	        {
-        	        $message = gettext("An error occured while updating the git repository");
-	        }
-        	else
-	        {
-        	        $message = gettext("Repository updated");
-	        }
-            }
-        } else {
-            $message = gettext('Mailing list address is invalid');
-        }
-    }
-}
-
-my $template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
-$template->param( MESSAGE => $message );
-
-$panel->set_refresh_url( "/group/view.pl?project=".$git->get_group->get_groupname, 0);
-$panel->build( $template );
-$panel->display;

Modified: trunk/vhffs-panel/templates/git/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/git/prefs.tmpl	2007-10-27 08:34:03 UTC (rev 1038)
+++ trunk/vhffs-panel/templates/git/prefs.tmpl	2007-10-27 18:06:11 UTC (rev 1039)
@@ -1,34 +1,26 @@
-<h1><tmpl_var name="TEXT_TITLE"> - <tmpl_var name="TEXT_REPONAME"></h1>
 <h2><tmpl_var name="TITLE_PUBLIC"></h2>
 
 
-<form method="post" action="/git/prefs_save.pl" accept-charset="utf-8">
+<form method="post" action="/git/prefs.pl" accept-charset="utf-8">
 	<p>
-		<label for="PUBLIC">
+		<label for="public">
 			<tmpl_var name="TEXT_PUBLIC"> :
 		</label>
-		<select name="PUBLIC" id="PUBLIC">
+		<select name="public" id="public">
 			<option value="1" <tmpl_var name="YES_SELECTED">><tmpl_var name="PUBLIC_YES"></option>
 			<option value="0" <tmpl_var name="NO_SELECTED">><tmpl_var name="PUBLIC_NO"></option>
 		</select>
 	</p>
-	<p class="button" id="buttonModify">
-		<input type="hidden" name="REPO_NAME" value="<tmpl_var name="TEXT_REPONAME">" />
-		<input type="submit" value="<tmpl_var name="TEXT_SEND">" />
-	</p>
-</form>
-
 <h2><tmpl_var name="TITLE_OPT"></h2>
-<form method="post" action="/git/prefs_save.pl" accept-charset="utf-8">
 	<p>
-		<label for="OPTION"><tmpl_var name="TEXT_OPT_ML"></label>
-                <input type="text" name="ML_NAME" value="<tmpl_var name="TEXT_ML_NAME">" />
+		<label for="ml_name"><tmpl_var name="TEXT_OPT_ML"></label>
+                <input type="text" name="ml_name" id="ml_name" value="<tmpl_var name="TEXT_ML_NAME">" />
 		<br/>
 		<tmpl_var name="TEXT_OPT_ML_REMINDER">
 	</p>
-	<p class="button" id="buttonModify">
-		<input type="hidden" name="REPO_NAME" value="<tmpl_var name="TEXT_REPONAME">" />
-		<input type="submit" value="<tmpl_var name="TEXT_SEND">" />
+	<p class="button">
+		<input type="hidden" name="name" value="<tmpl_var name="TEXT_REPONAME">" />
+		<input type="submit" value="<tmpl_var name="TEXT_SEND">" name="save_prefs_submit"/>
 	</p>
 </form>
 


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