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