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: Prevented store URL generation for staff managers on admin dashboard #2505

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

devAsadNur
Copy link
Member

@devAsadNur devAsadNur commented Jan 8, 2025

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

  • Full PR Link

Closes

How to test the changes in this Pull Request:

Changelog entry

fix: Prevented store URL generation for staff managers on admin dashboard

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • Bug Fixes
    • Improved user profile visibility controls by restricting "Store URL" field display based on user permissions.
    • Updated output method for banner upload instructions for better formatting.

@devAsadNur devAsadNur added Needs: Testing This requires further testing Needs: Dev Review It requires a developer review and approval labels Jan 8, 2025
@devAsadNur devAsadNur self-assigned this Jan 8, 2025
Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Walkthrough

The pull request modifies the UserProfile class to conditionally display the "Store URL" field based on user capabilities. Specifically, the change ensures that users with the 'vendor_staff' capability will not see the Store URL field in their profile, addressing a potential confusion point for staff managers who should not have individual store URLs.

Changes

File Change Summary
includes/Admin/UserProfile.php Added conditional check to hide "Store URL" field for users with 'vendor_staff' capability; changed output method for banner upload instructions from echo to printf.

Assessment against linked issues

Objective Addressed Explanation
Prevent Store URL Generation for Staff Managers [#4056]

Possibly related PRs

Suggested labels

QA approved, :+1: Dev Review Done

Suggested reviewers

  • mrabbani

Poem

🐰 A rabbit's tale of code so neat,
Where staff URLs meet their discreet defeat.
No more confusion, no 404 in sight,
User permissions now shine so bright!
Dokan's magic, with wisdom refined 🔧


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f81de1 and 0d49caf.

📒 Files selected for processing (1)
  • includes/Admin/UserProfile.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/Admin/UserProfile.php
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: api tests (1, 1)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devAsadNur devAsadNur requested a review from mrabbani January 8, 2025 09:57
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
includes/Admin/UserProfile.php (1)

Line range hint 89-95: Optimize string formatting using printf.

Replace echo sprintf() with printf() to improve code efficiency and address the pipeline failure.

-                                    echo sprintf(
+                                    printf(
                                        /* translators: %1$s: banner width, %2$s: banner height in integers */
                                        esc_attr__( 'Upload a banner for your store. Banner size is (%1$sx%2$s) pixels.', 'dokan-lite' ),
                                        esc_attr( $banner_width ),
                                        esc_attr( $banner_height )
                                    );
🧰 Tools
🪛 GitHub Actions: Inspections

[error] Unnecessary "echo sprintf(...)" found. Use "printf(...)" instead.

🧹 Nitpick comments (1)
includes/Admin/UserProfile.php (1)

Line range hint 385-516: Consider architectural improvements for better maintainability and security.

  1. Move the inline JavaScript to a separate file and enqueue it properly using WordPress's wp_enqueue_script().
  2. Add additional security checks for file uploads, including file type validation.
  3. Consider implementing rate limiting for the AJAX URL validation endpoint.

Example of moving the JavaScript to a separate file:

+ // In a new file: assets/js/admin-user-profile.js
+ (function($) {
+     var Dokan_Settings = {
+         // ... existing JavaScript code ...
+     };
+     $(document).ready(function() {
+         Dokan_Settings.init();
+         // ... rest of the JavaScript code ...
+     });
+ })(jQuery);

- <script type="text/javascript">
- jQuery(function($){
-     // ... existing JavaScript code ...
- });
- </script>

Then enqueue it in the enqueue_scripts method:

wp_enqueue_script(
    'dokan-admin-user-profile',
    DOKAN_PLUGIN_ASSEST . '/js/admin-user-profile.js',
    array('jquery'),
    DOKAN_PLUGIN_VERSION,
    true
);
🧰 Tools
🪛 GitHub Actions: Inspections

[error] Unnecessary "echo sprintf(...)" found. Use "printf(...)" instead.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8217a61 and 3f81de1.

📒 Files selected for processing (1)
  • includes/Admin/UserProfile.php (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Inspections
includes/Admin/UserProfile.php

[error] Unnecessary "echo sprintf(...)" found. Use "printf(...)" instead.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: api tests (1, 1)
  • GitHub Check: e2e tests (1, 3)
🔇 Additional comments (1)
includes/Admin/UserProfile.php (1)

137-145: LGTM! Clean implementation of the staff manager restriction.

The conditional check effectively prevents store URL generation for staff managers while maintaining proper escaping and following WordPress coding standards.

🧰 Tools
🪛 GitHub Actions: Inspections

[error] Unnecessary "echo sprintf(...)" found. Use "printf(...)" instead.

Comment on lines +137 to +145
<?php if ( ! user_can( $user, 'vendor_staff' ) ) : ?>
<tr>
<th><?php esc_html_e( 'Store URL', 'dokan-lite' ); ?></th>
<td>
<input type="text" name="dokan_store_url" data-vendor="<?php echo esc_attr( $user->ID ); ?>" class="regular-text" id="seller-url" value="<?php echo esc_attr( $user->data->user_nicename ); ?>"><strong id="url-alart-mgs"></strong>
<p><small><?php echo esc_url( home_url() . '/' . dokan_get_option( 'custom_store_url', 'dokan_general', 'store' ) ); ?>/<strong id="url-alart"><?php echo esc_attr( $user->data->user_nicename ); ?></strong></small></p>
</td>
</tr>
<?php endif; ?>
Copy link
Member

Choose a reason for hiding this comment

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

Pls remove the if condition and generate the url for vendor using dokan_get_current_user_id()

$vendor =  new WP_User( dokan_get_current_user_id() );

Now use $vendor instead of $user to generate the URL.

@mrabbani mrabbani added Needs: Author Reply and removed Needs: Dev Review It requires a developer review and approval labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Author Reply Needs: Testing This requires further testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants