1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Firesphere\SolrPermissions\Extensions; |
5
|
|
|
|
6
|
|
|
use SilverStripe\ORM\ArrayList; |
7
|
|
|
use SilverStripe\ORM\DataExtension; |
8
|
|
|
use SilverStripe\ORM\DataObject; |
9
|
|
|
use SilverStripe\Security\Member; |
10
|
|
|
use SilverStripe\Security\Security; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class \Firesphere\SolrPermissions\Extensions\DataObjectExtension |
14
|
|
|
* |
15
|
|
|
* Add the ability to get the Member View statusses for Solr. |
16
|
|
|
* |
17
|
|
|
* @package Firesphere\SolrPermissions\Extensions |
18
|
|
|
* @property DataObject|DataObjectExtension $owner |
19
|
|
|
*/ |
20
|
|
|
class DataObjectExtension extends DataExtension |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ArrayList Cached list of the members to reduce looping impact |
24
|
|
|
*/ |
25
|
|
|
protected static $memberList; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Get the member permissions for each unique user in the system |
29
|
|
|
* This is additional to the GroupView permissions |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
public function getMemberView() |
34
|
|
|
{ |
35
|
|
|
/** @var Member|null $currentUser */ |
36
|
|
|
$currentUser = Security::getCurrentUser(); |
37
|
|
|
Security::setCurrentUser(null); |
38
|
|
|
|
39
|
|
|
if ($this->owner->canView(null)) { |
|
|
|
|
40
|
|
|
Security::setCurrentUser($currentUser); |
41
|
|
|
|
42
|
|
|
return ['null']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$return = $this->getViewList(); |
46
|
|
|
|
47
|
|
|
Security::setCurrentUser($currentUser); |
48
|
|
|
|
49
|
|
|
return $return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get the list of members who can view this owner |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
private function getViewList(): array |
58
|
|
|
{ |
59
|
|
|
if (!static::$memberList) { |
60
|
|
|
static::$memberList = ArrayList::create(Member::get()->toArray()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$return = ['false']; |
64
|
|
|
foreach (static::$memberList as $member) { |
65
|
|
|
if ($this->owner->canView($member)) { |
66
|
|
|
$return[] = sprintf('1-%s', $member->ID); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $return; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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.