<commit_before><?php namespace Anomaly\PagesModule\Page;

use Anomaly\PagesModule\Page\Contract\PageInterface;
use Anomaly\Streams\Platform\Support\Authorizer;
use Anomaly\UsersModule\User\Contract\UserInterface;
use Illuminate\Auth\Guard;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Routing\ResponseFactory;

/**
 * Class PageAuthorizer
 *
 * @link          http://pyrocms.com/
 * @author        PyroCMS, Inc. <<EMAIL>>
 * @author        <NAME> <<EMAIL>>
 * @package       Anomaly\PagesModule\Page
 */
class PageAuthorizer
{

    /**
     * The authorization utility.
     *
     * @var Guard
     */
    protected $guard;

    /**
     * The config repository.
     *
     * @var Repository
     */
    protected $config;

    /**
     * The response factory.
     *
     * @var ResponseFactory
     */
    protected $response;

    /**
     * The authorizer utility.
     *
     * @var Authorizer
     */
    protected $authorizer;

    /**
     * Create a new PageAuthorizer instance.
     *
     * @param Guard           $guard
     * @param Repository      $config
     * @param Authorizer      $authorizer
     * @param ResponseFactory $response
     */
    public function __construct(Guard $guard, Repository $config, Authorizer $authorizer, ResponseFactory $response)
    {
        $this->guard      = $guard;
        $this->config     = $config;
        $this->response   = $response;
        $this->authorizer = $authorizer;
    }

    /**
     * Authorize the page.
     *
     * @param PageInterface $page
     */
    public function authorize(PageInterface $page)
    {
        /* @var UserInterface $user */
        $user = $this->guard->user();

        /**
         * If the page is not enabled and we
         * are not logged in then 404.
         */
        if (!$page->isEnabled() && !$user) {
            abort(404);
        }

        /**
         * If the page is not enabled and we are
         * logged in then make sure we have permission.
         */
        if (!$page->isEnabled()) {
            $this->authorizer->authorize('anomaly.module.pages::view_drafts');
        }

        /**
         * If the page is restricted to specific
         * roles then make sure our user is one of them.
         */
        $allowed = $page->getAllowedRoles();

        if (!$allowed->isEmpty() && (!$user || !$user->hasAnyRole($allowed))) {
            $page->setResponse($this->response->redirectGuest($this->config->get('streams::access.login', 'login')));
        }
    }
}<commit_msg>Paths<commit_after><?php namespace Anomaly\PagesModule\Page;

use Anomaly\PagesModule\Page\Contract\PageInterface;
use Anomaly\Streams\Platform\Support\Authorizer;
use Anomaly\UsersModule\User\Contract\UserInterface;
use Illuminate\Auth\Guard;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Routing\ResponseFactory;

/**
 * Class PageAuthorizer
 *
 * @link          http://pyrocms.com/
 * @author        PyroCMS, Inc. <<EMAIL>>
 * @author        <NAME> <<EMAIL>>
 * @package       Anomaly\PagesModule\Page
 */
class PageAuthorizer
{

    /**
     * The authorization utility.
     *
     * @var Guard
     */
    protected $guard;

    /**
     * The config repository.
     *
     * @var Repository
     */
    protected $config;

    /**
     * The response factory.
     *
     * @var ResponseFactory
     */
    protected $response;

    /**
     * The authorizer utility.
     *
     * @var Authorizer
     */
    protected $authorizer;

    /**
     * Create a new PageAuthorizer instance.
     *
     * @param Guard           $guard
     * @param Repository      $config
     * @param Authorizer      $authorizer
     * @param ResponseFactory $response
     */
    public function __construct(Guard $guard, Repository $config, Authorizer $authorizer, ResponseFactory $response)
    {
        $this->guard      = $guard;
        $this->config     = $config;
        $this->response   = $response;
        $this->authorizer = $authorizer;
    }

    /**
     * Authorize the page.
     *
     * @param PageInterface $page
     */
    public function authorize(PageInterface $page)
    {
        /* @var UserInterface $user */
        $user = $this->guard->user();

        /**
         * If the page is not enabled and we
         * are not logged in then 404.
         */
        if (!$page->isEnabled() && !$user) {
            abort(404);
        }

        /**
         * If the page is not enabled and we are
         * logged in then make sure we have permission.
         */
        if (!$page->isEnabled()) {
            $this->authorizer->authorize('anomaly.module.pages::view_drafts');
        }

        /**
         * If the page is restricted to specific
         * roles then make sure our user is one of them.
         */
        $allowed = $page->getAllowedRoles();

        if (!$allowed->isEmpty() && (!$user || !$user->hasAnyRole($allowed))) {
            $page->setResponse(
                $this->response->redirectGuest($this->config->get('anomaly.module.users::paths.login', 'login'))
            );
        }
    }
}
{'fraction_non_alphanumeric': 0.13031496062992126, 'fraction_numerical': 0.002362204724409449, 'mean_word_length': 1.9352975158867707, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1434346', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1442, 'n_words': 343}