[vhffs-dev] [1037] SVN prefs handling are now all in prefs.pl.

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


Revision: 1037
Author:   beuss
Date:     2007-10-26 22:16:27 +0000 (Fri, 26 Oct 2007)

Log Message:
-----------
SVN prefs handling are now all in prefs.pl.

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

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


Modified: trunk/vhffs-api/src/Vhffs/Services/Svn.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Svn.pm	2007-10-26 22:11:54 UTC (rev 1036)
+++ trunk/vhffs-api/src/Vhffs/Services/Svn.pm	2007-10-26 22:16:27 UTC (rev 1037)
@@ -142,24 +142,13 @@
 {
     my $self = shift;    
 
-    my $query = "UPDATE vhffs_svn SET public= '".$self->{'public'}."' WHERE svn_id=$self->{'svn_id'}";
-    my $request = $self->{'db'}->prepare($query);
-    $request->execute;
+    my $dbh = $self->get_db_object;
+    my $sql = 'UPDATE vhffs_svn SET public = ?, ml_name = ? WHERE svn_id = ?';
+    $dbh->do($sql, undef, $self->{public}, $self->{ml_name}, $self->{svn_id});
 
     $self->SUPER::commit;
 }
 
-sub commit_option
-{
-    my $self = shift;
-
-    my $query = "UPDATE vhffs_svn SET ml_name= '".$self->{'ml_name'}."' WHERE svn_id=$self->{'svn_id'}";
-    my $request = $self->{'db'}->prepare($query);
-    $request->execute;
-
-    $self->SUPER::commit;
-}
-
 sub set_public
 {
     my $self = shift;
@@ -197,6 +186,16 @@
     return $self->{reponame};
 }
 
+sub get_ml_name {
+    my $self = shift;
+    return $self->{ml_name};
+}
+
+sub set_ml_name {
+    my ($self, $ml_name) = @_;
+    $self->{ml_name} = $ml_name;
+}
+
 sub getall
 {
     my ($vhffs, $state, $name, $group) = @_;

Modified: trunk/vhffs-panel/Makefile.am
===================================================================
--- trunk/vhffs-panel/Makefile.am	2007-10-26 22:11:54 UTC (rev 1036)
+++ trunk/vhffs-panel/Makefile.am	2007-10-26 22:16:27 UTC (rev 1037)
@@ -110,7 +110,6 @@
 	svn/create.pl \
 	svn/delete.pl \
 	svn/index.pl \
-	svn/prefs_save.pl \
 	svn/prefs.pl \
 	git/create.pl \
 	git/delete.pl \

Modified: trunk/vhffs-panel/svn/prefs.pl
===================================================================
--- trunk/vhffs-panel/svn/prefs.pl	2007-10-26 22:11:54 UTC (rev 1036)
+++ trunk/vhffs-panel/svn/prefs.pl	2007-10-26 22:16:27 UTC (rev 1037)
@@ -95,9 +95,14 @@
 }
 else
 {
+    if(defined $cgi->param('prefs_save_submit')) {
+        if(save_prefs()) {
+            exit;
+        }
+    }
     $template = new HTML::Template( filename => $templatedir."/panel/svn/prefs.tmpl" );
 
-    $template->param( TEXT_TITLE => gettext("Admin Subversion Repository") );
+    $panel->set_title( gettext("Admin Subversion Repository") );
     
     
     $template->param( TEXT_REPONAME => $svn->get_reponame );
@@ -147,3 +152,48 @@
 
 $panel->build( $template );
 $panel->display;
+
+sub save_prefs {
+    my $public = $cgi->param('public');
+    my $ml_name = $cgi->param('ml_name');
+
+    if(!$user->can_modify($svn)) {
+        $panel->add_error( gettext('You are not allowed to modify this SVN Object (ACL Rights)') );
+        return 0;
+    }
+
+    if(!defined $ml_name || !defined $public) {
+        $panel->add_error( gettext('CGI Error') );
+        return 0;
+    }
+
+    if($public == 1 && !$svn->is_public) {
+        $svn->set_public;
+        $svn->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION );
+    } elsif($public == 0 && $svn->is_public) {
+        $svn->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION );
+        $svn->set_private;
+    }
+
+    if(($ml_name =~ /^\s*$/ || Vhffs::Functions::valid_mail($ml_name))) {
+        if($ml_name ne $svn->get_ml_name) {
+            $svn->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION );
+            $svn->set_ml_name($ml_name);
+        }
+    } else {
+        $panel->add_error( gettext('Mailing list address is invalid') );
+        return 0;
+    }
+
+    if($svn->get_status == Vhffs::Constants::WAITING_FOR_MODIFICATION) {
+        if($svn->commit > 0) {
+            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;
+
+        } else {
+            $panel->add_error( gettext('Unable to update repository') );
+            return 0;
+        }
+    }
+}

Deleted: trunk/vhffs-panel/svn/prefs_save.pl
===================================================================
--- trunk/vhffs-panel/svn/prefs_save.pl	2007-10-26 22:11:54 UTC (rev 1036)
+++ trunk/vhffs-panel/svn/prefs_save.pl	2007-10-26 22:16:27 UTC (rev 1037)
@@ -1,143 +0,0 @@
-#!%PERL% -w
-# Copyright (c) vhffs project and its contributors
-# 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::Svn;
-
-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 $svn = Vhffs::Services::Svn::get_by_reponame( $vhffs , $repo );
-
-my $templatedir = $vhffs->get_config->get_templatedir;
-
-if( ! defined $repo )
-{
-    $message = sprintf( gettext("CGI Error ! %s"), $repo );
-}
-elsif( ! defined($svn) )
-{
-    $message = gettext( "Cannot retrieve informations about this Subversion repository" );
-}
-elsif( ( Vhffs::Acl::what_perm_for_user( $user , $svn , $vhffs ) < Vhffs::Constants::ACL_MODIFY ) && ( $user->is_admin != 1 ) )
-{
-    $message = gettext( "You're not allowed to do this (ACL rights)" );
-}
-elsif( ( $svn->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 )
-        {
-            $svn->set_public;
-        }
-        else
-        {
-            $svn->set_private;
-        }
-
-        $svn->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION );
-        if( $svn->commit < 0 )
-        {
-                $message = gettext("An error occured while updating the Subversion repository");
-        }
-        else
-        {
-                $message = gettext("Repository updated");
-        }
-    }
-
-    if ( defined $ml_name ) {
-        if( $ml_name eq '' || Vhffs::Functions::valid_mail($ml_name) ) {
-            $svn->{ml_name} = $ml_name;
-            if( $svn->commit_option < 0 ) {
-                $message = gettext("An error occured while updating the Subversion repository");
-            } else {
-                $message = gettext("Repository updated");
-                $svn->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION );
-        	if( $svn->commit < 0 )
-	        {
-        	        $message = gettext("An error occured while updating the Subversion 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=".$svn->get_group->get_groupname, 0);
-$panel->build( $template );
-$panel->display;

Modified: trunk/vhffs-panel/templates/svn/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/svn/prefs.tmpl	2007-10-26 22:11:54 UTC (rev 1036)
+++ trunk/vhffs-panel/templates/svn/prefs.tmpl	2007-10-26 22:16:27 UTC (rev 1037)
@@ -1,34 +1,24 @@
-<h1><tmpl_var name="TEXT_TITLE"> - <tmpl_var name="TEXT_REPONAME"></h1>
+<form method="post" action="/svn/prefs.pl" accept-charset="utf-8">
 <h2><tmpl_var name="TITLE_PUBLIC"></h2>
-
-
-<form method="post" action="/svn/prefs_save.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="/svn/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="option"><tmpl_var name="TEXT_OPT_ML"></label>
+                <input type="text" name="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="prefs_save_submit"/>
 	</p>
 </form>
 


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