From 49b4486dd0dcf88184ed3b334bad02d50b1c5f9d Mon Sep 17 00:00:00 2001 From: akshath <akshath.t@vtiger.com> Date: Sun, 13 Jan 2019 22:47:12 +0530 Subject: [PATCH] Allowing role based picklist values in list view, summay and detail view of record along with Reports --- include/ListView/ListViewController.php | 33 +--------- languages/en_us/Settings/Picklist.php | 3 +- .../modules/Settings/Picklist/CreateView.tpl | 16 +++-- .../Settings/Workflows/resources/Edit.js | 4 +- .../modules/Vtiger/resources/AdvanceFilter.js | 12 ++++ layouts/v7/modules/Vtiger/resources/Field.js | 6 +- .../Calendar/models/DetailRecordStructure.php | 26 -------- modules/Reports/ReportUtils.php | 19 +----- .../Vtiger/models/DetailRecordStructure.php | 24 ------- modules/Vtiger/models/Field.php | 62 +++++++++++++++---- .../Vtiger/models/SummaryRecordStructure.php | 30 --------- 11 files changed, 83 insertions(+), 152 deletions(-) diff --git a/include/ListView/ListViewController.php b/include/ListView/ListViewController.php index ccc648e90..27d737235 100644 --- a/include/ListView/ListViewController.php +++ b/include/ListView/ListViewController.php @@ -339,11 +339,6 @@ class ListViewController { if($module == 'Calendar' && ($fieldName == 'taskstatus' || $fieldName == 'eventstatus' || $fieldName == 'activitytype')) { $value = Vtiger_Language_Handler::getTranslatedString($value,$module); $value = textlength_check($value); - } - else if ($value != '' && !$is_admin && $this->picklistRoleMap[$fieldName] && - !in_array($value, $this->picklistValueMap[$fieldName]) && strtolower($value) != '--none--' && strtolower($value) != 'none' ) { - $value = "<font color='red'>". Vtiger_Language_Handler::getTranslatedString('LBL_NOT_ACCESSIBLE', - $module)."</font>"; } else { $value = Vtiger_Language_Handler::getTranslatedString($value,$module); $value = textlength_check($value); @@ -440,33 +435,7 @@ class ListViewController { } elseif($field->getUIType() == 98) { $value = '<a href="index.php?module=Roles&parent=Settings&view=Edit&record='.$value.'">'.textlength_check(getRoleName($value)).'</a>'; } elseif($fieldDataType == 'multipicklist') { - if(!$is_admin && $value != '') { - $valueArray = ($rawValue != "") ? explode(' |##| ',$rawValue) : array(); - $notaccess = '<font color="red">'.getTranslatedString('LBL_NOT_ACCESSIBLE', - $module)."</font>"; - $tmp = ''; - $tmpArray = array(); - foreach($valueArray as $index => $val) { - $val = decode_html($val); - if(!$listview_max_textlength || - !(strlen(preg_replace("/(<\/?)(\w+)([^>]*>)/i","",$tmp)) > - $listview_max_textlength)) { - if (!$is_admin && $this->picklistRoleMap[$fieldName] && - !in_array(trim($val), $this->picklistValueMap[$fieldName])) { - $tmpArray[] = $notaccess; - $tmp .= ', '.$notaccess; - } else { - $tmpArray[] = $val; - $tmp .= ', '.$val; - } - } else { - $tmpArray[] = '...'; - $tmp .= '...'; - } - } - $value = implode(', ', $tmpArray); - $value = textlength_check($value); - } else if ($value != '') { + if ($value != '') { $moduleName = getTabModuleName($field->getTabId()); $value = explode(' |##| ', $value); foreach ($value as $key => $val) { diff --git a/languages/en_us/Settings/Picklist.php b/languages/en_us/Settings/Picklist.php index d765d3e1f..881663a0c 100644 --- a/languages/en_us/Settings/Picklist.php +++ b/languages/en_us/Settings/Picklist.php @@ -24,7 +24,8 @@ $languageStrings = array( 'LBL_DELETE_PICKLIST_ITEMS' => 'Delete PickList Items', 'LBL_ITEMS_TO_DELETE' => 'Items to Delete', 'LBL_REPLACE_IT_WITH' => 'Replace it with', - 'LBL_ASSIGN_TO_ROLE' => 'Assign to Role', + 'LBL_ASSIGN_TO_ROLE' => 'Who can assign this value to a record?', + 'LBL_ASSIGN_TO_ROLE_INFO' => 'Only users with selected roles will be able to assign this value to a record. Once assigned, all users with access to record can view the value. The value will be available for selection to all users in list filters', 'LBL_ALL_ROLES' => 'All Roles', 'LBL_CHOOSE_ROLES' => 'Choose Roles', 'LBL_ALL_VALUES' => 'All values', diff --git a/layouts/v7/modules/Settings/Picklist/CreateView.tpl b/layouts/v7/modules/Settings/Picklist/CreateView.tpl index c0b16e443..19ab08490 100644 --- a/layouts/v7/modules/Settings/Picklist/CreateView.tpl +++ b/layouts/v7/modules/Settings/Picklist/CreateView.tpl @@ -25,24 +25,32 @@ {include file="ModalHeader.tpl"|vtemplate_path:$MODULE TITLE=$HEADER_TITLE} <div class="modal-body"> <div class="form-group"> - <div class="control-label col-sm-3 col-xs-3">{vtranslate('LBL_ITEM_VALUE',$QUALIFIED_MODULE)} <span class="redColor">*</span></div> + <div class="control-label col-sm-4 col-xs-4">{vtranslate('LBL_ITEM_VALUE',$QUALIFIED_MODULE)} <span class="redColor">*</span></div> <div class="controls col-sm-3 col-xs-3"><input style="min-width: 220px;" name="newValue" class="form-control select2" data-rule-required="true"/></div> </div> {if $SELECTED_PICKLIST_FIELDMODEL->isRoleBased()} <div class="form-group"> - <div class="control-label col-sm-3 col-xs-3">{vtranslate('LBL_ASSIGN_TO_ROLE',$QUALIFIED_MODULE)}</div> + <div class="control-label col-sm-4 col-xs-4"> + {vtranslate('LBL_ASSIGN_TO_ROLE',$QUALIFIED_MODULE)} + <span class="input-info-addon cursorPointer"> + <i class="fa fa-info-circle" data-toggle="tooltip" data-placement="bottom" title="{vtranslate('LBL_ASSIGN_TO_ROLE_INFO',$QUALIFIED_MODULE)}"></i> + </span> + </div> <div class="controls col-sm-3 col-xs-3"> <select class="rolesList form-control" name="rolesSelected[]" multiple style="min-width: 220px" data-placeholder="{vtranslate('LBL_CHOOSE_ROLES',$QUALIFIED_MODULE)}"> <option value="all" selected>{vtranslate('LBL_ALL_ROLES',$QUALIFIED_MODULE)}</option> {foreach from=$ROLES_LIST item=ROLE} <option value="{$ROLE->get('roleid')}">{$ROLE->get('rolename')}</option> {/foreach} - </select> + </select> + </div> + <div class="input-info-addon cursorPointer" style='line-height: 2;'> + <i class="fa fa-info-circle" data-toggle="tooltip" data-placement="bottom" title="{vtranslate('LBL_ASSIGN_TO_ROLE_INFO',$QUALIFIED_MODULE)}"></i> </div> </div> {/if} <div class="form-group"> - <div class="control-label col-sm-3 col-xs-3">{vtranslate('LBL_SELECT_COLOR', $QUALIFIED_MODULE)}</div> + <div class="control-label col-sm-4 col-xs-4">{vtranslate('LBL_SELECT_COLOR', $QUALIFIED_MODULE)}</div> <div class="controls col-sm-3 col-xs-3"> <input type="hidden" name="selectedColor" /> <div class="colorPicker"> diff --git a/layouts/v7/modules/Settings/Workflows/resources/Edit.js b/layouts/v7/modules/Settings/Workflows/resources/Edit.js index 1a9aa44ed..d999bb455 100644 --- a/layouts/v7/modules/Settings/Workflows/resources/Edit.js +++ b/layouts/v7/modules/Settings/Workflows/resources/Edit.js @@ -110,7 +110,7 @@ Settings_Vtiger_Edit_Js("Settings_Workflows_Edit_Js", { }, - getPopUp: function (container) { + getPopUp: function (container, flag) { var thisInstance = this; if (typeof container == 'undefined') { container = thisInstance.getContainer(); @@ -811,7 +811,7 @@ Settings_Vtiger_Edit_Js("Settings_Workflows_Edit_Js", { jQuery.each(fields, function (i, field) { thisInstance.loadFieldSpecificUi(jQuery(field)); }); - this.getPopUp(jQuery('#saveTask')); + this.getPopUp(jQuery('#saveTask'), true); }, registerVTPushNotificationTaskEvents: function () { this.registerFillMailContentEvent(); diff --git a/layouts/v7/modules/Vtiger/resources/AdvanceFilter.js b/layouts/v7/modules/Vtiger/resources/AdvanceFilter.js index b49f4b5b8..38383c608 100644 --- a/layouts/v7/modules/Vtiger/resources/AdvanceFilter.js +++ b/layouts/v7/modules/Vtiger/resources/AdvanceFilter.js @@ -675,6 +675,12 @@ Vtiger_Currencylist_Field_Js('AdvanceFilter_Currencylist_Field_Js',{},{ Vtiger_Picklist_Field_Js('AdvanceFilter_Picklist_Field_Js',{},{ + /** + * Function to get the picklist values + */ + getPickListValues : function() { + return this.get('picklistvalues'); + }, getUi : function(){ var comparatorSelectedOptionVal = this.get('comparatorElementVal'); if(comparatorSelectedOptionVal == 'e' || comparatorSelectedOptionVal =='n'){ @@ -716,6 +722,12 @@ Vtiger_Picklist_Field_Js('AdvanceFilter_Picklist_Field_Js',{},{ Vtiger_Multipicklist_Field_Js('AdvanceFilter_Multipicklist_Field_Js',{},{ + /** + * Function to get the picklist values + */ + getPickListValues : function() { + return this.get('picklistvalues'); + }, getSelectedOptions : function(selectedOption){ var valueArray = selectedOption.split(','); var selectedOptionsArray = []; diff --git a/layouts/v7/modules/Vtiger/resources/Field.js b/layouts/v7/modules/Vtiger/resources/Field.js index 75a0fc493..d254bc78f 100644 --- a/layouts/v7/modules/Vtiger/resources/Field.js +++ b/layouts/v7/modules/Vtiger/resources/Field.js @@ -229,7 +229,7 @@ Vtiger_Field_Js('Vtiger_Picklist_Field_Js',{},{ * @return <object> key value pair of options */ getPickListValues : function() { - return this.get('picklistvalues'); + return this.get('editablepicklistvalues'); }, /** @@ -327,7 +327,7 @@ Vtiger_Field_Js('Vtiger_Multipicklist_Field_Js',{},{ * @return <object> key value pair of options */ getPickListValues : function() { - return this.get('picklistvalues'); + return this.get('editablepicklistvalues'); }, getSelectedOptions : function(selectedOption){ @@ -469,7 +469,7 @@ Vtiger_Field_Js('Vtiger_Owner_Field_Js',{},{ * Function to get the picklist values */ getPickListValues : function() { - return this.get('picklistvalues'); + return this.get('editablepicklistvalues'); }, getUi : function() { diff --git a/modules/Calendar/models/DetailRecordStructure.php b/modules/Calendar/models/DetailRecordStructure.php index 87821fe01..c6a5dc9d0 100644 --- a/modules/Calendar/models/DetailRecordStructure.php +++ b/modules/Calendar/models/DetailRecordStructure.php @@ -45,32 +45,6 @@ class Calendar_DetailRecordStructure_Model extends Vtiger_DetailRecordStructure_ if(!$currentUsersModel->isAdminUser() && ($fieldModel->getFieldDataType() == 'picklist' || $fieldModel->getFieldDataType() == 'multipicklist')) { $value = decode_html($value); $this->setupAccessiblePicklistValueList($fieldName); - if($fieldModel->getFieldDataType() == 'picklist') { - if ($value != '' && $this->picklistRoleMap[$fieldName] && !in_array($value, $this->picklistValueMap[$fieldName]) && strtolower($value) != '--none--' && strtolower($value) != 'none' ) { - $value = "<font color='red'>". vtranslate('LBL_NOT_ACCESSIBLE', - $moduleModel->getName())."</font>"; - } - } - if($fieldModel->getFieldDataType() == 'multipicklist') { - if(!$currentUsersModel->isAdminUser() && $value != '') { - $valueArray = ($value != "") ? explode(' |##| ',$value) : array(); - $notaccess = '<font color="red">'. vtranslate('LBL_NOT_ACCESSIBLE', - $moduleModel->getName())."</font>"; - $tmp = ''; - $tmpArray = array(); - foreach($valueArray as $val) { - if (!$currentUsersModel->isAdminUser() && $this->picklistRoleMap[$fieldName] && - !in_array(trim($val), $this->picklistValueMap[$fieldName])) { - $tmpArray[] = $notaccess; - $tmp .= ', '.$notaccess; - } else { - $tmpArray[] = $val; - $tmp .= ', '.$val; - } - } - $value = implode(' |##| ', $tmpArray); - } - } } $fieldModel->set('fieldvalue', $value); } diff --git a/modules/Reports/ReportUtils.php b/modules/Reports/ReportUtils.php index dc0bf7440..bbd40c0fd 100644 --- a/modules/Reports/ReportUtils.php +++ b/modules/Reports/ReportUtils.php @@ -202,30 +202,13 @@ function getReportFieldValue ($report, $picklistArray, $dbField, $valueArray, $f $fieldvalue = $value; } } elseif( $fieldType == "picklist" && !empty($value) ) { - if(is_array($picklistArray)) { - if(is_array($picklistArray[$dbField->name]) && - $field->getFieldName() != 'activitytype' && !in_array( - $value, $picklistArray[$dbField->name])){ - $fieldvalue =$app_strings['LBL_NOT_ACCESSIBLE']; - } else { - $fieldvalue = getTranslatedString($value, $module); - } - } else { $fieldvalue = getTranslatedString($value, $module); - } } elseif( $fieldType == "multipicklist" && !empty($value) ) { if(is_array($picklistArray[1])) { $valueList = explode(' |##| ', $value); $translatedValueList = array(); foreach ( $valueList as $value) { - if(is_array($picklistArray[1][$dbField->name]) && !in_array( - $value, $picklistArray[1][$dbField->name])) { - $translatedValueList[] = - $app_strings['LBL_NOT_ACCESSIBLE']; - } else { - $translatedValueList[] = getTranslatedString($value, - $module); - } + $translatedValueList[] = getTranslatedString($value, $module); } } if (!is_array($picklistArray[1]) || !is_array($picklistArray[1][$dbField->name])) { diff --git a/modules/Vtiger/models/DetailRecordStructure.php b/modules/Vtiger/models/DetailRecordStructure.php index f825977a5..47d71a0d7 100644 --- a/modules/Vtiger/models/DetailRecordStructure.php +++ b/modules/Vtiger/models/DetailRecordStructure.php @@ -42,30 +42,6 @@ class Vtiger_DetailRecordStructure_Model extends Vtiger_RecordStructure_Model { if(!$currentUsersModel->isAdminUser() && ($fieldModel->getFieldDataType() == 'picklist' || $fieldModel->getFieldDataType() == 'multipicklist')) { $value = decode_html($value); $this->setupAccessiblePicklistValueList($fieldName); - if($fieldModel->getFieldDataType() == 'picklist') { - if ($value != '' && $this->picklistRoleMap[$fieldName] && !in_array($value, $this->picklistValueMap[$fieldName]) && strtolower($value) != '--none--' && strtolower($value) != 'none' ) { - $value = "<font color='red'>". vtranslate('LBL_NOT_ACCESSIBLE', - $moduleModel->getName())."</font>"; - } - } - if($fieldModel->getFieldDataType() == 'multipicklist') { - if (!$currentUsersModel->isAdminUser() && $value != '') { - $valueArray = ($value != "") ? explode(' |##| ', $value) : array(); - $notaccess = '<font color="red">'.vtranslate('LBL_NOT_ACCESSIBLE', $moduleModel->getName())."</font>"; - $tmp = ''; - $tmpArray = array(); - foreach ($valueArray as $val) { - if (!$currentUsersModel->isAdminUser() && $this->picklistRoleMap[$fieldName] && !in_array(trim($val), $this->picklistValueMap[$fieldName])) { - $tmpArray[] = $notaccess; - $tmp .= ', '.$notaccess; - } else { - $tmpArray[] = $val; - $tmp .= ', '.$val; - } - } - $value = implode(' |##| ', $tmpArray); - } - } } $fieldModel->set('fieldvalue', $value); } diff --git a/modules/Vtiger/models/Field.php b/modules/Vtiger/models/Field.php index dea6331f1..3f5105285 100644 --- a/modules/Vtiger/models/Field.php +++ b/modules/Vtiger/models/Field.php @@ -264,22 +264,53 @@ class Vtiger_Field_Model extends Vtiger_Field { if($fieldName == 'hdnTaxType' || ($fieldName == 'region_id' && $this->get('displaytype') == 5)) return null; - if($fieldDataType == 'picklist' || $fieldDataType == 'multipicklist') { - $fieldPickListValues = array(); - $currentUser = Users_Record_Model::getCurrentUserModel(); - if($this->isRoleBased()) { - $userModel = Users_Record_Model::getCurrentUserModel(); - $picklistValues = Vtiger_Util_Helper::getRoleBasedPicklistValues($fieldName, $userModel->get('roleid')); - }else{ - $picklistValues = Vtiger_Util_Helper::getPickListValues($fieldName); + if($fieldDataType == 'picklist' || $fieldDataType == 'multipicklist' || $fieldDataType == 'metricpicklist' || $fieldDataType == 'timestring') { + $fieldPickListValues = array(); + $picklistValues = Vtiger_Util_Helper::getPickListValues($fieldName); + + foreach($picklistValues as $value) { + $fieldPickListValues[$value] = vtranslate($value,$this->getModuleName()); } - foreach($picklistValues as $value) { - $fieldPickListValues[$value] = vtranslate($value,$this->getModuleName()); + return $fieldPickListValues; + } + return null; + } + + + /** + * Function to get all editable picklist values for the current user + * @return <Array> List of picklist values if the field is of type picklist or multipicklist, null otherwise. + */ + public function getEditablePicklistValues() { + $fieldDataType = $this->getFieldDataType(); + $fieldName = $this->getName(); + $permission = true; + + // for reference fields the field name will be in the format of (referencefieldname;(module)fieldname) + preg_match('/(\w+) ; \((\w+)\) (\w+)/', $fieldName, $matches); + if(count($matches) > 0) { + list($full, $referenceParentField, $referenceModule, $referenceFieldName) = $matches; + $fieldName = $referenceFieldName; + } + + if($fieldName == 'hdnTaxType' || ($fieldName == 'region_id' && $this->get('displaytype') == 5)) return null; + + if($fieldDataType == 'picklist' || $fieldDataType == 'multipicklist') { + $fieldPickListValues = array(); + if($this->isRoleBased()) { + $userModel = Users_Record_Model::getCurrentUserModel(); + $picklistValues = Vtiger_Util_Helper::getRoleBasedPicklistValues($fieldName, $userModel->get('roleid')); + }else{ + $picklistValues = Vtiger_Util_Helper::getPickListValues($fieldName); + } + + foreach($picklistValues as $value) { + $fieldPickListValues[$value] = vtranslate($value,$this->getModuleName()); } - return $fieldPickListValues; + return $fieldPickListValues; } return null; - } + } /** * Function to check if the current field is mandatory or not @@ -533,11 +564,18 @@ class Vtiger_Field_Model extends Vtiger_Field { if($fieldDataType == 'picklist' || $fieldDataType == 'multipicklist' || $fieldDataType == 'multiowner') { $pickListValues = $this->getPicklistValues(); + $editablePicklistValues = $this->getEditablePicklistValues(); if(!empty($pickListValues)) { $this->fieldInfo['picklistvalues'] = $pickListValues; } else { $this->fieldInfo['picklistvalues'] = array(); } + + if(!empty($editablePicklistValues)) { + $this->fieldInfo['editablepicklistvalues'] = $editablePicklistValues; + } else { + $this->fieldInfo['editablepicklistvalues'] = array(); + } $this->fieldInfo['picklistColors'] = array(); $picklistColors = $this->getPicklistColors(); diff --git a/modules/Vtiger/models/SummaryRecordStructure.php b/modules/Vtiger/models/SummaryRecordStructure.php index 9c47744ac..216b56fa9 100644 --- a/modules/Vtiger/models/SummaryRecordStructure.php +++ b/modules/Vtiger/models/SummaryRecordStructure.php @@ -46,36 +46,6 @@ class Vtiger_SummaryRecordStructure_Model extends Vtiger_DetailRecordStructure_M $blockSequence = $fieldModel->block->sequence; if(!$currentUsersModel->isAdminUser() && ($fieldModel->getFieldDataType() == 'picklist' || $fieldModel->getFieldDataType() == 'multipicklist')) { $this->setupAccessiblePicklistValueList($fieldName); - $value = decode_html($fieldModel->get('fieldvalue')); - $moduleModel = $fieldModel->getModule(); - if($fieldModel->getFieldDataType() == 'picklist') { - if ($value != '' && $this->picklistRoleMap[$fieldName] && !in_array($value, $this->picklistValueMap[$fieldName]) && strtolower($value) != '--none--' && strtolower($value) != 'none' ) { - $value = '<font color="red">'. vtranslate('LBL_NOT_ACCESSIBLE', - $moduleModel->getName()).'</font>'; - $fieldModel->set('fieldvalue', $value); - } - } - if($fieldModel->getFieldDataType() == 'multipicklist') { - if(!$currentUsersModel->isAdminUser() && $value != '') { - $valueArray = ($value != "") ? explode(' |##| ',$value) : array(); - $notaccess = '<font color="red">'. vtranslate('LBL_NOT_ACCESSIBLE', - $moduleModel->getName())."</font>"; - $tmp = ''; - $tmpArray = array(); - foreach($valueArray as $val) { - if (!$currentUsersModel->isAdminUser() && $this->picklistRoleMap[$fieldName] && - !in_array(trim($val), $this->picklistValueMap[$fieldName])) { - $tmpArray[] = $notaccess; - $tmp .= ', '.$notaccess; - } else { - $tmpArray[] = $val; - $tmp .= ', '.$val; - } - } - $value = implode(' |##| ', $tmpArray); - $fieldModel->set('fieldvalue', $value); - } - } } $blockSeqSortSummaryFields[$blockSequence]['SUMMARY_FIELDS'][$fieldName] = $fieldModel; } -- GitLab