Passed
Push — master ( ce5b30...8f6961 )
by Jason
02:09
created

FileListObject::canView()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 12
1
<?php
2
3
namespace Dynamic\Elements\FileList\Model;
4
5
use Dynamic\Elements\FileList\Elements\ElementFileList;
6
use SilverStripe\Assets\File;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\Security\Permission;
9
10
class FileListObject extends DataObject
11
{
12
    /**
13
     * @var string
14
     */
15
    private static $singular_name = 'File';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
16
17
    /**
18
     * @var string
19
     */
20
    private static $plural_name = 'Files';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
21
22
    /**
23
     * @var array
24
     */
25
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
26
        'Title' => 'Varchar(255)',
27
        'SortOrder' => "Int",
28
    ];
29
30
    /**
31
     * @var array
32
     */
33
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
34
        'FileList' => ElementFileList::class,
35
        'File' => File::class,
36
    ];
37
38
    /**
39
     * @var array
40
     */
41
    private static $owns = [
0 ignored issues
show
introduced by
The private property $owns is not used, and could be removed.
Loading history...
42
        'File',
43
    ];
44
45
    /**
46
     * @var array
47
     */
48 1
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
49
        'File.Name' => 'File',
50 1
        'Title',
51
    ];
52 1
53 1
    /**
54
     * @var string
55
     */
56 1
    private static $table_name = 'FileListObject';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
57
58
    /**
59
     * @return \SilverStripe\Forms\FieldList
60
     */
61
    public function getCMSFields()
62
    {
63
        $fields = parent::getCMSFields();
64
65
        $fields->removeByName([
66
            'FileListID',
67
            'SortOrder',
68
        ]);
69
70
        return $fields;
71
    }
72
73
    /**
74
     * Basic permissions, defaults to page perms where possible.
75
     *
76
     * @param \SilverStripe\Security\Member|null $member
77
     * @return boolean
78
     */
79
    public function canView($member = null)
80
    {
81
        $extended = $this->extendedCan(__FUNCTION__, $member);
82
        if ($extended !== null) {
83
            return $extended;
84
        }
85
86
        if ($page = $this->FileList()->getPage()) {
0 ignored issues
show
Bug introduced by
The method FileList() does not exist on Dynamic\Elements\FileList\Model\FileListObject. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
        if ($page = $this->/** @scrutinizer ignore-call */ FileList()->getPage()) {
Loading history...
87
            return $page->canView($member);
88
        }
89
90
        return Permission::check('CMS_ACCESS', 'any', $member);
91
    }
92
93
    /**
94
     * Basic permissions, defaults to page perms where possible.
95
     *
96
     * @param \SilverStripe\Security\Member|null $member
97
     *
98
     * @return boolean
99
     */
100
    public function canEdit($member = null)
101
    {
102
        $extended = $this->extendedCan(__FUNCTION__, $member);
103
        if ($extended !== null) {
104
            return $extended;
105
        }
106
107
        if ($page = $this->FileList()->getPage()) {
108
            return $page->canEdit($member);
109
        }
110
111
        return Permission::check('CMS_ACCESS', 'any', $member);
112
    }
113
114
    /**
115
     * Basic permissions, defaults to page perms where possible.
116
     *
117
     * Uses archive not delete so that current stage is respected i.e if a
118
     * element is not published, then it can be deleted by someone who doesn't
119
     * have publishing permissions.
120
     *
121
     * @param \SilverStripe\Security\Member|null $member
122
     *
123
     * @return boolean
124
     */
125
    public function canDelete($member = null)
126
    {
127
        $extended = $this->extendedCan(__FUNCTION__, $member);
128
        if ($extended !== null) {
129
            return $extended;
130
        }
131
132
        if ($page = $this->FileList()->getPage()) {
133
            return $page->canArchive($member);
134
        }
135
136
        return Permission::check('CMS_ACCESS', 'any', $member);
137
    }
138
139
    /**
140
     * Basic permissions, defaults to page perms where possible.
141
     *
142
     * @param \SilverStripe\Security\Member|null $member
143
     * @param array $context
144
     *
145
     * @return boolean
146
     */
147
    public function canCreate($member = null, $context = array())
148
    {
149
        $extended = $this->extendedCan(__FUNCTION__, $member);
150
        if ($extended !== null) {
151
            return $extended;
152
        }
153
154
        return Permission::check('CMS_ACCESS', 'any', $member);
155
    }
156
}
157