AnsweredAssumed Answered

SugarVisibility does not work

Question asked by Artis Plocins on Feb 23, 2018

I tried to implement a simple visibility clause according to this page in the developer guide for all bean queries to check that team_id of the bean is equal to the team_id of the current user.

The code below does nothing at all. Even if I add global fatal log messages to __construct() and addVisibilityQuery() they never appear in the log.


File custom/data/visibility/TeamSelectorFilter.php

class TeamSelectorFilter extends SugarVisibility
    public function __construct(SugarBean $bean, $params = null)
        parent::__construct($bean, $params);
        global $current_user;
        // Get the current user's team_id.
        $this->user_team_id = $current_user->team_id;

    public function addVisibilityQuery(SugarQuery $query)
        // The bean's team_id must be the same as the user's team_id.
        $query->where('team_id', $this->user_team_id);
        return $query;


It makes sense that it just inserts another WHERE clause into the running SugarQuery and passes it along, but why does it not work at all?