1 | <?php |
||
2 | |||
3 | namespace SilverStripe\RealMe\Extension; |
||
4 | |||
5 | use SilverStripe\RealMe\RealMeService; |
||
6 | use SilverStripe\Security\InheritedPermissions; |
||
7 | use SilverStripe\Security\Member; |
||
8 | use SilverStripe\ORM\DataObject; |
||
9 | use SilverStripe\ORM\DataExtension; |
||
10 | |||
11 | class SiteTreeExtension extends DataExtension |
||
12 | { |
||
13 | private static $dependencies = array( |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
14 | 'service' => '%$' . RealMeService::class |
||
15 | ); |
||
16 | |||
17 | /** |
||
18 | * @var RealMeService |
||
19 | */ |
||
20 | public $service; |
||
21 | |||
22 | /** |
||
23 | * This function is an extension of the default SiteTree canView(), and allows viewing permissions for a SiteTree |
||
24 | * object which has allowed a page to be presented to logged in users. With RealMe a logged in user is a user |
||
25 | * which has authenticated with the identity provider, and we have stored a FLT in session. |
||
26 | * |
||
27 | * Return true, if the CanViewType is LoggedInUsers, and we have a valid RealMe Session authenticated. |
||
28 | * |
||
29 | * @param Member|int $member |
||
30 | * |
||
31 | * @return bool|null True if the current user can view this page (or null to defer) |
||
32 | */ |
||
33 | public function canView($member) |
||
34 | { |
||
35 | // Defer if there's a member - this only catches allowing those who aren't members but might be authenticated |
||
36 | // with RealMe |
||
37 | if ($member && $member->ID) { |
||
38 | return null; |
||
39 | } |
||
40 | |||
41 | $data = $this->service->getUserData(); |
||
42 | if (empty($data)) { |
||
43 | // Defer if there's no logged in RealMe user |
||
44 | return null; |
||
45 | } |
||
46 | |||
47 | // Follow existing SiteTree logic where orphaned pages aren't viewable |
||
48 | if ($this->owner->isOrphaned()) { |
||
49 | return false; |
||
50 | } |
||
51 | |||
52 | if ($this->owner->CanViewType === InheritedPermissions::LOGGED_IN_USERS) { |
||
53 | // We have a logged in RealMe user (which may not be a member) |
||
54 | return true; |
||
55 | } |
||
56 | |||
57 | // Defer in all other cases |
||
58 | return null; |
||
59 | } |
||
60 | } |
||
61 |