Policy for displaying single element

@param User $user   User trying to do it
@param User $entity User that we're trying to read

@return boolean
543234
public function read(User $user, User $entity)
    {
        if ($entity->id === $user->id) {
            return true;
        }
        return $user->hasPermission('user-read');
    }
984180
public function isBidder(User $user)
    {
        return (bool) $this->bids()->whereHas('bidder', function ($query) use ($user) {
            return $query->where('user_id', $user->userId);
        })->count();
    }
1238953
private function getPermissionTable(User $user) {
		$userId = $user->getId();
		if ($this->permissionTable->has($userId)) {
			return $this->permissionTable->get($userId);
		}

		// always allow what guests can do
		$guestGroup = GroupQuery::create()->findOneByIsGuest(true);

		// collect groups from user
		$groups = GroupQuery::create()->filterByUser($user)->find();
		$userGroup = GroupQuery::create()->filterByOwnerId(($userId))->findOne();
		if ($userGroup) {
			$groups[] = $userGroup;
		}
		$groups[] = $guestGroup;

		// ... structure them
		$permissionTable = new Set();
		foreach ($groups as $group) {
			foreach ($group->getActions() as $action) {
				$permissionTable->add($action->getId());
			}
		}

		$this->permissionTable->set($userId, $permissionTable);

		return $this->permissionTable->get($userId);
	}
479434
public function countUnread(User $user)
    {
        return $this->createQueryBuilder('m')
            ->select('count(m)')
            ->join('m.userMessages', 'um')
            ->where('m.user != :sender')
            ->orWhere('m.user IS NULL')
            ->andWhere('um.user = :user')
            ->andWhere('um.isRead = 0')
            ->andWhere('um.isRemoved = 0')
            ->setParameter(':user', $user)
            ->setParameter(':sender', $user)
            ->getQuery()
            ->getSingleScalarResult();
    }
964275
public function checkBonusEntry($game, $user)
    {
        $query = $this->em->createQuery(
            'SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e 
             WHERE e.user = :user AND e.game = :game AND (e.bonus = 0 OR e.bonus IS NULL)'
        );
        $query->setParameter('user', $user);
        $query->setParameter('game', $game);
        $nbEntries = $query->getSingleScalarResult();

        $query = $this->em->createQuery(
            'SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e 
             WHERE e.user = :user AND e.game = :game AND e.bonus = 1'
        );
        $query->setParameter('user', $user);
        $query->setParameter('game', $game);
        $nbBonusEntries = $query->getSingleScalarResult();

        if (($nbEntries - $nbBonusEntries) <= 0) {
            return false;
        }

        return true;
    }
755429
public function setUser(\Core\Entity\User $user = null)
    {
        $this->user = $user;

        return $this;
    }
430969
public function has_user_read_post(stdClass $user, post_entity $post) : bool {
        global $CFG;
        $isoldpost = ($post->get_time_modified() < (time() - ($CFG->forum_oldpostdays * 24 * 3600)));

        if ($isoldpost) {
            return true;
        }

        $receipts = isset($this->receiptsbypostid[$post->get_id()]) ? $this->receiptsbypostid[$post->get_id()] : [];

        foreach ($receipts as $receipt) {
            if ($receipt->userid == $user->id) {
                return true;
            }
        }

        return false;
    }
780221
protected function createEntityVersionLock(User $user, LockableEntity $entity)
    {
        /** @var EntityVersionLock $lock */
        $lock = $this->objectManager->getRepository('KunstmaanAdminListBundle:EntityVersionLock')->findOneBy([
            'owner' => $user->getUsername(),
            'lockableEntity' => $entity,
        ]);
        if (!$lock) {
            $lock = new EntityVersionLock();
        }
        $lock->setOwner($user->getUsername());
        $lock->setLockableEntity($entity);
        $lock->setCreatedAt(new \DateTime());
        $this->objectManager->persist($lock);
        $this->objectManager->flush();
    }
851861
public function setUserData(User $user)
    {
        $userVarArray = get_object_vars($user);

        foreach ($userVarArray as $key => $value) {
            if ($value !== null) {
                $this->{$key} = $value;
            }
        }
    }
38196
public function saveUser(User $user, Request $request)
    {
        $user->fill($request->get('user'))
            ->save();

        Alert::info(__('User was saved.'));

        return back();
    }
1027080
public function can_view_post_shell(stdClass $user, post_entity $post) : bool {
        if (!$post->is_private_reply()) {
            return true;
        }

        if ($post->is_private_reply_intended_for_user($user)) {
            return true;
        }

        return $this->can_view_any_private_reply($user);
    }
713963
public function updateRoles(Request $request, User $user)
    {
        $this->authorize('roles', $user);

        $roles = Role::all();

        foreach ($roles as $role) {
            if (array_key_exists($role->id, $request->all())) {
                $role->addUser($user);
            } else {
                $role->deleteUser($user);
            }
        }

        return redirect()->route('laralum::users.index')->with('success', __('laralum_users::general.user_roles_updated', ['id' => $user->id]));
    }
693620
public function isApiEnabledForUser(User $user)
    {
        $roles = $user->roles->pluck('id')->toArray();
        return !count($roles) ? false : $this->newQuery()->whereIn('role_id', array_values($roles))->where('enabled', 1)->get()->count() > 0;
    }
261204
public function isVisibleTo(User $user)
    {
        return (bool) $this->newQuery()->whereVisibleTo($user)->find($this->id);
    }
853395
public function findUserList(User $user)
    {
        $dql = 'SELECT e FROM Phraseanet:UsrListEntry e
            WHERE e.user = :usr_id';

        $params = [
            'usr_id' => $user->getId(),
        ];

        $query = $this->_em->createQuery($dql);
        $query->setParameters($params);

        return $query->getResult();
    }
12318
private function mapUserToVersion(User $user, Request $request)
    {
        $content = $this->repository->getContentService()->loadContent($user->id);
        $request->headers->set('Url', $request->getPathInfo());

        return new Version(
            $content,
            $this->repository->getContentTypeService()->loadContentType($content->contentInfo->contentTypeId),
            $this->repository->getContentService()->loadRelations($content->getVersionInfo()),
            $request->getPathInfo()
        );
    }
35692
public function view($user, Event $event)
    {
        if ($event->creator->id == $user->id) {
            return true;
        }

        return User::findOrFail($user->id)->hasPermission('laralum::events.view');
    }