BalanceTransactionPermissionsController.php
3 years ago
ChargePermissionsController.php
3 years ago
CheckoutPermissionsController.php
3 years ago
CustomerPermissionsController.php
2 years ago
InvoicePermissionsController.php
3 years ago
LicensePermissionsController.php
3 years ago
MediaPermissionsController.php
3 years ago
ModelPermissionsController.php
3 years ago
OrderPermissionsController.php
3 years ago
PaymentMethodPermissionsController.php
3 years ago
PurchasePermissionsController.php
3 years ago
RefundPermissionsController.php
3 years ago
SubscriptionPermissionsController.php
3 years ago
InvoicePermissionsController.php
84 lines
| 1 | <?php |
| 2 | namespace SureCart\Permissions\Models; |
| 3 | |
| 4 | use SureCart\Models\Invoice; |
| 5 | |
| 6 | /** |
| 7 | * Handle various charge permissions. |
| 8 | */ |
| 9 | class InvoicePermissionsController extends ModelPermissionsController { |
| 10 | /** |
| 11 | * Can user edit charge. |
| 12 | * |
| 13 | * @param \SureCart\Models\User $user User model. |
| 14 | * @param array $args { |
| 15 | * Arguments that accompany the requested capability check. |
| 16 | * |
| 17 | * @type string $0 Requested capability. |
| 18 | * @type int $1 Concerned user ID. |
| 19 | * @type mixed ...$2 Optional second and further parameters, typically object ID. |
| 20 | * } |
| 21 | * @param bool[] $allcaps Array of key/value pairs where keys represent a capability name |
| 22 | * and boolean values represent whether the user has that capability. |
| 23 | * @return boolean Does user have permission. |
| 24 | */ |
| 25 | public function edit_sc_invoice( $user, $args, $allcaps ) { |
| 26 | if ( ! empty( $allcaps['edit_sc_invoices'] ) ) { |
| 27 | return true; |
| 28 | } |
| 29 | $invoice = Invoice::find( $args[2] ); |
| 30 | if ( ! $invoice || is_wp_error( $invoice ) ) { |
| 31 | return false; |
| 32 | } |
| 33 | return in_array( $invoice->status, [ 'draft', 'finalized' ] ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Can user read. |
| 38 | * |
| 39 | * @param \SureCart\Models\User $user User model. |
| 40 | * @param array $args { |
| 41 | * Arguments that accompany the requested capability check. |
| 42 | * |
| 43 | * @type string $0 Requested capability. |
| 44 | * @type int $1 Concerned user ID. |
| 45 | * @type mixed ...$2 Optional second and further parameters, typically object ID. |
| 46 | * } |
| 47 | * @param bool[] $allcaps Array of key/value pairs where keys represent a capability name |
| 48 | * and boolean values represent whether the user has that capability. |
| 49 | * @return boolean Does user have permission. |
| 50 | */ |
| 51 | public function read_sc_invoice( $user, $args, $allcaps ) { |
| 52 | if ( ! empty( $allcaps['read_sc_invoices'] ) ) { |
| 53 | return true; |
| 54 | } |
| 55 | $invoice = Invoice::find( $args[2] ); |
| 56 | if ( in_array( $invoice->status, [ 'draft', 'finalized' ] ) ) { |
| 57 | return true; |
| 58 | } |
| 59 | return $this->belongsToUser( Invoice::class, $args[2], $user ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Can user read. |
| 64 | * |
| 65 | * @param \SureCart\Models\User $user User model. |
| 66 | * @param array $args { |
| 67 | * Arguments that accompany the requested capability check. |
| 68 | * |
| 69 | * @type string $0 Requested capability. |
| 70 | * @type int $1 Concerned user ID. |
| 71 | * @type mixed ...$2 Optional second and further parameters, typically object ID. |
| 72 | * } |
| 73 | * @param bool[] $allcaps Array of key/value pairs where keys represent a capability name |
| 74 | * and boolean values represent whether the user has that capability. |
| 75 | * @return boolean Does user have permission. |
| 76 | */ |
| 77 | public function read_sc_invoices( $user, $args, $allcaps ) { |
| 78 | if ( ! empty( $allcaps['read_sc_invoices'] ) ) { |
| 79 | return true; |
| 80 | } |
| 81 | return $this->isListingOwnCustomerIds( $user, $args[2]['customer_ids'] ?? [] ); |
| 82 | } |
| 83 | } |
| 84 |