Failed Conditions
Push — master ( 51347b...4787ce )
by Adrien
08:37
created

Acl::buildMessage()   A

Complexity

Conditions 6
Paths 17

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 10
nc 17
nop 4
dl 0
loc 20
ccs 11
cts 11
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Acl;
6
7
use Application\Acl\Assertion\BookableAvailable;
8
use Application\Acl\Assertion\ExpenseClaimStatusIsNew;
9
use Application\Acl\Assertion\StatusIsNew;
10
use Application\Model\Account;
11
use Application\Model\AccountingDocument;
12
use Application\Model\Bookable;
13
use Application\Model\BookableMetadata;
14
use Application\Model\BookableTag;
15
use Application\Model\Booking;
16
use Application\Model\Configuration;
17
use Application\Model\Country;
18
use Application\Model\ExpenseClaim;
19
use Application\Model\Image;
20
use Application\Model\License;
21
use Application\Model\Message;
22
use Application\Model\Transaction;
23
use Application\Model\TransactionTag;
24
use Application\Model\User;
25
use Application\Model\UserTag;
26
use Ecodev\Felix\Acl\Assertion\All;
27
use Ecodev\Felix\Acl\Assertion\IsMyself;
28
use Ecodev\Felix\Acl\Assertion\IsOwner;
29
30
class Acl extends \Ecodev\Felix\Acl\Acl
31
{
32 26
    public function __construct()
33
    {
34
        // Each role is strictly "stronger" than the last one
35 26
        $this->addRole(User::ROLE_ANONYMOUS);
36 26
        $this->addRole(User::ROLE_BOOKING_ONLY, User::ROLE_ANONYMOUS);
37 26
        $this->addRole(User::ROLE_INDIVIDUAL, User::ROLE_BOOKING_ONLY);
38 26
        $this->addRole(User::ROLE_MEMBER, User::ROLE_INDIVIDUAL);
39 26
        $this->addRole(User::ROLE_RESPONSIBLE, User::ROLE_MEMBER);
40 26
        $this->addRole(User::ROLE_ADMINISTRATOR, User::ROLE_RESPONSIBLE);
41
42 26
        $bookable = $this->createModelResource(Bookable::class);
43 26
        $bookableMetadata = $this->createModelResource(BookableMetadata::class);
44 26
        $bookableTag = $this->createModelResource(BookableTag::class);
45 26
        $booking = $this->createModelResource(Booking::class);
46 26
        $image = $this->createModelResource(Image::class);
47 26
        $license = $this->createModelResource(License::class);
48 26
        $user = $this->createModelResource(User::class);
49 26
        $userTag = $this->createModelResource(UserTag::class);
50 26
        $country = $this->createModelResource(Country::class);
51 26
        $account = $this->createModelResource(Account::class);
52 26
        $accountingDocument = $this->createModelResource(AccountingDocument::class);
53 26
        $transactionTag = $this->createModelResource(TransactionTag::class);
54 26
        $expenseClaim = $this->createModelResource(ExpenseClaim::class);
55 26
        $message = $this->createModelResource(Message::class);
56 26
        $transaction = $this->createModelResource(Transaction::class);
57 26
        $configuration = $this->createModelResource(Configuration::class);
58
59 26
        $this->allow(User::ROLE_ANONYMOUS, [$country, $bookable, $bookableMetadata, $bookableTag, $image, $license, $transactionTag, $configuration], ['read']);
60 26
        $this->allow(User::ROLE_BOOKING_ONLY, $booking, ['create'], new BookableAvailable());
61 26
        $this->allow(User::ROLE_BOOKING_ONLY, $booking, ['read', 'update']);
62
63 26
        $this->allow(User::ROLE_INDIVIDUAL, $user, ['read']);
64 26
        $this->allow(User::ROLE_INDIVIDUAL, $user, ['update'], new IsMyself());
65 26
        $this->allow(User::ROLE_INDIVIDUAL, [$expenseClaim], ['create']);
66 26
        $this->allow(User::ROLE_INDIVIDUAL, [$expenseClaim], ['read']);
67 26
        $this->allow(User::ROLE_INDIVIDUAL, [$expenseClaim], ['update', 'delete'], new All(new IsOwner(), new StatusIsNew()));
68 26
        $this->allow(User::ROLE_INDIVIDUAL, [$accountingDocument], ['create'], new ExpenseClaimStatusIsNew());
69 26
        $this->allow(User::ROLE_INDIVIDUAL, [$accountingDocument], ['read']);
70 26
        $this->allow(User::ROLE_INDIVIDUAL, [$accountingDocument], ['update', 'delete'], new All(new IsOwner(), new ExpenseClaimStatusIsNew()));
71 26
        $this->allow(User::ROLE_INDIVIDUAL, [$account], ['read']);
72 26
        $this->allow(User::ROLE_INDIVIDUAL, [$account], ['update'], new IsOwner());
73 26
        $this->allow(User::ROLE_INDIVIDUAL, $message, ['read']);
74
75 26
        $this->allow(User::ROLE_MEMBER, $user, ['create']);
76 26
        $this->allow(User::ROLE_MEMBER, $user, ['update'], new IsOwner());
77
78 26
        $this->allow(User::ROLE_RESPONSIBLE, [$transaction, $account, $transactionTag], ['read']);
79 26
        $this->allow(User::ROLE_RESPONSIBLE, [$expenseClaim, $accountingDocument], ['read', 'update']);
80 26
        $this->allow(User::ROLE_RESPONSIBLE, [$user], ['update']);
81 26
        $this->allow(User::ROLE_RESPONSIBLE, [$userTag], ['create', 'read', 'update', 'delete']);
82 26
        $this->allow(User::ROLE_RESPONSIBLE, [$bookable, $bookableMetadata, $bookableTag, $image, $license], ['create', 'update', 'delete']);
83 26
        $this->allow(User::ROLE_RESPONSIBLE, [$booking], ['delete']);
84
85 26
        $this->allow(User::ROLE_ADMINISTRATOR, [$transaction, $account, $transactionTag, $accountingDocument, $expenseClaim], ['create', 'update', 'delete']);
86 26
        $this->allow(User::ROLE_ADMINISTRATOR, [$configuration], ['create']);
87 26
    }
88
}
89