[vhffs-dev] [838] CVS prefs now use only one page.

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


Revision: 838
Author:   beuss
Date:     2007-08-30 18:21:30 +0000 (Thu, 30 Aug 2007)

Log Message:
-----------
CVS prefs now use only one page.
Added a couple of method to Vhffs::User to simplify permissions checks.

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

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


Modified: trunk/vhffs-api/src/Vhffs/Services/Cvs.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Cvs.pm	2007-08-30 18:17:23 UTC (rev 837)
+++ trunk/vhffs-api/src/Vhffs/Services/Cvs.pm	2007-08-30 18:21:30 UTC (rev 838)
@@ -125,28 +125,30 @@
 {
 	my $self = shift;	
 
-	my $query = "UPDATE vhffs_cvs SET cvsroot='".$self->{'cvsroot'}."', public='".$self->{'public'}."' WHERE cvs_id='".$self->{'cvs_id'}."'";
+    my $sql = 'UPDATE vhffs_cvs SET cvsroot = ?, public = ? WHERE cvs_id = ?';
+    $self->get_db_object()->do($sql, undef, $self->{'cvsroot'},
+                                        $self->{'public'}, $self->{'cvs_id'})
+                                            or return -1;
 
-	my $request = $self->{'db'}->prepare($query);
-	$request->execute or return -1;
-
 	return -2 if( $self->SUPER::commit < 0 );
 	return 1;
 }
 
 
+=head2 set_public
+
+    $cvs->set_public(0);
+
+Defines if a CVS repository is public (param == 1) or not (0).
+
+=cut
+
 sub set_public
 {
-	my $self = shift;
-	$self->{'public'} = "TRUE";
+	my ($self, $public) = @_;
+	$self->{'public'} = $public;
 }
 
-sub set_private
-{
-	my $self = shift;
-	$self->{'public'} = "FALSE";
-}
-
 sub is_public
 {
 	my $self = shift;

Modified: trunk/vhffs-api/src/Vhffs/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/User.pm	2007-08-30 18:17:23 UTC (rev 837)
+++ trunk/vhffs-api/src/Vhffs/User.pm	2007-08-30 18:21:30 UTC (rev 838)
@@ -84,6 +84,7 @@
 use DBI;
 use Vhffs::Group;
 use Vhffs::Functions;
+use Vhffs::Acl;
 
 sub _new {
     my ($class, $main, $uid, $gid, $oid, $username, $passwd, $homedir, $shell, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, $note, $language, $theme, $date_creation, $description, $state) = @_;
@@ -724,7 +725,43 @@
 	return \@groups;
 }
 
+=head2 can_modify
 
+    die("You are not allowed to modify this object\n")
+                                unless($user->can_modify($object));
+
+Returns true if the user on which the method is called can modify the given
+object.
+
+=cut
+
+sub can_modify
+{
+    my ($self, $o) = @_;
+    return (Vhffs::Acl::what_perm_for_user( $self, $o, $self->get_main) >= Vhffs::Constants::ACL_MODIFY
+        || $self->is_admin );
+}
+
+=head2 can_view
+
+    die("You are not allowed to view this object\n")
+                                unless($user->can_view($object));
+
+Returns true if the user on which the method is called can view the given
+object.
+
+=cut
+
+sub can_view
+{
+    my ($self, $o) = @_;
+    return (Vhffs::Acl::what_perm_for_user( $self, $o, $self->get_main) >= Vhffs::Constants::ACL_VIEW
+        || $self->is_admin );
+}
+
+
+
+
 sub have_activegroups
 {
 	my $self = shift;

Modified: trunk/vhffs-panel/Makefile.am
===================================================================
--- trunk/vhffs-panel/Makefile.am	2007-08-30 18:17:23 UTC (rev 837)
+++ trunk/vhffs-panel/Makefile.am	2007-08-30 18:21:30 UTC (rev 838)
@@ -97,7 +97,6 @@
 	cvs/create.pl \
 	cvs/delete.pl \
 	cvs/index.pl \
-	cvs/prefs_save.pl \
 	cvs/prefs.pl \
 	dns/create.pl \
 	dns/delete.pl \

Modified: trunk/vhffs-panel/cvs/prefs.pl
===================================================================
--- trunk/vhffs-panel/cvs/prefs.pl	2007-08-30 18:17:23 UTC (rev 837)
+++ trunk/vhffs-panel/cvs/prefs.pl	2007-08-30 18:21:30 UTC (rev 838)
@@ -75,7 +75,7 @@
 	$template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
 	$message = gettext( "Cannot get informations on this object");
 	$template->param( MESSAGE => $message );
-} elsif( ( Vhffs::Acl::what_perm_for_user( $user , $cvs , $vhffs ) < Vhffs::Constants::ACL_VIEW ) && ( $user->is_admin != 1 ) ) {
+} elsif( ! $user->can_view($cvs) ) {
 	$template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
 	$message = gettext( "You're not allowed to do this (ACL rights)");
 	$template->param( MESSAGE => $message );
@@ -84,6 +84,34 @@
     $message = gettext( "This object is not functionnal yet. Please wait creation, moderation or modification.");
 	$template->param( MESSAGE => $message );
 } else {
+    my $cgi = $panel->{cgi};
+    if( defined $cgi->param('cvs_public_submit') ) {
+        if(! $user->can_modify($cvs)) {
+            $panel->add_error( gettext("You are not allowed to modify this object (ACL rights)") );
+        } elsif( !defined($cgi->param('public')) ) {
+            $panel->add_error( gettext("CGI error") );
+        } else {
+            $cvs->set_public($cgi->param('public'));
+            $cvs->set_status(Vhffs::Constants::WAITING_FOR_MODIFICATION);
+            if($cvs->commit > 0) {
+                $panel->add_info(gettext("CVS repository updated"));
+            } else {
+                $panel->add_error(gettext("An error occured during CVS repository update"));
+            }
+        }
+    } elsif( defined $cgi->param('cvs_fixperms_submit')) {
+        if(! $user->can_modify($cvs) ) {
+            $panel->add_error( gettext("You are not allowed to modify this object (ACL rights)") );
+        } else {
+            $cvs->set_status(Vhffs::Constants::WAITING_FOR_MODIFICATION);
+        }
+        if($cvs->commit > 0) {
+                $panel->add_info(gettext("CVS repository updated"));
+        } else {
+                $panel->add_error(gettext("An error occured during CVS repository update"));
+        }
+    }
+
 	$template = new HTML::Template( filename => $templatedir."/panel/cvs/prefs.tmpl" );
 
 	$panel->set_title( gettext('Admin CVS Repository') );
@@ -108,12 +136,7 @@
     $template->param( PERM_TEXT => "Fixing permissions on a repository solve permission access on the repository. Can be helpful if you encounter problems" );
     $template->param( PERM_BUTTON => "Fix it" );
 
-	if( $cvs->is_public == 1 ) {
-    	$template->param( YES_SELECTED => "selected" );
-	} else {
-    	$template->param( NO_SELECTED => "selected" );
-	}
-
+    $template->param( PUBLIC => $cvs->is_public );
 }
 
 display Vhffs::Panel::Main($panel, $template->output );

Deleted: trunk/vhffs-panel/cvs/prefs_save.pl
===================================================================
--- trunk/vhffs-panel/cvs/prefs_save.pl	2007-08-30 18:17:23 UTC (rev 837)
+++ trunk/vhffs-panel/cvs/prefs_save.pl	2007-08-30 18:21:30 UTC (rev 838)
@@ -1,124 +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 POSIX qw(locale_h);
-use HTML::Template;
-use locale;
-use Locale::gettext;
-use CGI;
-use CGI::Session;
-use strict;
-
-
-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::Cvs;
-
-my $panel = new Vhffs::Panel::Main();
-if(!$panel)  {
-        exit 0;
-}
-
-my $vhffs = $panel->{'vhffs'};
-my $session = $panel->{'session'};
-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 $templatedir = $vhffs->get_config->get_templatedir;
-
-my $cvs;
-
-if( ( ! defined $repo ) )
-{
-    $message = sprintf( gettext("CGI Error ! %s"), $repo );
-
-} elsif( !defined($cvs = Vhffs::Services::Cvs::get_by_cvsroot($vhffs, $repo) ) ) {
-	$message = gettext( "Cannot retrieve informations about this CVS repository" );
-}
-elsif( ( Vhffs::Acl::what_perm_for_user( $user , $cvs , $vhffs ) < Vhffs::Constants::ACL_MODIFY ) && ( $user->is_admin != 1 ) )
-{
-	$message = gettext( "You're not allowed to do this (ACL rights)" );
-}
-elsif( $cvs->get_status != Vhffs::Constants::ACTIVATED )
-{
-    $message = gettext( "This object is not functionnal yet. Please wait creation or moderation.");
-}
-else
-{
-
-	#If public is defined, the user want change the CVS
-	#permission status
-	#Else, he just want update rights, so, we update the status
-	#with WAITING_FOR_MODIFICATION to leave the robots modify permissions
-	if( defined $public )
-	{
-		if( $public == 1 )
-		{
-		    $cvs->set_public;
-		}
-		else
-		{
-		    $cvs->set_private;
-		}
-	}
-
-	$cvs->set_status( Vhffs::Constants::WAITING_FOR_MODIFICATION );	
-
-
-	#Commit what we modify on the current object
-	if( $cvs->commit < 0 )
-	{
-	        $message .= gettext("An error occured while updating the CVS repository");
-	}  
-	else  
-	{
-        $message .= gettext("CVS repository updated");
-	}
-}
-
-my $template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
-$template->param( MESSAGE => $message );
-
-set_refresh_url Vhffs::Panel::Main($panel, "/panel.pl?project=".$cvs->get_group->get_groupname, 0);
-display Vhffs::Panel::Main($panel, $template->output);

Modified: trunk/vhffs-panel/templates/cvs/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/cvs/prefs.tmpl	2007-08-30 18:17:23 UTC (rev 837)
+++ trunk/vhffs-panel/templates/cvs/prefs.tmpl	2007-08-30 18:21:30 UTC (rev 838)
@@ -1,32 +1,32 @@
 <h2><tmpl_var name="TEXT_REPONAME"></h2>
 
-<form method="post" action="/cvs/prefs_save.pl">
+<form method="post" action="/cvs/prefs.pl">
 	<p>
 		<label>
-			<tmpl_var name="TEXT_PUBLIC"> :
+			<tmpl_var name="TEXT_PUBLIC">
 		</label>
-		<select name="PUBLIC" size=2 multiple>
-		<option value="1" <tmpl_var name="YES_SELECTED">><tmpl_var name="PUBLIC_YES">
-		<option value="0" <tmpl_var name="NO_SELECTED">><tmpl_var name="PUBLIC_NO">
+		<select name="public" size="2" multiple="multiple">
+		<option value="1" <tmpl_if name="PUBLIC">selected="selected"</tmpl_if>><tmpl_var name="PUBLIC_YES">
+		<option value="0" <tmpl_unless name="PUBLIC">selected="selected"</tmpl_unless>><tmpl_var name="PUBLIC_NO">
 		</select>
 	</p>
 	
 
 	<p class="button" id="buttonSend">
-		<input type="hidden" name="REPO_NAME" value="<tmpl_var name="TEXT_REPONAME">" />
-		<input type="submit" value="<tmpl_var name="TEXT_SEND">" />
+		<input type="hidden" name="name" value="<tmpl_var name="TEXT_REPONAME">" />
+		<input type="submit" value="<tmpl_var name="TEXT_SEND">" name="cvs_public_submit"/>
 	</p>
 </form>
 
 
 <h2><tmpl_var name="PERM_TITLE"></h2>
-<form method="post" action="/cvs/prefs_save.pl">
+<form method="post" action="/cvs/prefs.pl">
 	<p>
 		<tmpl_var name="PERM_TEXT">
     </p>
     <p class="button">
-        <input type="submit" value="<tmpl_var name="PERM_BUTTON">" />
-		<input type="hidden" name="REPO_NAME" value="<tmpl_var name="TEXT_REPONAME">" />
+        <input type="submit" value="<tmpl_var name="PERM_BUTTON">" name="cvs_fixperms_submit"/>
+		<input type="hidden" name="name" value="<tmpl_var name="TEXT_REPONAME">" />
 	</p>
 </form>
 


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