| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Class DataObjectExtension|Firesphere\SolrPermissions\Extensions\DataObjectExtension Generate the View permissions of |
||
| 4 | * each member for indexing |
||
| 5 | * |
||
| 6 | * @package Firesphere\Solr\Permissions |
||
| 7 | * @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo |
||
| 8 | * @copyright Copyright (c) 2018 - now() Firesphere & Sheepy |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Firesphere\SolrPermissions\Extensions; |
||
| 12 | |||
| 13 | use SilverStripe\ORM\ArrayList; |
||
| 14 | use SilverStripe\ORM\DataExtension; |
||
| 15 | use SilverStripe\ORM\DataObject; |
||
| 16 | use SilverStripe\Security\Member; |
||
| 17 | use SilverStripe\Security\Security; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Class \Firesphere\SolrPermissions\Extensions\DataObjectExtension |
||
| 21 | * |
||
| 22 | * Add the ability to get the Member View statusses for Solr. |
||
| 23 | * |
||
| 24 | * @package Firesphere\Solr\Permissions |
||
| 25 | * @property DataObject|DataObjectExtension $owner |
||
| 26 | */ |
||
| 27 | class DataObjectExtension extends DataExtension |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var ArrayList Cached list of the members to reduce looping impact |
||
| 31 | */ |
||
| 32 | protected static $memberList; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Get the member permissions for each unique user in the system |
||
| 36 | * This is additional to the GroupView permissions |
||
| 37 | * |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | 2 | public function getMemberView() |
|
| 41 | { |
||
| 42 | /** @var Member|null $currentUser */ |
||
| 43 | 2 | $currentUser = Security::getCurrentUser(); |
|
| 44 | 2 | Security::setCurrentUser(null); |
|
| 45 | |||
| 46 | 2 | if ($this->owner->canView(null)) { |
|
|
0 ignored issues
–
show
|
|||
| 47 | 2 | Security::setCurrentUser($currentUser); |
|
| 48 | |||
| 49 | 2 | return ['null']; |
|
| 50 | } |
||
| 51 | |||
| 52 | 1 | $return = $this->getViewList(); |
|
| 53 | |||
| 54 | 1 | Security::setCurrentUser($currentUser); |
|
| 55 | |||
| 56 | 1 | return $return; |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Get the list of members who can view this owner |
||
| 61 | * |
||
| 62 | * @return array |
||
| 63 | */ |
||
| 64 | 1 | private function getViewList(): array |
|
| 65 | { |
||
| 66 | 1 | if (!static::$memberList) { |
|
| 67 | 1 | static::$memberList = ArrayList::create(Member::get()->toArray()); |
|
| 68 | } |
||
| 69 | |||
| 70 | 1 | $return = ['false']; |
|
| 71 | 1 | foreach (static::$memberList as $member) { |
|
| 72 | 1 | if ($this->owner->canView($member)) { |
|
| 73 | 1 | $return[] = sprintf('1-%s', $member->ID); |
|
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | 1 | return $return; |
|
| 78 | } |
||
| 79 | } |
||
| 80 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.