From 32ea4716cf8a54003616c4cedb65166098bf305c Mon Sep 17 00:00:00 2001 From: Jonathan Byrne Date: Tue, 13 Nov 2007 13:08:26 +0000 Subject: [PATCH] KTS-1390 "A more precise error message needed when creating a duplicate of an already existing Permission" --- i18n/knowledgeTree.pot | 28 ++++++++++++++++++++++++++-- plugins/ktcore/admin/managePermissions.php | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- templates/ktcore/manage_permissions.smarty | 19 ++++++++++++++++++- 3 files changed, 124 insertions(+), 13 deletions(-) diff --git a/i18n/knowledgeTree.pot b/i18n/knowledgeTree.pot index 36c507a..abf5278 100644 --- a/i18n/knowledgeTree.pot +++ b/i18n/knowledgeTree.pot @@ -4062,8 +4062,32 @@ msgstr "" msgid "Error creating allocation" msgstr "" -#: plugins/ktcore/admin/managePermissions.php:76 -msgid "Error creating permission" +#: plugins/ktcore/admin/managePermissions.php:81 +msgid "An error occured while creating your permission" +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:86 +msgid "An error occured while creating your permission: The System Name was not provided." +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:92 +msgid "An error occured while creating your permission: The Display Name was not provided." +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:98 +msgid "An error occured while creating your permission: The Display Name and System Name weren't provided." +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:120 +msgid "An error occured while creating your permission: The Display Name and System Name you have provided both already exist." +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:129 +msgid "An error occured while creating your permission: A permission with the same System Name already exists." +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:138 +msgid "An error occured while creating your permission: A permission with the same Display Name already exists." msgstr "" #: plugins/ktcore/admin/managePermissions.php:95 diff --git a/plugins/ktcore/admin/managePermissions.php b/plugins/ktcore/admin/managePermissions.php index 765087f..9bedf9e 100755 --- a/plugins/ktcore/admin/managePermissions.php +++ b/plugins/ktcore/admin/managePermissions.php @@ -44,13 +44,25 @@ require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php"); class ManagePermissionsDispatcher extends KTAdminDispatcher { var $sHelpPage = 'ktcore/admin/manage permissions.html'; function do_main() { + session_start(); $this->oPage->setTitle(_kt('Manage Permissions')); $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Manage Permissions')); $add_fields = array(); - $add_fields[] = new KTStringWidget(_kt('System Name'), _kt('The internal name used for the permission. This should never be changed.'), 'name', null, $this->oPage, true); - $add_fields[] = new KTStringWidget(_kt('Display Name'), _kt('A short name that is shown to users whenever permissions must be assigned.'), 'human_name', null, $this->oPage, true); + $add_fields[] = new KTStringWidget(_kt('System Name'), _kt('The internal name used for the permission. This should never be changed.'), 'name', null, $this->oPage, true, 'name'); + $add_fields[] = new KTStringWidget(_kt('Display Name'), _kt('A short name that is shown to users whenever permissions must be assigned.'), 'human_name', null, $this->oPage, true, 'human_name'); + if($_SESSION['Permission']['NameValue']) + { + $this->sNameVal = $_SESSION['Permission']['NameValue']; + $_SESSION['Permission']['NameValue'] = ''; + } + else if($_SESSION['Permission']['HumanNameValue']) + { + $this->sHumanNameVal = $_SESSION['Permission']['HumanNameValue']; + $_SESSION['Permission']['HumanNameValue'] = ''; + } + $oTemplating =& KTTemplating::getSingleton(); $aPermissions =& KTPermission::getList(); $oTemplate = $oTemplating->loadTemplate("ktcore/manage_permissions"); @@ -63,17 +75,75 @@ class ManagePermissionsDispatcher extends KTAdminDispatcher { } function do_newPermission() { - $name = KTUtil::arrayGet($_REQUEST, 'name'); - $human_name = KTUtil::arrayGet($_REQUEST, 'human_name'); - if (empty($name) || empty($human_name)) { - return $this->errorRedirectToMain(_kt("Both names not given")); + session_start(); + $sName = KTUtil::arrayGet($_REQUEST, 'name'); + $sHumanName = KTUtil::arrayGet($_REQUEST, 'human_name'); + $sError = 'An error occured while creating your permission'; + + //Checking that the System Name and Display Name fields aren't empty + if (empty($sName) && !empty($sHumanName)) + { + $sError = 'An error occured while creating your permission: The System Name was not provided.'; + $_SESSION['Permission']['HumanNameValue'] = $sHumanName; + return $this->errorRedirectToMain(_kt($sError)); } - $oPerm = KTPermission::createFromArray(array( - 'name' => $name, - 'humanname' => $human_name, + else if(!empty($sName) && empty($sHumanName)) + { + $sError = 'An error occured while creating your permission: The Display Name was not provided.'; + $_SESSION['Permission']['NameValue'] = $sName; + return $this->errorRedirectToMain(_kt($sError)); + } + else if (empty($sName) && empty($sHumanName)) + { + $sError = 'An error occured while creating your permission: The Display Name and System Name weren\'t provided.'; + return $this->errorRedirectToMain(_kt($sError)); + } + + //Checking that the System Name and Display Name aren't already in the database + $aPermissions = KTPermission::getList(); + //$iNameErrorCount and $iHumanNameErrorCount are used to check whether only one name is duplicated or if two names are duplicated. + $iNameErrorCount = 0; + $iHumanNameErrorCount = 0; + foreach ($aPermissions as $aPermission) + { + if($sName == $aPermission->getName()) + { + $iNameErrorCount ++; + } + if ($sHumanName == $aPermission->getHumanName()) + { + $iHumanNameErrorCount ++; + } + } + if ($iNameErrorCount > 0 && $iHumanNameErrorCount > 0) + { + $sError = 'An error occured while creating your permission: The Display Name and System Name you have provided both already exist.'; + return $this->errorRedirectToMain(_kt($sError)); + } + else if ($iNameErrorCount > 0 && $iHumanNameErrorCount == 0) + { + if(!empty($sHumanName)) + { + $_SESSION['Permission']['HumanNameValue'] = $sHumanName; + } + $sError = 'An error occured while creating your permission: A permission with the same System Name already exists.'; + return $this->errorRedirectToMain(_kt($sError)); + } + else if ($iNameErrorCount == 0 && $iHumanNameErrorCount > 0) + { + if(!empty($sName)) + { + $_SESSION['Permission']['NameValue'] = $sName; + } + $sError = 'An error occured while creating your permission: A permission with the same Display Name already exists.'; + return $this->errorRedirectToMain(_kt($sError)); + } + $oPerm = KTPermission::createFromArray(array( + 'name' => $sName, + 'humanname' => $sHumanName, )); if (PEAR::isError($oPerm)) { - return $this->errorRedirectToMain(_kt("Error creating permission")); + return $this->errorRedirectToMain(_kt($sError)); } return $this->successRedirectToMain(_kt("Permission created")); } diff --git a/templates/ktcore/manage_permissions.smarty b/templates/ktcore/manage_permissions.smarty index 7ccc6b6..08e4671 100644 --- a/templates/ktcore/manage_permissions.smarty +++ b/templates/ktcore/manage_permissions.smarty @@ -1,3 +1,11 @@ +{literal} + +{/literal}

{i18n}Existing permissions{/i18n}

{i18n}Permissions are descriptors used to ascertain whether groups of users have access to certain functionality. The built-in permissions below facilitate the default functionality of the DMS and can't be changed. Plugin developers may choose to add additional permissions below that manage access to their plugins functionality.{/i18n}

@@ -54,4 +62,13 @@ class="ktAction ktDelete">{i18n}Delete Permission{/i18n} { /foreach } - +{if $context->sNameVal != ''} + +{/if} +{if $context->sHumanNameVal != ''} + +{/if} \ No newline at end of file -- libgit2 0.21.4