Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
4 / 5 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ChecksRole | |
80.00% |
4 / 5 |
|
80.00% |
4 / 5 |
6.29 | |
0.00% |
0 / 1 |
| isCommercial | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isCustomerService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| canWrite | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| canManage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| canDelete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\Concerns; |
| 4 | |
| 5 | trait ChecksRole |
| 6 | { |
| 7 | protected function isCommercial(): bool |
| 8 | { |
| 9 | return request()->header('backend-role') === 'commercial'; |
| 10 | } |
| 11 | |
| 12 | protected function isCustomerService(): bool |
| 13 | { |
| 14 | return request()->header('backend-role') === 'customer_service'; |
| 15 | } |
| 16 | |
| 17 | /** Write access: commercial yes, customer_service no. */ |
| 18 | protected function canWrite(): bool |
| 19 | { |
| 20 | return !$this->isCustomerService(); |
| 21 | } |
| 22 | |
| 23 | /** Full access: only non-restricted roles (not commercial, not customer_service). */ |
| 24 | protected function canManage(): bool |
| 25 | { |
| 26 | return !$this->isCommercial() && !$this->isCustomerService(); |
| 27 | } |
| 28 | |
| 29 | /** Alias for canManage — restricted operations like delete. */ |
| 30 | protected function canDelete(): bool |
| 31 | { |
| 32 | return $this->canManage(); |
| 33 | } |
| 34 | } |