[Fusionforge-commits] r10604 - in trunk/src: common/include www/project/admin

Alain Peyrat aljeux at libremir.placard.fr.eu.org
Tue Sep 21 19:37:37 CEST 2010


Author: aljeux
Date: 2010-09-21 19:37:36 +0200 (Tue, 21 Sep 2010)
New Revision: 10604

Added:
   trunk/src/www/project/admin/roledelete.php
Modified:
   trunk/src/common/include/Role.class.php
   trunk/src/www/project/admin/roleedit.php
Log:
Initial code for deleting a role (not activated)

Modified: trunk/src/common/include/Role.class.php
===================================================================
--- trunk/src/common/include/Role.class.php	2010-09-21 17:37:30 UTC (rev 10603)
+++ trunk/src/common/include/Role.class.php	2010-09-21 17:37:36 UTC (rev 10604)
@@ -489,6 +489,52 @@
 		return true;
 	}
 
+	/**
+	 *	delete - delete a role in the database.
+	 *
+	 *	@return	boolean	True on success or false on failure.
+	 */
+	function delete() {
+
+		if (!is_numeric($this->getID())) {
+			$this->setError('Role::delete() role_id is not an integer');
+			return false;
+		}
+
+		//	Cannot delete role_id=1
+		if ($this->getID() == 1) {
+			$this->setError('Cannot Delete Default Role.');
+			return false;
+		}
+		$perm =& $this->Group->getPermission();
+		if (!$perm || !is_object($perm) || $perm->isError() || !$perm->isAdmin()) {
+			$this->setPermissionDeniedError();
+			return false;
+		}
+
+		$res=db_query_params('SELECT user_id FROM user_group WHERE role_id=$1',
+			array($this->getID()));
+		assert($res);
+		if (db_numrows($res) > 0) {
+			$this->setError('Cannot remove a non empty role.');
+			return false;
+		}
+
+		db_begin();
+
+		$res=db_query_params('DELETE FROM role WHERE group_id=$1 AND role_id=$2',
+			array($this->Group->getID(), $this->getID())) ;
+		if (!$res || db_affected_rows($res) < 1) {
+			$this->setError('delete::name::'.db_error());
+			db_rollback();
+			return false;
+		}
+
+		db_commit();
+
+		return true;
+	}
+
 	function setUser($user_id) {
 		global $SYS;
 		if (USE_PFO_RBAC) {

Added: trunk/src/www/project/admin/roledelete.php
===================================================================
--- trunk/src/www/project/admin/roledelete.php	                        (rev 0)
+++ trunk/src/www/project/admin/roledelete.php	2010-09-21 17:37:36 UTC (rev 10604)
@@ -0,0 +1,86 @@
+<?php
+/**
+ * Role Delete Page
+ *
+ * Copyright 2010 (c) Alcatel-Lucent
+ *
+ * @author Alain Peyrat
+ * @date 2010-05-18
+ *
+ * This file is part of GForge.
+ *
+ * GForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GForge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+require_once('../../env.inc.php');
+require_once $gfcommon.'include/pre.php';
+require_once $gfwww.'project/admin/project_admin_utils.php';
+require_once $gfcommon.'include/Role.class.php';
+
+$group_id = getIntFromRequest('group_id');
+$role_id = getIntFromRequest('role_id');
+
+session_require(array('group'=>$group_id,'admin_flags'=>'A'));
+
+if (!$role_id) {
+	session_redirect('/project/admin/users.php?group_id='.$group_id);
+}
+
+$group = group_get_object($group_id);
+
+$role = new Role($group,$role_id);
+if (!$role || !is_object($role)) {
+	exit_error('Error',_('Could Not Get Role'));
+} elseif ($role->isError()) {
+	exit_error('Error',$role->getErrorMessage());
+}
+
+if (getStringFromRequest('submit')) {
+	if (getIntFromRequest('sure')) {
+		if (!$role->delete()) {
+			$error_msg = _('ERROR: ').$role->getErrorMessage();
+		} else {
+			$feedback = _('Successfully Deleted Role');
+		}
+	} else {
+		$error_msg = 'Error: Please check "I\'m Sure" to confirm or return to previous page to cancel.';
+	}
+
+	//plugin webcal
+	//change assistant for webcal
+	$params = getIntFromRequest('group_id');
+	plugin_hook('change_cal_permission_auto',$params);
+	
+	if (!isset($error_msg)) {
+		session_redirect('/project/admin/users.php?group_id='.$group_id.'&feedback='.urlencode($feedback));
+	}
+}
+
+$title = sprintf(_('Permanently Delete Role %s'), $role->getName());
+project_admin_header(array('title'=>$title,'group'=>$group_id));
+
+printf(_('You are about to permanently delete role %s'), $role->getName()); ?>
+
+<form action="<?php echo getStringFromServer('PHP_SELF') ?>?group_id=<?php echo $group_id ?>&amp;role_id=<?php echo $role_id ?>" method="post">
+<p>
+<input name="sure" value="1" type="checkbox" /><?php echo _("I'm Sure.") ?><br />
+</p>
+
+<p>
+<input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
+</p>
+</form>
+
+<?php project_admin_footer(array()) ?>

Modified: trunk/src/www/project/admin/roleedit.php
===================================================================
--- trunk/src/www/project/admin/roleedit.php	2010-09-21 17:37:30 UTC (rev 10603)
+++ trunk/src/www/project/admin/roleedit.php	2010-09-21 17:37:36 UTC (rev 10604)
@@ -37,6 +37,10 @@
 
 $group = group_get_object($group_id);
 
+if (getStringFromRequest('delete')) {
+	session_redirect('/project/admin/roledelete.php?group_id='.$group_id.'&role_id='.$role_id);
+}
+
 //
 //	The observer is a special role, which is actually
 //	just controlling the is_public/allow anon flags




More information about the Fusionforge-commits mailing list