From 9eadcdb72d1a57686b366a14ca24c31f9dd870cc Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 2 Mar 2017 11:09:17 -0500 Subject: [PATCH] CRM-19943 - Add permission check and move tags button --- CRM/Tag/Form/Merge.php | 9 ++++- templates/CRM/Tag/Page/Tag.tpl | 72 +++++++++++++++++++++++++++++----- 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/CRM/Tag/Form/Merge.php b/CRM/Tag/Form/Merge.php index f893ae08de..f6778083d0 100644 --- a/CRM/Tag/Form/Merge.php +++ b/CRM/Tag/Form/Merge.php @@ -43,13 +43,20 @@ class CRM_Tag_Form_Merge extends CRM_Core_Form { $this->_id = explode(',', $this->_id); $url = CRM_Utils_System::url('civicrm/tag'); if (count($this->_id) < 2) { - CRM_Core_Error::statusBounce(ts("You must select at least 2 tags for merging"), $url); + CRM_Core_Error::statusBounce(ts("You must select at least 2 tags for merging."), $url); } $tags = civicrm_api3('Tag', 'get', array('id' => array('IN' => $this->_id), 'options' => array('limit' => 0))); $this->_tags = $tags['values']; if (count($this->_id) != count($this->_tags)) { CRM_Core_Error::statusBounce(ts("Unknown tag."), $url); } + if (!CRM_Core_Permission::check('administer reserved tags')) { + foreach ($tags['values'] as $tag) { + if (!empty($tag['is_reserved'])) { + CRM_Core_Error::statusBounce(ts("You do not have permission to administer reserved tags."), $url); + } + } + } } /** diff --git a/templates/CRM/Tag/Page/Tag.tpl b/templates/CRM/Tag/Page/Tag.tpl index fe4560ca8f..45912546bc 100644 --- a/templates/CRM/Tag/Page/Tag.tpl +++ b/templates/CRM/Tag/Page/Tag.tpl @@ -92,6 +92,7 @@ function renderTree($panel) { var plugins, + selected = [], tagset = $panel.attr('id').split('-')[1] || 0; function hasChildren(id) { @@ -116,10 +117,12 @@ function changeSelection(e, data) { var tplParams = { tagset: tagset, + tagsetCount: _.keys(tagSets).length, adminReserved: CRM.checkPerm('administer reserved tags') }, tree = $('.tag-tree', $panel).jstree(true), $infoBox = $('.tag-info', $panel); + selected = data.selected; if (!data.selected || !data.selected.length) { tplParams.is_reserved = tagset ? tagSets[tagset].is_reserved == 1 : false; tplParams.length = $('.tag-tree li', $panel).length; @@ -194,11 +197,46 @@ addHelp(); } + function moveTagDialog(e) { + e.preventDefault(); + var sets = [{key: '0', value: '{/literal}{ts escape='js'}Main Tag Tree{/ts}{literal}'}]; + _.each(tagSets, function(tagSet) { + sets.push({key: tagSet.id, value: tagSet.name}); + }); + CRM.confirm({ + title: '{/literal}{ts escape='js'}Move to Tagset{/ts}{literal}', + message: '