PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.2.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.2.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Permissions / Models / CheckoutPermissionsController.php
CheckoutPermissionsController.php
93 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace SureCart\Permissions\Models;
3
4 use SureCart\Models\Checkout;
5
6 /**
7 * Handle various charge permissions.
8 */
9 class CheckoutPermissionsController 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_checkout( $user, $args, $allcaps ) {
26 if ( ! empty( $allcaps['edit_sc_checkouts'] ) ) {
27 return true;
28 }
29 $checkout = Checkout::find( $args[2] );
30 if ( ! $checkout || is_wp_error( $checkout ) ) {
31 return false;
32 }
33
34 $params = $args[3] ?? [];
35
36 // If request has some specific keys, then stop.
37 // as only admin can edit some of those fields.
38 if ( $this->requestHasKeys( $params, array( 'tax_behavior' ) ) ) {
39 return false;
40 }
41
42 return in_array( $checkout->status, [ 'draft', 'finalized' ] );
43 }
44
45 /**
46 * Can user read.
47 *
48 * @param \SureCart\Models\User $user User model.
49 * @param array $args {
50 * Arguments that accompany the requested capability check.
51 *
52 * @type string $0 Requested capability.
53 * @type int $1 Concerned user ID.
54 * @type mixed ...$2 Optional second and further parameters, typically object ID.
55 * }
56 * @param bool[] $allcaps Array of key/value pairs where keys represent a capability name
57 * and boolean values represent whether the user has that capability.
58 * @return boolean Does user have permission.
59 */
60 public function read_sc_checkout( $user, $args, $allcaps ) {
61 if ( ! empty( $allcaps['read_sc_checkouts'] ) ) {
62 return true;
63 }
64 $checkout = Checkout::find( $args[2] );
65 if ( in_array( $checkout->status, [ 'draft', 'finalized' ] ) ) {
66 return true;
67 }
68 return $this->belongsToUser( Checkout::class, $args[2], $user );
69 }
70
71 /**
72 * Can user read.
73 *
74 * @param \SureCart\Models\User $user User model.
75 * @param array $args {
76 * Arguments that accompany the requested capability check.
77 *
78 * @type string $0 Requested capability.
79 * @type int $1 Concerned user ID.
80 * @type mixed ...$2 Optional second and further parameters, typically object ID.
81 * }
82 * @param bool[] $allcaps Array of key/value pairs where keys represent a capability name
83 * and boolean values represent whether the user has that capability.
84 * @return boolean Does user have permission.
85 */
86 public function read_sc_checkouts( $user, $args, $allcaps ) {
87 if ( ! empty( $allcaps['read_sc_checkouts'] ) ) {
88 return true;
89 }
90 return $this->isListingOwnCustomerIds( $user, $args[2]['customer_ids'] ?? [] );
91 }
92 }
93