1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\RestfulServer\Tests\Stubs; |
4
|
|
|
|
5
|
|
|
use SilverStripe\RestfulServer\Tests\Stubs\RestfulServerTestPage; |
6
|
|
|
use SilverStripe\RestfulServer\Tests\Stubs\RestfulServerTestAuthor; |
7
|
|
|
use SilverStripe\Security\Permission; |
8
|
|
|
use SilverStripe\ORM\DataObject; |
9
|
|
|
use SilverStripe\Security\PermissionProvider; |
10
|
|
|
use SilverStripe\Dev\TestOnly; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Everybody can view comments, logged in members in the "users" group can create comments, |
14
|
|
|
* but only "editors" can edit or delete them. |
15
|
|
|
* |
16
|
|
|
*/ |
17
|
|
|
class RestfulServerTestComment extends DataObject implements PermissionProvider, TestOnly |
18
|
|
|
{ |
19
|
|
|
private static $api_access = true; |
|
|
|
|
20
|
|
|
|
21
|
|
|
private static $table_name = 'RestfulServerTestComment'; |
|
|
|
|
22
|
|
|
|
23
|
|
|
private static $db = array( |
|
|
|
|
24
|
|
|
"Name" => "Varchar(255)", |
25
|
|
|
"Comment" => "Text" |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
private static $has_one = array( |
|
|
|
|
29
|
|
|
'Page' => RestfulServerTestPage::class, |
30
|
|
|
'Author' => RestfulServerTestAuthor::class, |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
public function providePermissions() |
34
|
|
|
{ |
35
|
|
|
return array( |
36
|
|
|
'EDIT_Comment' => 'Edit Comment Objects', |
37
|
|
|
'CREATE_Comment' => 'Create Comment Objects', |
38
|
|
|
'DELETE_Comment' => 'Delete Comment Objects', |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function canView($member = null) |
43
|
|
|
{ |
44
|
|
|
return true; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function canEdit($member = null) |
48
|
|
|
{ |
49
|
|
|
return Permission::checkMember($member, 'EDIT_Comment'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function canDelete($member = null) |
53
|
|
|
{ |
54
|
|
|
return Permission::checkMember($member, 'DELETE_Comment'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function canCreate($member = null, $context = array()) |
58
|
|
|
{ |
59
|
|
|
return Permission::checkMember($member, 'CREATE_Comment'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|