-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6572 from getkirby/fix/6400-preview-permission-pe…
…r-role Support role permissions for `preview` option
- Loading branch information
Showing
6 changed files
with
232 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -725,6 +725,25 @@ public function testPermalink() | |
|
||
public function testPreviewUrl() | ||
{ | ||
$app = $this->app->clone([ | ||
'users' => [ | ||
[ | ||
'id' => 'test', | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
'roles' => [ | ||
[ | ||
'id' => 'editor', | ||
'name' => 'editor', | ||
] | ||
] | ||
]); | ||
|
||
// authenticate | ||
$app->impersonate('[email protected]'); | ||
|
||
$page = new Page([ | ||
'slug' => 'test', | ||
'files' => [ | ||
|
@@ -738,8 +757,42 @@ public function testPreviewUrl() | |
$this->assertSame('/test/test.pdf', $file->previewUrl()); | ||
} | ||
|
||
public function testPreviewUrlUnauthenticated() | ||
{ | ||
$page = new Page([ | ||
'slug' => 'test', | ||
'files' => [ | ||
[ | ||
'filename' => 'test.pdf' | ||
] | ||
] | ||
]); | ||
|
||
$file = $page->file('test.pdf'); | ||
$this->assertNull($file->previewUrl()); | ||
} | ||
|
||
public function testPreviewUrlForDraft() | ||
{ | ||
$app = $this->app->clone([ | ||
'users' => [ | ||
[ | ||
'id' => 'test', | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
'roles' => [ | ||
[ | ||
'id' => 'editor', | ||
'name' => 'editor', | ||
] | ||
] | ||
]); | ||
|
||
// authenticate | ||
$app->impersonate('[email protected]'); | ||
|
||
$page = new Page([ | ||
'slug' => 'test', | ||
'isDraft' => true, | ||
|
@@ -754,7 +807,7 @@ public function testPreviewUrlForDraft() | |
$this->assertSame($file->url(), $file->previewUrl()); | ||
} | ||
|
||
public function testPreviewUrlForPageWithCustomPreviewSetting() | ||
public function testPreviewUrlForPageWithDeniedPreviewSetting() | ||
{ | ||
$app = new App([ | ||
'blueprints' => [ | ||
|
@@ -779,15 +832,98 @@ public function testPreviewUrlForPageWithCustomPreviewSetting() | |
] | ||
] | ||
] | ||
], | ||
'users' => [ | ||
[ | ||
'id' => 'test', | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
'roles' => [ | ||
[ | ||
'id' => 'editor', | ||
'name' => 'editor', | ||
] | ||
] | ||
]); | ||
|
||
// authenticate | ||
$app->impersonate('[email protected]'); | ||
|
||
$file = $app->file('test/test.pdf'); | ||
$this->assertNull($file->previewUrl()); | ||
} | ||
|
||
public function testPreviewUrlForPageWithCustomPreviewSetting() | ||
{ | ||
$app = new App([ | ||
'blueprints' => [ | ||
'pages/test' => [ | ||
'options' => [ | ||
'preview' => '/foo/bar' | ||
] | ||
] | ||
], | ||
'roots' => [ | ||
'index' => '/dev/null' | ||
], | ||
'site' => [ | ||
'children' => [ | ||
[ | ||
'slug' => 'test', | ||
'template' => 'test', | ||
'files' => [ | ||
[ | ||
'filename' => 'test.pdf' | ||
] | ||
] | ||
] | ||
] | ||
], | ||
'users' => [ | ||
[ | ||
'id' => 'test', | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
'roles' => [ | ||
[ | ||
'id' => 'editor', | ||
'name' => 'editor', | ||
] | ||
] | ||
]); | ||
|
||
// authenticate | ||
$app->impersonate('[email protected]'); | ||
|
||
$file = $app->file('test/test.pdf'); | ||
$this->assertSame($file->url(), $file->previewUrl()); | ||
} | ||
|
||
public function testPreviewUrlForUserFile() | ||
{ | ||
$app = $this->app->clone([ | ||
'users' => [ | ||
[ | ||
'id' => 'test', | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
'roles' => [ | ||
[ | ||
'id' => 'editor', | ||
'name' => 'editor', | ||
] | ||
] | ||
]); | ||
|
||
// authenticate | ||
$app->impersonate('[email protected]'); | ||
|
||
$user = new User([ | ||
'email' => '[email protected]', | ||
'files' => [ | ||
|
@@ -820,9 +956,25 @@ public function testPreviewUrlForExtendedComponent() | |
] | ||
] | ||
] | ||
], | ||
'users' => [ | ||
[ | ||
'id' => 'test', | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
'roles' => [ | ||
[ | ||
'id' => 'editor', | ||
'name' => 'editor', | ||
] | ||
] | ||
]); | ||
|
||
// authenticate | ||
$app->impersonate('[email protected]'); | ||
|
||
$file = $app->file('test/test.pdf'); | ||
$this->assertSame('https://getkirby.com/test.pdf', $file->previewUrl()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -583,9 +583,30 @@ public function testPreviewUrl() | |
'slug' => 'test' | ||
]); | ||
|
||
// authenticate | ||
$app->impersonate('kirby'); | ||
|
||
$this->assertSame('/test', $page->previewUrl()); | ||
} | ||
|
||
public function testPreviewUrlUnauthenticated() | ||
{ | ||
new App([ | ||
'roots' => [ | ||
'index' => '/dev/null' | ||
], | ||
'urls' => [ | ||
'index' => '/' | ||
] | ||
]); | ||
|
||
$page = new Page([ | ||
'slug' => 'test' | ||
]); | ||
|
||
$this->assertNull($page->previewUrl()); | ||
} | ||
|
||
public static function previewUrlProvider(): array | ||
{ | ||
return [ | ||
|
@@ -600,23 +621,46 @@ public static function previewUrlProvider(): array | |
['{{ page.url }}?preview=true', '/test?preview=true&{token}', true], | ||
[false, null, false], | ||
[false, null, true], | ||
[null, null, false, false], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider previewUrlProvider | ||
*/ | ||
public function testCustomPreviewUrl($input, $expected, $draft) | ||
{ | ||
public function testCustomPreviewUrl( | ||
$input, | ||
$expected, | ||
bool $draft, | ||
bool $authenticated = true | ||
): void { | ||
$app = new App([ | ||
'roots' => [ | ||
'index' => '/dev/null' | ||
], | ||
'urls' => [ | ||
'index' => '/' | ||
], | ||
'users' => [ | ||
[ | ||
'id' => 'test', | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
'roles' => [ | ||
[ | ||
'id' => 'editor', | ||
'name' => 'editor', | ||
] | ||
] | ||
]); | ||
|
||
// authenticate | ||
if ($authenticated) { | ||
$app->impersonate('[email protected]'); | ||
} | ||
|
||
$options = []; | ||
|
||
if ($input !== null) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,23 +194,45 @@ public static function previewUrlProvider(): array | |
['https://test.com', 'https://test.com'], | ||
['{{ site.url }}#test', '/#test'], | ||
[false, null], | ||
[null, null, false], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider previewUrlProvider | ||
*/ | ||
public function testCustomPreviewUrl($input, $expected) | ||
{ | ||
public function testCustomPreviewUrl( | ||
$input, | ||
$expected, | ||
bool $authenticated = true | ||
): void { | ||
$app = new App([ | ||
'roots' => [ | ||
'index' => '/dev/null' | ||
], | ||
'urls' => [ | ||
'index' => '/' | ||
], | ||
'users' => [ | ||
[ | ||
'id' => 'test', | ||
'email' => '[email protected]', | ||
'role' => 'editor' | ||
] | ||
], | ||
'roles' => [ | ||
[ | ||
'id' => 'editor', | ||
'name' => 'editor', | ||
] | ||
] | ||
]); | ||
|
||
// authenticate | ||
if ($authenticated) { | ||
$app->impersonate('[email protected]'); | ||
} | ||
|
||
$options = []; | ||
|
||
if ($input !== null) { | ||
|