如果分配的用户登录 SUITECRM,则在弹出列表视图中过滤记录

filter records in popup list view if assigned user is login SUITECRM

我想过滤记录,以便分配的用户只能从弹出列表视图中看到分配给他的记录。

我之所以没有在角色管理中这样做是因为如果我将用户分配给客户记录,那么具有相同角色的其他用户将看不到它,所以我已将角色->列表选项卡设置为 "all" 并在列表视图中添加自定义代码,只有登录用户才能看到自己的记录。

这是我所做的。

<?php

    require_once('include/MVC/View/views/view.popup.php');

    class AccountsViewPopup extends ViewPopup
    {
        public function display()
        {
            parent::display(); // TODO: Change the autogenerated stub

            require_once 'modules/ACLRoles/ACLRole.php';
            $ACLRole = new ACLRole();
            $roles = $ACLRole->getUserRoles($GLOBALS['current_user']->id);

            if (in_array('User1', $roles)) {

                global $db, $current_user;

                $this->where .= " AND accounts.assigned_user_id = '$current_user->id' AND deleted=0 ";
            }
        }
    }

但是我得到这个错误:

Undefined property: AccountsViewPopup::$where

仅限列表视图custom/modules/MODULE_NAME/views/view.list.php

下面是帮助代码:

require_once('include/MVC/View/views/view.list.php');
class MODULE_NAMEViewList extends ViewList {

    function listViewProcess() {
        global $current_user;
        $this->params['custom_where'] = ' AND module_name.name = "test" ';

        parent::listViewProcess();
}

}



对于列表和弹出视图(两者)

您需要更改 create_new_list_query 函数中实际准备查询的逻辑。一些模块在 bean 级别覆盖了它(例如,参见 modules/Leads/Lead.php)。

如果您想以升级安全的方式覆盖它,则在自定义目录中创建一个文件,例如:custom/modules/Leads/Lead.php,然后从核心 bean class 扩展它,如下所示:

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('modules/Leads/Lead.php');
class CustomLead extends Lead {

    function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false,$parentbean=null, $singleSelect = false, $ifListForExport = false)
    { 
        // Code from create_new_list_query in and then modify it accordingly. 
    }
}

在此位置注册新 bean class:custom/Extension/application/Ext/Include/custom_leads_class.php 注册代码如下所示:

<?php
$objectList['Leads'] = 'Lead';
$beanList['Leads'] = 'CustomLead';
$beanFiles['CustomLead'] = 'custom/modules/Leads/Lead.php';
?>

我知道这已经得到解答,但还是决定 post 我的解决方案。前段时间(7.10.7)我遇到了几乎相同的问题。 PopupView 有方法 getCustomWhereClause(),您可以在自定义视图中实现该方法。 它必须 return 包含带有条件的字符串。

示例:

custom/modules/Meetings/views/view.popup.php    
/*class declaration and other stuff*/
protected function getCustomWhereClause()
{
    global $current_user;
    return " ( {$this->bean->table_name}.assigned_user_id='{$current_user->id}') ";
}

记得在开头和结尾至少保留一个 space,因为 SuiteCRM 实际上会忘记添加它,这可能会导致查询中断(但在日志中很容易找到)。