Skip to content

Commit

Permalink
[4.x] Use protection scheme from data before using site-wide protecti…
Browse files Browse the repository at this point in the history
…on scheme (#9607)
  • Loading branch information
duncanmcclean authored Feb 28, 2024
1 parent f20d135 commit e088b18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
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

0 comments on commit e088b18

Please sign in to comment.