Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Use protection scheme from data before using site-wide protection scheme #9607

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Auth/Protect/Protection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ public function data()

public function scheme()
{
if ($default = config('statamic.protect.default')) {
return $default;
if (
$this->data
&& $this->data instanceof Protectable
&& $scheme = $this->data->getProtectionScheme()
) {
return $scheme;
}

if ($this->data && $this->data instanceof Protectable) {
return $this->data->getProtectionScheme();
if ($default = config('statamic.protect.default')) {
return $default;
}

return null;
Expand Down
14 changes: 14 additions & 0 deletions tests/Auth/Protect/ProtectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ public function scheme_comes_from_data()
$this->assertEquals('logged_in', $this->protection->scheme());
}

/** @test */
public function scheme_comes_from_data_even_when_sitewide_scheme_is_defined()
{
config(['statamic.protect.default' => 'logged_in']);
config(['statamic.protect.schemes.logged_in' => [
'driver' => 'auth',
'form_url' => '/login',
]]);

$this->protection->setData($this->createEntryWithScheme('password'));

$this->assertEquals('password', $this->protection->scheme());
}

/** @test */
public function if_the_data_isnt_protectable_it_doesnt_get_a_scheme()
{
Expand Down
Loading