Work out whether this record can be shown to a user with a given access level

@param int $access_level

@return bool
556089
private function canShowRecord(int $access_level): bool
    {
        // This setting would better be called "$ENABLE_PRIVACY"
        if (!$this->tree->getPreference('HIDE_LIVE_PEOPLE')) {
            return true;
        }

        // We should always be able to see our own record (unless an admin is applying download restrictions)
        if ($this->xref() === $this->tree->getUserPreference(Auth::user(), 'gedcomid') && $access_level === Auth::accessLevel($this->tree)) {
            return true;
        }

        // Does this record have a RESN?
        if (strpos($this->gedcom, "\n1 RESN confidential") !== false) {
            return Auth::PRIV_NONE >= $access_level;
        }
        if (strpos($this->gedcom, "\n1 RESN privacy") !== false) {
            return Auth::PRIV_USER >= $access_level;
        }
        if (strpos($this->gedcom, "\n1 RESN none") !== false) {
            return true;
        }

        // Does this record have a default RESN?
        $individual_privacy = $this->tree->getIndividualPrivacy();
        if (isset($individual_privacy[$this->xref()])) {
            return $individual_privacy[$this->xref()] >= $access_level;
        }

        // Privacy rules do not apply to admins
        if (Auth::PRIV_NONE >= $access_level) {
            return true;
        }

        // Different types of record have different privacy rules
        return $this->canShowByType($access_level);
    }
756217
public function hasAccess(User $user, Application $app)
    {
        if ($this->getCollection($app) instanceof collection) {
            return $app->getAclForUser($user)->has_access_to_base($this->collection->get_base_id());
        }

        return true;
    }
877178
public void add(User user, AccessLevel accessLevel) {
        getAccessList().add(new Access(user, accessLevel));
    }
598305
protected function checkAccessControlRequestHeaders(array $accessControlRequestHeaders)
    {
        // Make sure all array elements are strings and not blank
        foreach ($accessControlRequestHeaders as $h) {
            if (!is_string($h) || $h === '') {
                return false;
            }
        }

        return true;
    }
380963
protected function canShowByType(int $access_level): bool
    {
        // Hide sources if they are attached to private repositories ...
        preg_match_all('/\n1 REPO @(.+)@/', $this->gedcom, $matches);
        foreach ($matches[1] as $match) {
            $repo = Repository::getInstance($match, $this->tree);
            if ($repo && !$repo->canShow($access_level)) {
                return false;
            }
        }

        // ... otherwise apply default behaviour
        return parent::canShowByType($access_level);
    }
644176
public function is_user_access_restricted_by_capability() {
        $userid = $this->modinfo->get_user_id();
        if ($userid == -1) {
            return null;
        }
        $capability = 'mod/' . $this->modname . ':view';
        $capabilityinfo = get_capability_info($capability);
        if (!$capabilityinfo) {
            // Capability does not exist, no one is prevented from seeing the activity.
            return false;
        }

        // You are blocked if you don't have the capability.
        return !has_capability($capability, $this->get_context(), $userid);
    }
358581
def validate_access!
        action = self.action_name
        clearance_levels = Array(current_clearance_levels)
        authorized = clearance_levels.any? { |c| keeper.lets? c, action, self.class }
        not_authorized! unless authorized
      end
390681
protected function normalizeAccessToken($access_token) {
    if (!isset($access_token['token_type'])) {
      $access_token['token_type'] = 'Bearer';
    }
    if (!isset($access_token['expires_at']) && isset($access_token['expires_in'])) {
      $access_token['expires_at'] = $access_token['expires_in'] + $access_token['request_time'];
    }
    return $access_token;
  }
1369991
public function checkAccess($p = P, $do = P_DO, $user_id = 0)
    {
        // Guest module can be opened by anyone
        if ($p === 'guest') {
            return true;
        }

        // Only logged-in Users can proceed further
        if (!$this->isLogged()) {
            return false;
        }

        // Get User id
        if (!$user_id) {
            $user_id = USER_ID;
        }

        // Check maybe User have group with full access
        $group_id = $this->getUserData('group_id', $user_id);
        if (self::getInstance()->getGroupData('full_access', $group_id)) {
            return true;
        }

        // Check or init cache
        if (!self::$access) {
            $group_access_collection = new GroupAccessRepository();
            $group_access_collection->setWhereGroupId((int)$group_id);
            foreach ($group_access_collection->getAsArrayOfObjectData() as $group_access) {
                /** @var GroupAccess $group_access */
                self::$access[$group_access['p']][$group_access['do']] = true;
            }
        }

        // Check access for exact admin panel page and action
        return isset(self::$access[$p][$do]);
    }
309166
protected function createPrivateGedcomRecord(int $access_level): string
    {
        $SHOW_PRIVATE_RELATIONSHIPS = $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS');

        $rec = '0 @' . $this->xref . '@ FAM';
        // Just show the 1 CHIL/HUSB/WIFE tag, not any subtags, which may contain private data
        preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches, PREG_SET_ORDER);
        foreach ($matches as $match) {
            $rela = Individual::getInstance($match[1], $this->tree);
            if ($rela && ($SHOW_PRIVATE_RELATIONSHIPS || $rela->canShow($access_level))) {
                $rec .= $match[0];
            }
        }

        return $rec;
    }
1039429
def user_has_access(self, user):
        
        if ROLE_ADMIN in user.roles:
            return True

        # Non-admin users should only see active accounts
        if self.enabled:
            if not self.required_roles:
                return True

            for role in self.required_roles:
                if role in user.roles:
                    return True

        return False
155710
private function userinfo($access_token){
		$userinfo = $this->serverGet('https://www.googleapis.com/oauth2/v1/userinfo', array('access_token' => $access_token), null, $headers);
		if (!empty($userinfo)){
			return $this->recursiveGetObjectVars(json_decode($userinfo));
		}
		else{
			$error = array(
				'code' => 'userinfo_error',
				'message' => 'Failed when attempting to query for user information',
				'raw' => array(
					'response' => $userinfo,
					'headers' => $headers
				)
			);

			$this->errorCallback($error);
		}
	}
545871
public function hasAccess(array $url, array $user): bool
    {
        $result = parent::hasAccess($url, $user);

        if (!$result) {
            return $result;
        }

        if (!empty($user['is_supervisor']) && $user['is_supervisor']) {
            $users = Utils::getReportToUsers($user['id']);

            foreach ($users as $userRecord) {
                $result = (new AccessFactory())->hasAccess($url, $userRecord->toArray());

                if ($result) {
                    return $result;
                }
            }
        }

        return false;
    }
1320357
public function children($access_level = null): Collection
    {
        if ($access_level === null) {
            $access_level = Auth::accessLevel($this->tree);
        }

        $SHOW_PRIVATE_RELATIONSHIPS = (bool) $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS');

        $children = new Collection();

        foreach ($this->facts(['CHIL'], false, $access_level, $SHOW_PRIVATE_RELATIONSHIPS) as $fact) {
            $child = $fact->target();

            if ($child instanceof Individual && ($SHOW_PRIVATE_RELATIONSHIPS || $child->canShowName($access_level))) {
                $children->push($child);
            }
        }

        return $children;
    }
305430
public function check_access() {
        global $CFG;
        $context = empty($this->context) ? context_system::instance() : $this->context;
        foreach($this->req_capability as $cap) {
            if (has_capability($cap, $context)) {
                return true;
            }
        }
        return false;
    }
793403
public function canView($member = null)
    {
        //get member
        if (!$member) {
            $member = Security::getCurrentUser();
        }
        //check for extensions, we do this first as they can overrule everything
        $extended = $this->extendedCan(__FUNCTION__, $member);
        if ($extended !== null) {
            return $extended;
        }

        //need to be logged in and/or most checks below rely on $member being a Member
        if (!$member) {
            return false;
        }
        // members can usually view their own record
        if ($this->ID == $member->ID) {
            return true;
        }

        //standard check
        return Permission::checkMember($member, 'CMS_ACCESS_SecurityAdmin');
    }
202038
public function has_access_to_base($base_id)
    {
        $this->load_rights_bas();

        return (isset($this->_rights_bas[$base_id]) &&
            $this->_rights_bas[$base_id][self::ACTIF] === true);
    }