Module: nagvis
Branch: master
Commit: 92cd1268e1b4c5a4c4a911c3208926824a5563e7
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=92cd1268e1b4c5a4c4a911c3208926824a5563e7

Author: LaMi <[email protected]>
Date:   Sun Nov 15 15:10:26 2009 +0100

Added role deletion dialog and mechanism

---

 .../core/classes/CoreAuthorisationHandler.php      |    6 +++
 .../core/classes/CoreAuthorisationModSQLite.php    |   15 +++++++
 share/server/core/classes/CoreModRoleMgmt.php      |   43 +++++++++++++++++++-
 share/server/core/classes/CoreModUserMgmt.php      |    2 +
 .../server/core/classes/NagVisViewManageRoles.php  |    4 +-
 .../templates/pages/default.manageRoles.html       |   20 +++++++++
 6 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/share/server/core/classes/CoreAuthorisationHandler.php 
b/share/server/core/classes/CoreAuthorisationHandler.php
index 5298cf1..9a8e773 100644
--- a/share/server/core/classes/CoreAuthorisationHandler.php
+++ b/share/server/core/classes/CoreAuthorisationHandler.php
@@ -88,6 +88,12 @@ class CoreAuthorisationHandler {
                return $this->sModuleName;
        }
        
+       public function deleteRole($roleId) {
+               // FIXME: First check if this is supported
+               
+               return $this->MOD->deleteRole($roleId);
+       }
+       
        public function deleteUser($userId) {
                // FIXME: First check if this is supported
                
diff --git a/share/server/core/classes/CoreAuthorisationModSQLite.php 
b/share/server/core/classes/CoreAuthorisationModSQLite.php
index 591be6f..f615c2e 100644
--- a/share/server/core/classes/CoreAuthorisationModSQLite.php
+++ b/share/server/core/classes/CoreAuthorisationModSQLite.php
@@ -42,6 +42,21 @@ class CoreAuthorisationModSQLite extends 
CoreAuthorisationModule {
                }
        }
        
+       public function deleteRole($roleId) {
+               // Delete user
+               $this->DB->query('DELETE FROM roles WHERE 
roleId=\''.sqlite_escape_string($roleId).'\'');
+               
+               // Delete role permissions
+               $this->DB->query('DELETE FROM roles2perms WHERE 
roleId=\''.sqlite_escape_string($roleId).'\'');
+               
+               // Check result
+               if(!$this->checkRoleExists($roleId)) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+       
        public function deleteUser($userId) {
                // Delete user
                $this->DB->query('DELETE FROM users WHERE 
userId=\''.sqlite_escape_string($userId).'\'');
diff --git a/share/server/core/classes/CoreModRoleMgmt.php 
b/share/server/core/classes/CoreModRoleMgmt.php
index 655a148..b4e92f9 100644
--- a/share/server/core/classes/CoreModRoleMgmt.php
+++ b/share/server/core/classes/CoreModRoleMgmt.php
@@ -9,7 +9,8 @@ class CoreModRoleMgmt extends CoreModule {
                $this->aActions = Array('view' => REQUIRES_AUTHORISATION,
                                        'getRolePerms' => 
REQUIRES_AUTHORISATION,
                                        'doAdd' => REQUIRES_AUTHORISATION,
-                                       'doEdit' => REQUIRES_AUTHORISATION);
+                                       'doEdit' => REQUIRES_AUTHORISATION,
+                                       'doDelete' => REQUIRES_AUTHORISATION);
                
                $this->FHANDLER = new CoreRequestHandler($_POST);
        }
@@ -67,12 +68,52 @@ class CoreModRoleMgmt extends CoreModule {
                                                $sReturn = '';
                                        }
                                break;
+                               case 'doDelete':
+                                       $aReturn = 
$this->handleResponseDelete();
+                                       
+                                       if($aReturn !== false) {
+                                               
if($this->AUTHORISATION->deleteRole($aReturn['roleId'])) {
+                                                       new 
GlobalMessage('NOTE', $this->CORE->getLang()->getText('The role has been 
deleted.'));
+                                                       $sReturn = '';
+                                               } else {
+                                                       new 
GlobalMessage('NOTE', $this->CORE->getLang()->getText('Problem while deleting 
the role.'));
+                                                       $sReturn = '';
+                                               }
+                                       } else {
+                                               new GlobalMessage('ERROR', 
$this->CORE->getLang()->getText('You entered invalid information.'));
+                                               $sReturn = '';
+                                       }
+                               break;
                        }
                }
                
                return $sReturn;
        }
        
+       private function handleResponseDelete() {
+               $bValid = true;
+               // Validate the response
+               
+               // Check for needed params
+               if($bValid && !$this->FHANDLER->isSetAndNotEmpty('roleId')) {
+                       $bValid = false;
+               }
+               
+               // Parse the specific options
+               // FIXME: validate
+               $roleId = intval($this->FHANDLER->get('roleId'));
+               
+               // FIXME: Check not to delete any referenced role
+               
+         // Store response data
+         if($bValid === true) {
+                 // Return the data
+                 return Array('roleId' => $roleId);
+               } else {
+                       return false;
+               }
+       }
+       
        private function handleResponseEdit() {
                $bValid = true;
                // Validate the response
diff --git a/share/server/core/classes/CoreModUserMgmt.php 
b/share/server/core/classes/CoreModUserMgmt.php
index e227ef4..1781539 100644
--- a/share/server/core/classes/CoreModUserMgmt.php
+++ b/share/server/core/classes/CoreModUserMgmt.php
@@ -107,6 +107,8 @@ class CoreModUserMgmt extends CoreModule {
                // FIXME: validate
                $userId = intval($this->FHANDLER->get('userId'));
                
+               // FIXME: Add check not to delete own user
+               
          // Store response data
          if($bValid === true) {
                  // Return the data
diff --git a/share/server/core/classes/NagVisViewManageRoles.php 
b/share/server/core/classes/NagVisViewManageRoles.php
index f09a0a1..0da9a28 100644
--- a/share/server/core/classes/NagVisViewManageRoles.php
+++ b/share/server/core/classes/NagVisViewManageRoles.php
@@ -55,6 +55,7 @@ class NagVisViewManageRoles {
                        'htmlBase' => 
$this->CORE->getMainCfg()->getValue('paths', 'htmlbase'),
                        'formTargetAdd' => 
$this->CORE->getMainCfg()->getValue('paths','htmlbase').'/server/core/ajax_handler.php?mod=RoleMgmt&amp;act=doAdd',
                        'formTargetEdit' => 
$this->CORE->getMainCfg()->getValue('paths','htmlbase').'/server/core/ajax_handler.php?mod=RoleMgmt&amp;act=doEdit',
+                       'formTargetDelete' => 
$this->CORE->getMainCfg()->getValue('paths','htmlbase').'/server/core/ajax_handler.php?mod=RoleMgmt&amp;act=doDelete',
                        'htmlImages' => 
$this->CORE->getMainCfg()->getValue('paths', 'htmlimages'),
       'maxRolenameLength' => AUTH_MAX_PASSWORD_LENGTH,
       'langRoleAdd' => $this->CORE->getLang()->getText('Create Role'),
@@ -65,7 +66,8 @@ class NagVisViewManageRoles {
       'langAction' => $this->CORE->getLang()->getText('Action'),
       'langObject' => $this->CORE->getLang()->getText('Object'),
       'langPermitted' => $this->CORE->getLang()->getText('Permitted'),
-      'langRoleModify' => $this->CORE->getLang()->getText('Save Changes'),
+      'langRoleModify' => $this->CORE->getLang()->getText('Modify Role'),
+      'langRoleDelete' => $this->CORE->getLang()->getText('Delete Role'),
       'roles' => $this->AUTHORISATION->getAllRoles(),
       'perms' => $this->AUTHORISATION->getAllVisiblePerms()
                );
diff --git a/share/userfiles/templates/pages/default.manageRoles.html 
b/share/userfiles/templates/pages/default.manageRoles.html
index 32c8e25..94f9b52 100644
--- a/share/userfiles/templates/pages/default.manageRoles.html
+++ b/share/userfiles/templates/pages/default.manageRoles.html
@@ -87,4 +87,24 @@ function selectRolePerms(id) \{
                </p>
        </form>
 </fieldset>
+</div>
+
+<div id="deleteRoles">
+<fieldset class="form">
+       <legend>{$langRoleDelete}</legend>
+       <form name="roleDelete" id="roleDeleteForm" action="#" 
onsubmit="submitFrontendForm('{$formTargetDelete}', 'roleDeleteForm');return 
false" method="post">
+               <table>
+                       <tr>
+                               <td><label 
for="roleId">{$langRoleName}:</label></td>
+                               <td>
+                                       <select type="text" name="roleId" 
id="roleId" class="select" tabindex="40" />
+                                               <option value="" 
selected="selected"></option>
+                                               {foreach $roles role}<option 
value="{$role.roleId}">{$role.name}</option>{/foreach}
+                                       </select>
+                               </td>
+                               <td><input type="submit" name="submit" 
id="submit" value="{$langRoleDelete}" tabindex="100" /></td>
+                       </tr>
+               </table>
+       </form>
+</fieldset>
 </div>
\ No newline at end of file


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to