From: Jagadedes Date: Thu, 4 Dec 2014 09:09:30 +0000 (+0530) Subject: added permissions and menu cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d2d4567c83d7d916b90a2366e8161daa2a5098ef;p=com.zyxware.civiwci.git added permissions and menu cleanup --- diff --git a/README.md b/README.md index dcaeaab..d7b0104 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,11 @@ Mailing list subscription feature also exposed though widget. To use that first For getting better performance WCI widget uses a cache system. A timeout value can be provided 'Widget cache timeout' field for saving the widget in database for that specified time. Static widgets (widgets with out progress bar) will be caches permanently unless there is any change in the widget. +### Permission + +There are 2 permissions associated with CiviWCI. +'Administer CiviWCI' : All WCI menu items are available for user of this permission. Please enable it in your CMS permission page. + +'Access CiviWCI Widget' : To see the widget the user should have this permission. Enable this to anonymous users too, if they want to view the widget. + CiviCRM-WCI development is sponsored by [Zyxware Tehnologies](http://www.zyxware.com). diff --git a/wci.php b/wci.php index 49755a6..b882919 100644 --- a/wci.php +++ b/wci.php @@ -128,15 +128,30 @@ function wci_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { _wci_civix_civicrm_alterSettingsFolders($metaDataFolders); } +function _getMenuKeyMax($menuArray) { + $max = array(max(array_keys($menuArray))); + foreach($menuArray as $v) { + if (!empty($v['child'])) { + $max[] = _getMenuKeyMax($v['child']); + } + } + return max($max); +} + +function wci_civicrm_permission(&$permissions) { + $prefix = ts('CiviWCI') . ': '; // name of extension or module + $permissions += array( + 'access CiviWCI Widget' => $prefix . ts('Access CiviWCI Widget'), + 'administer CiviWCI' => $prefix . ts('Administer CiviWCI'), + ); +} + function wci_civicrm_navigationMenu( &$params ) { - $navId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation"); - if (is_integer($navId)) { - $navId++; - } + $maxKey = _getMenuKeyMax($params); // Find the Help menu $helpID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Help', 'id', 'name'); - $params[$navId] = $params[$helpID]; + $params[$maxKey] = $params[$helpID]; // inserting WCI menu at the place of old help location $params[$helpID] = array ( 'attributes' => array ( @@ -147,7 +162,7 @@ function wci_civicrm_navigationMenu( &$params ) { 'operator' => 'OR', 'separator' => 0, 'parentID' => 0, - 'navID' => $navId, + 'navID' => $maxKey, 'active' => 1), 'child' => array ( '1' => array ( @@ -155,11 +170,11 @@ function wci_civicrm_navigationMenu( &$params ) { 'label' => ts('New Widget'), 'name' => 'new_widget', 'url' => 'civicrm/wci/widget/add', - 'permission' => 'access CiviReport,access CiviContribute', + 'permission' => 'administer CiviWCI', 'operator' => 'OR', 'separator' => 1, - 'parentID' => $navId, - 'navID' => $navId+1, + 'parentID' => $maxKey, + 'navID' => $maxKey+1, 'active' => 1)), '2' => array ( @@ -167,11 +182,11 @@ function wci_civicrm_navigationMenu( &$params ) { 'label' => ts('Manage Widgets'), 'name' => 'manage_widget', 'url' => 'civicrm/wci/widget?reset=1', - 'permission' => 'access CiviReport,access CiviContribute', + 'permission' => 'administer CiviWCI', 'operator' => 'OR', 'separator' => 1, - 'parentID' => $navId, - 'navID' => $navId+2, + 'parentID' => $maxKey, + 'navID' => $maxKey+2, 'active' => 1)), '3' => array ( @@ -179,11 +194,11 @@ function wci_civicrm_navigationMenu( &$params ) { 'label' => ts('New Progress Bar'), 'name' => 'new_progress_bar', 'url' => 'civicrm/wci/progress-bar/add', - 'permission' => 'access CiviReport,access CiviContribute', + 'permission' => 'administer CiviWCI', 'operator' => 'OR', 'separator' => 1, - 'parentID' => $navId, - 'navID' => $navId+3, + 'parentID' => $maxKey, + 'navID' => $maxKey+3, 'active' => 1)), '4' => array ( @@ -191,11 +206,11 @@ function wci_civicrm_navigationMenu( &$params ) { 'label' => ts('Manage Progress Bars'), 'name' => 'manage_progress_bar', 'url' => 'civicrm/wci/progress-bar?reset=1', - 'permission' => 'access CiviReport,access CiviContribute', + 'permission' => 'administer CiviWCI', 'operator' => 'OR', 'separator' => 1, - 'parentID' => $navId, - 'navID' => $navId+4, + 'parentID' => $maxKey, + 'navID' => $maxKey+4, 'active' => 1)), '5' => array ( @@ -203,11 +218,11 @@ function wci_civicrm_navigationMenu( &$params ) { 'label' => ts('New Embed Code'), 'name' => 'new_embed-code', 'url' => 'civicrm/wci/embed-code/add', - 'permission' => 'access CiviReport,access CiviContribute', + 'permission' => 'administer CiviWCI', 'operator' => 'OR', 'separator' => 1, - 'parentID' => $navId, - 'navID' => $navId+5, + 'parentID' => $maxKey, + 'navID' => $maxKey+5, 'active' => 1)), '6' => array ( @@ -215,11 +230,11 @@ function wci_civicrm_navigationMenu( &$params ) { 'label' => ts('Manage Embed Code'), 'name' => 'manage-emebed-code', 'url' => 'civicrm/wci/embed-code?reset=1', - 'permission' => 'access CiviReport,access CiviContribute', + 'permission' => 'administer CiviWCI', 'operator' => 'OR', 'separator' => 1, - 'parentID' => $navId, - 'navID' => $navId+6, + 'parentID' => $maxKey, + 'navID' => $maxKey+6, 'active' => 1)), '7' => array ( @@ -227,11 +242,11 @@ function wci_civicrm_navigationMenu( &$params ) { 'label' => ts('Widget Settings'), 'name' => 'widget-settings', 'url' => 'civicrm/wci/settings?reset=1', - 'permission' => 'access CiviReport,access CiviContribute', + 'permission' => 'administer CiviWCI', 'operator' => 'OR', 'separator' => 1, - 'parentID' => $navId, - 'navID' => $navId+7, + 'parentID' => $maxKey, + 'navID' => $maxKey+7, 'active' => 1)), ), ); diff --git a/xml/Menu/wci.xml b/xml/Menu/wci.xml index 7284cbb..20724d5 100644 --- a/xml/Menu/wci.xml +++ b/xml/Menu/wci.xml @@ -4,54 +4,54 @@ civicrm/wci/widget/add CRM_Wci_Form_CreateWidget Create Widget - access CiviCRM + administer CiviWCI civicrm/wci/progress-bar/add CRM_Wci_Form_ProgressBar ProgressBar - access CiviCRM + administer CiviWCI civicrm/wci/test-bar/testadd CRM_Wci_Form_TestBar TestBar - access CiviCRM + administer CiviWCI civicrm/wci/progress-bar CRM_Wci_Page_ProgressBarList ProgressBarList - access CiviCRM + administer CiviWCI civicrm/wci/widget CRM_Wci_Page_WidgetList Widget List - access CiviCRM + administer CiviWCI civicrm/wci/settings CRM_Wci_Form_WCISettings WCISettings - access CiviCRM + administer CiviWCI civicrm/wci/embed-code/add CRM_Wci_Form_NewEmbedCode NewEmbedCode - access CiviCRM + administer CiviWCI civicrm/wci/embed-code CRM_Wci_Page_ManageEmbedCode ManageEmbedCode - access CiviCRM + administer CiviWCI civicrm/wci/embed CRM_Wci_Page_Embed Embed - access CiviCRM + access CiviWCI Widget