Passed
Pull Request — master (#42)
by
unknown
01:59
created

RestfulServerTestComment::canEdit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
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;
0 ignored issues
show
introduced by
The private property $api_access is not used, and could be removed.
Loading history...
20
21
    private static $table_name = 'RestfulServerTestComment';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
22
23
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
24
        "Name" => "Varchar(255)",
25
        "Comment" => "Text"
26
    );
27
28
    private static $has_one = array(
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
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