8 changed files with 151 additions and 6 deletions
-
4app/Http/Controllers/Projects/FeesController.php
-
2app/Http/Controllers/Projects/InvoicesController.php
-
10app/Http/Controllers/Projects/JobsController.php
-
4app/Http/Controllers/Projects/ProjectsController.php
-
69app/Policies/PaymentPolicy.php
-
1app/Providers/AuthServiceProvider.php
-
10resources/views/projects/partials/nav-tabs.blade.php
-
57tests/Unit/Policies/PaymentPolicyTest.php
@ -0,0 +1,69 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Policies; |
||||
|
|
||||
|
use App\Entities\Payments\Payment; |
||||
|
use App\Entities\Users\User; |
||||
|
use Illuminate\Auth\Access\HandlesAuthorization; |
||||
|
|
||||
|
/** |
||||
|
* Payment model policy class. |
||||
|
* |
||||
|
* @author Nafies Luthfi <nafiesL@gmail.com> |
||||
|
*/ |
||||
|
class PaymentPolicy |
||||
|
{ |
||||
|
use HandlesAuthorization; |
||||
|
|
||||
|
/** |
||||
|
* Determine whether the user can view the payment. |
||||
|
* |
||||
|
* @param \App\Entities\Users\User $user |
||||
|
* @param \App\Entities\Partners\Payment $payment |
||||
|
* |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function view(User $user, Payment $payment) |
||||
|
{ |
||||
|
return $user->hasRole('admin'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Determine whether the user can create payments. |
||||
|
* |
||||
|
* @param \App\Entities\Users\User $user |
||||
|
* @param \App\Entities\Partners\Payment $payment |
||||
|
* |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function create(User $user, Payment $payment) |
||||
|
{ |
||||
|
return $user->hasRole('admin'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Determine whether the user can update the payment. |
||||
|
* |
||||
|
* @param \App\Entities\Users\User $user |
||||
|
* @param \App\Entities\Partners\Payment $payment |
||||
|
* |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function update(User $user, Payment $payment) |
||||
|
{ |
||||
|
return $this->view($user, $payment); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Determine whether the user can delete the payment. |
||||
|
* |
||||
|
* @param \App\Entities\Users\User $user |
||||
|
* @param \App\Entities\Partners\Payment $payment |
||||
|
* |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function delete(User $user, Payment $payment) |
||||
|
{ |
||||
|
return $this->view($user, $payment); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Unit\Policies; |
||||
|
|
||||
|
use App\Entities\Payments\Payment; |
||||
|
use Tests\TestCase as TestCase; |
||||
|
|
||||
|
/** |
||||
|
* Payment Policy Test. |
||||
|
* |
||||
|
* @author Nafies Luthfi <nafiesl@gmail.com> |
||||
|
*/ |
||||
|
class PaymentPolicyTest extends TestCase |
||||
|
{ |
||||
|
/** @test */ |
||||
|
public function only_admin_can_create_payment() |
||||
|
{ |
||||
|
$admin = $this->createUser('admin'); |
||||
|
$this->assertTrue($admin->can('create', new Payment())); |
||||
|
|
||||
|
$worker = $this->createUser('worker'); |
||||
|
$this->assertFalse($worker->can('create', new Payment())); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function only_admin_can_view_payment() |
||||
|
{ |
||||
|
$admin = $this->createUser('admin'); |
||||
|
$worker = $this->createUser('worker'); |
||||
|
$payment = factory(Payment::class)->create(); |
||||
|
|
||||
|
$this->assertTrue($admin->can('view', $payment)); |
||||
|
$this->assertFalse($worker->can('view', $payment)); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function only_admin_can_update_payment() |
||||
|
{ |
||||
|
$admin = $this->createUser('admin'); |
||||
|
$worker = $this->createUser('worker'); |
||||
|
$payment = factory(Payment::class)->create(); |
||||
|
|
||||
|
$this->assertTrue($admin->can('update', $payment)); |
||||
|
$this->assertFalse($worker->can('update', $payment)); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function only_admin_can_delete_payment() |
||||
|
{ |
||||
|
$admin = $this->createUser('admin'); |
||||
|
$worker = $this->createUser('worker'); |
||||
|
$payment = factory(Payment::class)->create(); |
||||
|
|
||||
|
$this->assertTrue($admin->can('delete', $payment)); |
||||
|
$this->assertFalse($worker->can('delete', $payment)); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue