Skip to content

Commit

Permalink
Use seperate permissions for purchase cost field
Browse files Browse the repository at this point in the history
  • Loading branch information
casdr committed Jan 3, 2025
1 parent 96218f7 commit 6f77ef0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Models/SnipeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function getDisplayNameAttribute()
*/
public function getPurchaseCostAttribute($value)
{
if (Auth::check() && !Auth::user()->can('self.view_purchase_cost')) {
if (Auth::check() && !Auth::user()->can('viewPurchaseCost', $this)) {
return null;
}

Expand Down
11 changes: 11 additions & 0 deletions app/Policies/SnipePermissionsPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,15 @@ public function manage(User $user, $item = null)
{
return $user->hasAccess($this->columnName().'.edit');
}

/**
* Determine whether the user can view the purchase cost.
*
* @param \App\Models\User $user
* @return mixed
*/
public function viewPurchaseCost(User $user, $item = null)
{
return $user->hasAccess($this->columnName().'.view.purchase_cost');
}
}
34 changes: 34 additions & 0 deletions config/permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
'display' => true,
],

[
'permission' => 'assets.view.purchase_cost',
'label' => 'View and Modify Purchase Cost',
'note' => '',
'display' => true,
],
],

'Accessories' => [
Expand Down Expand Up @@ -159,6 +165,13 @@
'display' => true,
],

[
'permission' => 'accesories.view.purchase_cost',
'label' => 'View and Modify Purchase Cost',
'note' => '',
'display' => true,
],

],

'Consumables' => [
Expand Down Expand Up @@ -198,6 +211,13 @@
'note' => '',
'display' => true,
],

[
'permission' => 'consumables.view.purchase_cost',
'label' => 'View and Modify Purchase Cost',
'note' => '',
'display' => true,
],
],


Expand Down Expand Up @@ -244,6 +264,13 @@
'note' => '',
'display' => true,
],

[
'permission' => 'licenses.view.purchase_cost',
'label' => 'View and Modify Purchase Cost',
'note' => '',
'display' => true,
],
],


Expand Down Expand Up @@ -291,6 +318,13 @@
'display' => true,
],

[
'permission' => 'components.view.purchase_cost',
'label' => 'View and Modify Purchase Cost',
'note' => '',
'display' => true,
],

],

'Kits' => [
Expand Down

0 comments on commit 6f77ef0

Please sign in to comment.