|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dynamic\FlexSlider\Model; |
|
4
|
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Forms\TextCheckboxGroupField; |
|
|
|
|
|
|
6
|
|
|
use Dynamic\FlexSlider\Interfaces\SlideInterface; |
|
7
|
|
|
use SilverStripe\Forms\FieldList; |
|
8
|
|
|
use SilverStripe\ORM\DataObject; |
|
9
|
|
|
use SilverStripe\Security\InheritedPermissions; |
|
10
|
|
|
use SilverStripe\Security\InheritedPermissionsExtension; |
|
11
|
|
|
use SilverStripe\Security\Permission; |
|
12
|
|
|
use SilverStripe\Security\PermissionProvider; |
|
13
|
|
|
use SilverStripe\Security\Security; |
|
14
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
|
15
|
|
|
use SilverStripe\Versioned\Versioned; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Slide |
|
19
|
|
|
* @package Dynamic\FlexSlider\Model |
|
20
|
|
|
* |
|
21
|
|
|
* @mixin Versioned |
|
22
|
|
|
* @mixin InheritedPermissionsExtension |
|
23
|
|
|
*/ |
|
24
|
|
|
class Slide extends DataObject implements PermissionProvider, SlideInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* The Create permission |
|
28
|
|
|
*/ |
|
29
|
|
|
const SLIDE_CREATE = 'SLIDE_CREATE'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The Publish permission |
|
33
|
|
|
*/ |
|
34
|
|
|
const SLIDE_PUBLISH = 'SLIDE_PUBLISH'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The Edit permission |
|
38
|
|
|
*/ |
|
39
|
|
|
const SLIDE_EDIT = 'SLIDE_EDIT'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* The Delete permission |
|
43
|
|
|
*/ |
|
44
|
|
|
const SLIDE_DELETE = 'SLIDE_DELETE'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
private static $singular_name = 'Slide'; |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
private static $plural_name = 'Slides'; |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var string |
|
58
|
|
|
*/ |
|
59
|
|
|
private static $table_name = 'Slide'; |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var array |
|
63
|
|
|
*/ |
|
64
|
|
|
private static $db = [ |
|
|
|
|
|
|
65
|
|
|
'Title' => 'Varchar(255)', |
|
66
|
|
|
'ShowTitle' => 'Boolean', |
|
67
|
|
|
'Content' => 'HTMLText', |
|
68
|
|
|
'SortOrder' => 'Int', |
|
69
|
|
|
]; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @var array |
|
73
|
|
|
*/ |
|
74
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
75
|
|
|
'Page' => \Page::class, |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @var array |
|
80
|
|
|
*/ |
|
81
|
|
|
private static $extensions = [ |
|
|
|
|
|
|
82
|
|
|
Versioned::class, |
|
83
|
|
|
InheritedPermissionsExtension::class, |
|
84
|
|
|
]; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @var array |
|
88
|
|
|
*/ |
|
89
|
|
|
private static $versioning = [ |
|
|
|
|
|
|
90
|
|
|
"Stage", "Live", |
|
91
|
|
|
]; |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @var string |
|
96
|
|
|
*/ |
|
97
|
|
|
private static $default_sort = 'SortOrder'; |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Adds Publish button to SlideImage record |
|
101
|
|
|
* |
|
102
|
|
|
* @var bool |
|
103
|
|
|
*/ |
|
104
|
|
|
private static $versioned_gridfield_extensions = true; |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @var array |
|
108
|
|
|
*/ |
|
109
|
|
|
private static $searchable_fields = [ |
|
|
|
|
|
|
110
|
|
|
'Title', |
|
111
|
|
|
'Content', |
|
112
|
|
|
]; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @var array |
|
116
|
|
|
*/ |
|
117
|
|
|
private static $summary_fields = [ |
|
|
|
|
|
|
118
|
|
|
'SlideType', |
|
119
|
|
|
'Title', |
|
120
|
|
|
]; |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return FieldList |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getCMSFields() |
|
126
|
|
|
{ |
|
127
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
128
|
|
|
$viewInherit = $fields->dataFieldByName('CanViewType'); |
|
129
|
|
|
$editInherit = $fields->dataFieldByName('CanEditType'); |
|
130
|
|
|
|
|
131
|
|
|
$fields->removeByName([ |
|
132
|
|
|
'Title', |
|
133
|
|
|
'ShowTitle', |
|
134
|
|
|
'SortOrder', |
|
135
|
|
|
'CanViewType', |
|
136
|
|
|
'CanEditType', |
|
137
|
|
|
'PageID', |
|
138
|
|
|
]); |
|
139
|
|
|
|
|
140
|
|
|
$fields->addFieldToTab( |
|
141
|
|
|
'Root.Main', |
|
142
|
|
|
TextCheckboxGroupField::create(), |
|
143
|
|
|
'Content' |
|
144
|
|
|
); |
|
145
|
|
|
|
|
146
|
|
|
$fields->addFieldsToTab( |
|
147
|
|
|
'Root.Permissions', |
|
148
|
|
|
[ |
|
149
|
|
|
$viewInherit, |
|
150
|
|
|
$editInherit, |
|
151
|
|
|
] |
|
152
|
|
|
); |
|
153
|
|
|
}); |
|
154
|
|
|
|
|
155
|
|
|
return parent::getCMSFields(); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return array |
|
160
|
|
|
*/ |
|
161
|
|
|
public function providePermissions() |
|
162
|
|
|
{ |
|
163
|
|
|
return [ |
|
164
|
|
|
static::SLIDE_CREATE => [ |
|
165
|
|
|
'name' => _t(__CLASS__ . '.PERMISSION_CREATE_DESCRIPTION', 'Create Slides'), |
|
166
|
|
|
'help' => _t(__CLASS__ . '.PERMISSION_CREATE_HELP', 'Allow creating slides'), |
|
167
|
|
|
'category' => _t(__CLASS__ . '.PERMISSIONS_CATEGORY', 'FlexSlider Permissions'), |
|
168
|
|
|
'sort' => 100, |
|
169
|
|
|
], |
|
170
|
|
|
static::SLIDE_PUBLISH => [ |
|
171
|
|
|
'name' => _t(__CLASS__ . '.PERMISSION_PUBLISH_DESCRIPTION', 'Publish Slides'), |
|
172
|
|
|
'help' => _t(__CLASS__ . '.PERMISSION_PUBLISH_HELP', 'Allow publishing slides'), |
|
173
|
|
|
'category' => _t(__CLASS__ . '.PERMISSIONS_CATEGORY', 'FlexSlider Permissions'), |
|
174
|
|
|
'sort' => 100, |
|
175
|
|
|
], |
|
176
|
|
|
static::SLIDE_EDIT => [ |
|
177
|
|
|
'name' => _t(__CLASS__ . '.PERMISSION_EDIT_DESCRIPTION', 'Edit Slides'), |
|
178
|
|
|
'help' => _t(__CLASS__ . '.PERMISSION_EDIT_HELP', 'Allow editing slides'), |
|
179
|
|
|
'category' => _t(__CLASS__ . '.PERMISSIONS_CATEGORY', 'FlexSlider Permissions'), |
|
180
|
|
|
'sort' => 100, |
|
181
|
|
|
], |
|
182
|
|
|
static::SLIDE_DELETE => [ |
|
183
|
|
|
'name' => _t(__CLASS__ . '.PERMISSION_DELETE_DESCRIPTION', 'Delete Slides'), |
|
184
|
|
|
'help' => _t(__CLASS__ . '.PERMISSION_DELETE_HELP', 'Allow deleting slides'), |
|
185
|
|
|
'category' => _t(__CLASS__ . '.PERMISSIONS_CATEGORY', 'FlexSlider Permissions'), |
|
186
|
|
|
'sort' => 100, |
|
187
|
|
|
], |
|
188
|
|
|
]; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @param null $member |
|
|
|
|
|
|
193
|
|
|
* @param array $context |
|
194
|
|
|
* @return bool|int |
|
195
|
|
|
*/ |
|
196
|
|
|
public function canCreate($member = null, $context = []) |
|
197
|
|
|
{ |
|
198
|
|
|
if (!$member) { |
|
|
|
|
|
|
199
|
|
|
$member = Security::getCurrentUser(); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
// Standard mechanism for accepting permission changes from extensions |
|
203
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member, $context); |
|
204
|
|
|
if ($extended !== null) { |
|
205
|
|
|
return $extended; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
// Check permission |
|
209
|
|
|
if ($member && Permission::checkMember($member, "ADMIN") || Permission::checkMember($member, static::SLIDE_CREATE)) { |
|
|
|
|
|
|
210
|
|
|
return true; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
// This doesn't necessarily mean we are creating a root page, but that |
|
214
|
|
|
// we don't know if there is a parent, so default to this permission |
|
215
|
|
|
return SiteConfig::current_site_config()->canCreateTopLevel($member); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @param null $member |
|
|
|
|
|
|
220
|
|
|
* @return bool|int |
|
221
|
|
|
*/ |
|
222
|
|
|
public function canPublish($member = null) |
|
223
|
|
|
{ |
|
224
|
|
|
if (!$member) { |
|
|
|
|
|
|
225
|
|
|
$member = Security::getCurrentUser(); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
// Check extension |
|
229
|
|
|
$extended = $this->extendedCan('canPublish', $member); |
|
230
|
|
|
if ($extended !== null) { |
|
231
|
|
|
return $extended; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
if (Permission::checkMember($member, "ADMIN") || Permission::checkMember($member, static::SLIDE_PUBLISH)) { |
|
235
|
|
|
return true; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
return false; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* @param null $member |
|
|
|
|
|
|
243
|
|
|
* @return bool|int |
|
244
|
|
|
*/ |
|
245
|
|
|
public function canEdit($member = null) |
|
246
|
|
|
{ |
|
247
|
|
|
if (!$member) { |
|
|
|
|
|
|
248
|
|
|
$member = Security::getCurrentUser(); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
// Standard mechanism for accepting permission changes from extensions |
|
252
|
|
|
$extended = $this->extendedCan('canEdit', $member); |
|
253
|
|
|
if ($extended !== null) { |
|
254
|
|
|
return $extended; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
// Default permissions |
|
258
|
|
|
if (Permission::checkMember($member, "ADMIN") || Permission::checkMember($member, static::SLIDE_EDIT)) { |
|
259
|
|
|
return true; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
|
|
263
|
|
|
return false; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @param null $member |
|
|
|
|
|
|
268
|
|
|
* @return bool|null |
|
269
|
|
|
*/ |
|
270
|
|
|
public function canView($member = null) |
|
271
|
|
|
{ |
|
272
|
|
|
if (!$member) { |
|
|
|
|
|
|
273
|
|
|
$member = Security::getCurrentUser(); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
// Standard mechanism for accepting permission changes from extensions |
|
277
|
|
|
$extended = $this->extendedCan('canView', $member); |
|
278
|
|
|
if ($extended !== null) { |
|
279
|
|
|
return $extended; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
// admin override |
|
283
|
|
|
if ($member && Permission::checkMember($member, ["ADMIN", "SITETREE_VIEW_ALL"])) { |
|
284
|
|
|
return true; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
// Note: getInheritedPermissions() is disused in this instance |
|
288
|
|
|
// to allow parent canView extensions to influence subpage canView() |
|
289
|
|
|
|
|
290
|
|
|
// check for empty spec |
|
291
|
|
|
if (!$this->CanViewType || $this->CanViewType === InheritedPermissions::ANYONE) { |
|
|
|
|
|
|
292
|
|
|
return true; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
// check for inherit |
|
296
|
|
|
if ($this->CanViewType === InheritedPermissions::INHERIT) { |
|
297
|
|
|
return $this->getSiteConfig()->canViewPages($member); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
// check for any logged-in users |
|
301
|
|
|
if ($this->CanViewType === InheritedPermissions::LOGGED_IN_USERS && $member && $member->ID) { |
|
302
|
|
|
return true; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
// check for specific groups |
|
306
|
|
|
if ($this->CanViewType === InheritedPermissions::ONLY_THESE_USERS |
|
307
|
|
|
&& $member |
|
308
|
|
|
&& $member->inGroups($this->ViewerGroups()) |
|
|
|
|
|
|
309
|
|
|
) { |
|
310
|
|
|
return true; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
return false; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* @param null $member |
|
|
|
|
|
|
318
|
|
|
* @return bool|int |
|
319
|
|
|
*/ |
|
320
|
|
|
public function canDelete($member = null) |
|
321
|
|
|
{ |
|
322
|
|
|
if (!$member) { |
|
|
|
|
|
|
323
|
|
|
$member = Security::getCurrentUser(); |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
// Standard mechanism for accepting permission changes from extensions |
|
327
|
|
|
$extended = $this->extendedCan('canDelete', $member); |
|
328
|
|
|
if ($extended !== null) { |
|
329
|
|
|
return $extended; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
if (!$member) { |
|
|
|
|
|
|
333
|
|
|
return false; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
// Default permission check |
|
337
|
|
|
if (Permission::checkMember($member, ["ADMIN", static::SLIDE_DELETE])) { |
|
338
|
|
|
return true; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
return false; |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
/** |
|
345
|
|
|
* Stub method to get the site config, unless the current class can provide an alternate. |
|
346
|
|
|
* |
|
347
|
|
|
* @return SiteConfig |
|
348
|
|
|
*/ |
|
349
|
|
|
public function getSiteConfig() |
|
350
|
|
|
{ |
|
351
|
|
|
$configs = $this->invokeWithExtensions('alternateSiteConfig'); |
|
352
|
|
|
foreach (array_filter($configs) as $config) { |
|
353
|
|
|
return $config; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
return SiteConfig::current_site_config(); |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* @return string |
|
361
|
|
|
*/ |
|
362
|
|
|
public function getSlideType() |
|
363
|
|
|
{ |
|
364
|
|
|
return static::i18n_singular_name(); |
|
|
|
|
|
|
365
|
|
|
} |
|
366
|
|
|
} |
|
367
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths