Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing args for several endpoints in the Stores API endpoints #2442

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions includes/REST/StoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,133 @@
'methods' => WP_REST_Server::CREATABLE,
'callback' => [ $this, 'create_store' ],
'permission_callback' => [ $this, 'permission_check_for_manageable_part' ],
'args' => [
'user_login' => [
'required' => false,
'type' => 'string',
'description' => __( 'The username for the store owner. If not provided, it will be auto-generated.', 'dokan-lite' ),
],
Comment on lines +56 to +60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation constraints for user_login field.

The user_login field should include validation to ensure it meets WordPress username requirements.

Apply this diff:

                        'user_login' => [
                            'required'    => false,
                            'type'        => 'string',
                            'description' => __( 'The username for the store owner. If not provided, it will be auto-generated.', 'dokan-lite' ),
+                            'pattern'     => '^[a-zA-Z0-9_]{3,}$',
+                            'minLength'   => 3,
+                            'maxLength'   => 60,
                        ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'user_login' => [
'required' => false,
'type' => 'string',
'description' => __( 'The username for the store owner. If not provided, it will be auto-generated.', 'dokan-lite' ),
],
'user_login' => [
'required' => false,
'type' => 'string',
'description' => __( 'The username for the store owner. If not provided, it will be auto-generated.', 'dokan-lite' ),
'pattern' => '^[a-zA-Z0-9_]{3,}$',
'minLength' => 3,
'maxLength' => 60,
],

'email' => [
'required' => true,
'type' => 'string',
'format' => 'email',
'description' => __( 'The email address for the store owner.', 'dokan-lite' ),
],
'store_name' => [
'required' => true,
'type' => 'string',
'description' => __( 'The name of the store.', 'dokan-lite' ),
],
Comment on lines +67 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation constraints for store_name field

The store_name field should include length and character constraints to ensure valid store names.

         'store_name' => [
             'required'    => true,
             'type'        => 'string',
             'description' => __( 'The name of the store.', 'dokan-lite' ),
+            'minLength'   => 1,
+            'maxLength'   => 100,
+            'pattern'     => '^[a-zA-Z0-9\s\-\_\.]+$'
         ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'store_name' => [
'required' => true,
'type' => 'string',
'description' => __( 'The name of the store.', 'dokan-lite' ),
],
'store_name' => [
'required' => true,
'type' => 'string',
'description' => __( 'The name of the store.', 'dokan-lite' ),
'minLength' => 1,
'maxLength' => 100,
'pattern' => '^[a-zA-Z0-9\s\-\_\.]+$'
],

'social' => [
'required' => false,
'type' => 'array',
'items' => [
'type' => 'string',
],
'description' => __( 'An array of social media details for the store.', 'dokan-lite' ),
],
'payment' => [
'required' => false,
'type' => 'object',
'properties' => array(
'paypal' => array(
'type' => 'array',
'items' => array(
'type' => 'string',
)

Check failure on line 88 in includes/REST/StoreController.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

There should be a comma after the last array item in a multi-line array.
),
'bank' => array(
'type' => 'array',
'items' => array(
'type' => 'string',
)

Check failure on line 94 in includes/REST/StoreController.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

There should be a comma after the last array item in a multi-line array.
)

Check failure on line 95 in includes/REST/StoreController.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

There should be a comma after the last array item in a multi-line array.
),
'description' => __( 'Payment details for the store. E.g., PayPal or bank details.', 'dokan-lite' ),
],
Comment on lines +80 to +98
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve payment schema validation.

The payment schema needs better structure validation and constraints.

Apply this diff to improve the schema:

         'payment' => [
             'required'    => false,
-            'type'        => 'object',
-            'properties'  => array(
-                'paypal' => array(
-                    'type' => 'array',
-                    'items' => array(
-                        'type' => 'string',
-                    )
-                ),
-                'bank' => array(
-                    'type' => 'array',
-                    'items' => array(
-                        'type' => 'string',
-                    )
-                )
-            ),
+            'type'        => 'object',
+            'properties'  => [
+                'paypal' => [
+                    'type'       => 'object',
+                    'properties' => [
+                        'email' => [
+                            'type'        => 'string',
+                            'format'      => 'email',
+                            'description' => __( 'PayPal email address', 'dokan-lite' ),
+                        ],
+                    ],
+                    'required' => ['email'],
+                ],
+                'bank' => [
+                    'type'       => 'object',
+                    'properties' => [
+                        'ac_name' => [
+                            'type'        => 'string',
+                            'description' => __( 'Account name', 'dokan-lite' ),
+                        ],
+                        'ac_number' => [
+                            'type'        => 'string',
+                            'description' => __( 'Account number', 'dokan-lite' ),
+                        ],
+                        'bank_name' => [
+                            'type'        => 'string',
+                            'description' => __( 'Bank name', 'dokan-lite' ),
+                        ],
+                    ],
+                    'required' => ['ac_name', 'ac_number', 'bank_name'],
+                ],
+            ],
             'description' => __( 'Payment details for the store. E.g., PayPal or bank details.', 'dokan-lite' ),
         ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'payment' => [
'required' => false,
'type' => 'object',
'properties' => array(
'paypal' => array(
'type' => 'array',
'items' => array(
'type' => 'string',
)
),
'bank' => array(
'type' => 'array',
'items' => array(
'type' => 'string',
)
)
),
'description' => __( 'Payment details for the store. E.g., PayPal or bank details.', 'dokan-lite' ),
],
'payment' => [
'required' => false,
'type' => 'object',
'properties' => [
'paypal' => [
'type' => 'object',
'properties' => [
'email' => [
'type' => 'string',
'format' => 'email',
'description' => __( 'PayPal email address', 'dokan-lite' ),
],
],
'required' => ['email'],
],
'bank' => [
'type' => 'object',
'properties' => [
'ac_name' => [
'type' => 'string',
'description' => __( 'Account name', 'dokan-lite' ),
],
'ac_number' => [
'type' => 'string',
'description' => __( 'Account number', 'dokan-lite' ),
],
'bank_name' => [
'type' => 'string',
'description' => __( 'Bank name', 'dokan-lite' ),
],
],
'required' => ['ac_name', 'ac_number', 'bank_name'],
],
],
'description' => __( 'Payment details for the store. E.g., PayPal or bank details.', 'dokan-lite' ),
],
🧰 Tools
🪛 GitHub Check: Run PHPCS inspection

[failure] 88-88:
There should be a comma after the last array item in a multi-line array.


[failure] 94-94:
There should be a comma after the last array item in a multi-line array.


[failure] 95-95:
There should be a comma after the last array item in a multi-line array.

'phone' => [
'required' => false,
'type' => 'string',
'description' => __( 'The contact phone number for the store.', 'dokan-lite' ),
],
Comment on lines +99 to +103
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add phone number format validation

The phone field should include format validation to ensure valid phone numbers are provided.

Add format validation:

         'phone' => [
             'required'    => false,
             'type'        => 'string',
             'description' => __( 'The contact phone number for the store.', 'dokan-lite' ),
+            'pattern'     => '^\+?[1-9]\d{1,14}$',
+            'minLength'   => 10,
+            'maxLength'   => 15
         ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'phone' => [
'required' => false,
'type' => 'string',
'description' => __( 'The contact phone number for the store.', 'dokan-lite' ),
],
'phone' => [
'required' => false,
'type' => 'string',
'description' => __( 'The contact phone number for the store.', 'dokan-lite' ),
'pattern' => '^\+?[1-9]\d{1,14}$',
'minLength' => 10,
'maxLength' => 15
],

'show_email' => [
'required' => false,
'type' => 'string',
'description' => __( 'Whether to show the store email publicly.', 'dokan-lite' ),
],
'address' => [
'required' => false,
'type' => 'array',
'items' => [
'type' => 'string'

Check failure on line 113 in includes/REST/StoreController.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

There should be a comma after the last array item in a multi-line array.
],
'description' => __( 'Address details of the store.', 'dokan-lite' ),
],
'location' => [
'required' => false,
'type' => 'string',
'description' => __( 'Geographical location of the store.', 'dokan-lite' ),
],
'banner_id' => [
'required' => false,
'type' => 'integer',
'description' => __( 'ID of the banner image for the store.', 'dokan-lite' ),
],
'icon' => [
'required' => false,
'type' => 'string',
'description' => __( 'URL of the icon image for the store.', 'dokan-lite' ),
],
'gravatar_id' => [
'required' => false,
'type' => 'integer',
'description' => __( 'ID of the gravatar image for the store.', 'dokan-lite' ),
],
'enable_tnc' => [
'required' => false,
'type' => 'string',
'description' => __( 'Enable Terms and Conditions for the store.', 'dokan-lite' ),
],
'store_tnc' => [
'required' => false,
'type' => 'string',
'description' => __( 'Terms and Conditions text for the store.', 'dokan-lite' ),
],
'show_min_order_discount' => [
'required' => false,
'type' => 'string',
'description' => __( 'Whether to show minimum order discount information.', 'dokan-lite' ),
],
'store_seo' => [
'required' => false,
'type' => 'array',
'items' => [
'type' => 'string'

Check failure on line 156 in includes/REST/StoreController.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

There should be a comma after the last array item in a multi-line array.
],
'description' => __( 'SEO metadata for the store.', 'dokan-lite' ),
],
'store_open_close' => [
'required' => false,
'type' => 'array',
'items' => array(
'type' => 'object',
'properties' => array(
'day' => array(
'type' => 'array',
'items' => array(
'type' => 'string',
)

Check failure on line 170 in includes/REST/StoreController.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

There should be a comma after the last array item in a multi-line array.
)

Check failure on line 171 in includes/REST/StoreController.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

There should be a comma after the last array item in a multi-line array.
)

Check failure on line 172 in includes/REST/StoreController.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

There should be a comma after the last array item in a multi-line array.
),
'description' => __( 'Opening and closing times for the store.', 'dokan-lite' ),
],
'notify_vendor' => [
'required' => false,
'type' => 'boolean',
'description' => __( 'Whether to notify the vendor after creation.', 'dokan-lite' ),
],
],
],
]
);
Expand Down Expand Up @@ -131,6 +258,24 @@
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'check_store_availability' ],
'permission_callback' => '__return_true',
'args' => [
'store_slug' => [
'required' => false,
'type' => 'string',
'description' => __( 'Slug of the store to check availability.', 'dokan-lite' ),
],
'username' => [
'required' => false,
'type' => 'string',
'description' => __( 'Username to check availability.', 'dokan-lite' ),
],
Comment on lines +262 to +271
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add pattern validation for store_slug and username

The store_slug and username fields should include pattern validation to ensure they meet WordPress naming conventions.

Add pattern validation:

         'store_slug' => [
             'required' => false,
             'type' => 'string',
             'description' => __( 'Slug of the store to check availability.', 'dokan-lite' ),
+            'pattern' => '^[a-zA-Z0-9-_]+$',
+            'minLength' => 3,
+            'maxLength' => 50
         ],
         'username' => [
             'required' => false,
             'type' => 'string',
             'description' => __( 'Username to check availability.', 'dokan-lite' ),
+            'pattern' => '^[a-zA-Z0-9-_]+$',
+            'minLength' => 3,
+            'maxLength' => 50
         ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'store_slug' => [
'required' => false,
'type' => 'string',
'description' => __( 'Slug of the store to check availability.', 'dokan-lite' ),
],
'username' => [
'required' => false,
'type' => 'string',
'description' => __( 'Username to check availability.', 'dokan-lite' ),
],
'store_slug' => [
'required' => false,
'type' => 'string',
'description' => __( 'Slug of the store to check availability.', 'dokan-lite' ),
'pattern' => '^[a-zA-Z0-9-_]+$',
'minLength' => 3,
'maxLength' => 50
],
'username' => [
'required' => false,
'type' => 'string',
'description' => __( 'Username to check availability.', 'dokan-lite' ),
'pattern' => '^[a-zA-Z0-9-_]+$',
'minLength' => 3,
'maxLength' => 50
],

'email' => [
'required' => false,
'type' => 'string',
'description' => __( 'Email address to check availability.', 'dokan-lite' ),
'format' => 'email',
],
],
],
]
);
Expand Down Expand Up @@ -197,6 +342,32 @@
'methods' => WP_REST_Server::EDITABLE,
'callback' => [ $this, 'batch_update' ],
'permission_callback' => [ $this, 'permission_check_for_manageable_part' ],
'args' => [
'approved' => [
'type' => 'array',
'required' => false,
'items' => [
'type' => 'integer',
],
'description' => __( 'List of vendor IDs to approve.', 'dokan-lite' ),
],
'pending' => [
'type' => 'array',
'required' => false,
'items' => [
'type' => 'integer',
],
'description' => __( 'List of vendor IDs to set as pending.', 'dokan-lite' ),
],
'delete' => [
'type' => 'array',
'required' => false,
'items' => [
'type' => 'integer',
],
'description' => __( 'List of vendor IDs to delete.', 'dokan-lite' ),
],
],
Comment on lines +345 to +370
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add size limits for batch operations

The batch operation arrays should have size limits to prevent performance issues with large batches.

         'args'                => [
             'approved' => [
                 'type'        => 'array',
                 'required'    => false,
                 'items'       => [
                     'type' => 'integer',
                 ],
                 'description' => __( 'List of vendor IDs to approve.', 'dokan-lite' ),
+                'maxItems'    => 100,
             ],
             'pending'  => [
                 'type'        => 'array',
                 'required'    => false,
                 'items'       => [
                     'type' => 'integer',
                 ],
                 'description' => __( 'List of vendor IDs to set as pending.', 'dokan-lite' ),
+                'maxItems'    => 100,
             ],
             'delete'   => [
                 'type'        => 'array',
                 'required'    => false,
                 'items'       => [
                     'type' => 'integer',
                 ],
                 'description' => __( 'List of vendor IDs to delete.', 'dokan-lite' ),
+                'maxItems'    => 100,
             ],
         ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'args' => [
'approved' => [
'type' => 'array',
'required' => false,
'items' => [
'type' => 'integer',
],
'description' => __( 'List of vendor IDs to approve.', 'dokan-lite' ),
],
'pending' => [
'type' => 'array',
'required' => false,
'items' => [
'type' => 'integer',
],
'description' => __( 'List of vendor IDs to set as pending.', 'dokan-lite' ),
],
'delete' => [
'type' => 'array',
'required' => false,
'items' => [
'type' => 'integer',
],
'description' => __( 'List of vendor IDs to delete.', 'dokan-lite' ),
],
],
'args' => [
'approved' => [
'type' => 'array',
'required' => false,
'items' => [
'type' => 'integer',
],
'description' => __( 'List of vendor IDs to approve.', 'dokan-lite' ),
'maxItems' => 100,
],
'pending' => [
'type' => 'array',
'required' => false,
'items' => [
'type' => 'integer',
],
'description' => __( 'List of vendor IDs to set as pending.', 'dokan-lite' ),
'maxItems' => 100,
],
'delete' => [
'type' => 'array',
'required' => false,
'items' => [
'type' => 'integer',
],
'description' => __( 'List of vendor IDs to delete.', 'dokan-lite' ),
'maxItems' => 100,
],
],

],
]
);
Expand Down Expand Up @@ -438,7 +609,7 @@
*
* @return array Links for the given post.
*/
protected function prepare_links( $object, $request ) {

Check warning on line 612 in includes/REST/StoreController.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

It is recommended not to use reserved keyword "object" as function parameter name. Found: $object
$links = [
'self' => [
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->base, $object['id'] ) ),
Expand Down
Loading