src/Versioned.php
public function canViewVersioned($member = null)
    {
        // Bypass when live stage
        $owner = $this->owner;

        // Bypass if site is unsecured
        if (!self::get_draft_site_secured()) {
            return true;
        }

        // Get reading mode from source query (or current mode)
        $readingParams = $owner->getSourceQueryParams()
            // Guess record mode from current reading mode instead
            ?: ReadingMode::toDataQueryParams(static::get_reading_mode());

        // If this is the live record we can view it
        if (isset($readingParams["Versioned.mode"])
            && $readingParams["Versioned.mode"] === 'stage'
            && $readingParams["Versioned.stage"] === static::LIVE
        ) {
            return true;
        }

        // Bypass if record doesn't have a live stage
        if (!$this->hasStages()) {
            return true;
        }

        // If we weren't definitely loaded from live, and we can't view non-live content, we need to
        // check to make sure this version is the live version and so can be viewed
        $latestVersion = Versioned::get_versionnumber_by_stage(get_class($owner), static::LIVE, $owner->ID);
        if ($latestVersion == $owner->Version) {
            // Even if this is loaded from a non-live stage, this is the live version
            return true;
        }

        // If stages are synchronised treat this as the live stage
        if (!$this->stagesDiffer()) {
            return true;
        }

        // Extend versioned behaviour
        $extended = $owner->extendedCan('canViewNonLive', $member);
        if ($extended !== null) {
            return (bool)$extended;
        }

        // Fall back to default permission check
        $permissions = Config::inst()->get(get_class($owner), 'non_live_permissions');
        $check = Permission::checkMember($member, $permissions);
        return (bool)$check;
    }
public function canViewVersioned($member = null)
    {
        // Bypass when live stage
        $owner = $this->owner;

        // Bypass if site is unsecured
        if (!self::get_draft_site_secured()) {
            return true;
        }

        // Get reading mode from source query (or current mode)
        $readingParams = $owner->getSourceQueryParams()
            // Guess record mode from current reading mode instead
            ?: ReadingMode::toDataQueryParams(static::get_reading_mode());

        // If this is the live record we can view it
        if (isset($readingParams["Versioned.mode"])
            && $readingParams["Versioned.mode"] === 'stage'
            && $readingParams["Versioned.stage"] === static::LIVE
        ) {
            return true;
        }

        // Bypass if record doesn't have a live stage
        if (!$this->hasStages()) {
            return true;
        }

        // If we weren't definitely loaded from live, and we can't view non-live content, we need to
        // check to make sure this version is the live version and so can be viewed
        $latestVersion = Versioned::get_versionnumber_by_stage(get_class($owner), static::LIVE, $owner->ID);
        if ($latestVersion == $owner->Version) {
            // Even if this is loaded from a non-live stage, this is the live version
            return true;
        }

        // If stages are synchronised treat this as the live stage
        if (!$this->stagesDiffer()) {
            return true;
        }

        // Extend versioned behaviour
        $extended = $owner->extendedCan('canViewNonLive', $member);
        if ($extended !== null) {
            return (bool)$extended;
        }

        // Fall back to default permission check
        $permissions = Config::inst()->get(get_class($owner), 'non_live_permissions');
        $check = Permission::checkMember($member, $permissions);
        return (bool)$check;
    }
public function canViewVersioned ( $ member = null ) { // Bypass when live stage $ owner = $ this -> owner ; // Bypass if site is unsecured if ( ! self :: get_draft_site_secured ( ) ) { return true ; } // Get reading mode from source query (or current mode) $ readingParams = $ owner -> getSourceQueryParams ( ) // Guess record mode from current reading mode instead ? : ReadingMode :: toDataQueryParams ( static :: get_reading_mode ( ) ) ; // If this is the live record we can view it if ( isset ( $ readingParams [ "Versioned.mode" ] ) && $ readingParams [ "Versioned.mode" ] === 'stage' && $ readingParams [ "Versioned.stage" ] === static :: LIVE ) { return true ; } // Bypass if record doesn't have a live stage if ( ! $ this -> hasStages ( ) ) { return true ; } // If we weren't definitely loaded from live, and we can't view non-live content, we need to // check to make sure this version is the live version and so can be viewed $ latestVersion = Versioned :: get_versionnumber_by_stage ( get_class ( $ owner ) , static :: LIVE , $ owner -> ID ) ; if ( $ latestVersion == $ owner -> Version ) { // Even if this is loaded from a non-live stage, this is the live version return true ; } // If stages are synchronised treat this as the live stage if ( ! $ this -> stagesDiffer ( ) ) { return true ; } // Extend versioned behaviour $ extended = $ owner -> extendedCan ( 'canViewNonLive' , $ member ) ; if ( $ extended !== null ) { return ( bool ) $ extended ; } // Fall back to default permission check $ permissions = Config :: inst ( ) -> get ( get_class ( $ owner ) , 'non_live_permissions' ) ; $ check = Permission :: checkMember ( $ member , $ permissions ) ; return ( bool ) $ check ; }
Determine if there are any additional restrictions on this object for the given reading version.

Override this in a subclass to customise any additional effect that Versioned applies to canView.

This is expected to be called by canView, and thus is only responsible for denying access if
the default canView would otherwise ALLOW access. Thus it should not be called in isolation
as an authoritative permission check.

This has the following extension points:
- canViewDraft is invoked if Mode = stage and Stage = stage
- canViewArchived is invoked if Mode = archive

@param Member $member
@return bool False is returned if the current viewing mode denies visibility
Determine if there are any additional restrictions on this object for the given reading version .