-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add Traffic Boost permissions infrastructure #2939
Add Traffic Boost permissions infrastructure #2939
Conversation
📝 WalkthroughWalkthroughThe changes in this pull request introduce a new feature called Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (3)
src/class-permissions.php (2)
165-165
: Document the new TrafficBoost feature mapping.The TrafficBoost feature mapping follows the existing pattern and is well-integrated. However, consider updating the class-level PHPDoc to document this new feature.
Add a description of the TrafficBoost feature in the class documentation:
/** * Class implementing user/role permissions functionality. * * @since 3.16.0 * * @phpstan-import-type Parsely_Options_Content_Helper from Parsely * @phpstan-import-type Parsely_Options_Content_Helper_Feature from Parsely + * + * Supported features: + * - SmartLinking: Enables smart linking functionality + * - TitleSuggestions: Provides title suggestions + * - ExcerptSuggestions: Provides excerpt suggestions + * - TrafficBoost: Controls traffic boost functionality */
209-212
: LGTM! Consider improving type hints.The traffic_boost settings implementation follows the existing pattern and maintains consistency with other features.
Consider adding a more specific PHPDoc type for the settings array structure:
/** * @phpstan-type Parsely_Feature_Settings array{ * enabled: bool, * allowed_user_roles: array<int, string> * } * @phpstan-type Parsely_Options_Content_Helper array{ * ai_features_enabled: bool, * smart_linking: Parsely_Feature_Settings, * title_suggestions: Parsely_Feature_Settings, * excerpt_suggestions: Parsely_Feature_Settings, * traffic_boost: Parsely_Feature_Settings * } */tests/Integration/UI/SettingsPageTest.php (1)
753-753
: LGTM! Consider adding a period to the inline comment.The addition of traffic_boost to the content helper options is consistent with the existing pattern and properly implements the permissions infrastructure.
Following WordPress coding standards, consider adding a period to the end of the inline comment:
- $options['content_helper']['traffic_boost']['allowed_user_roles'] = array( 'administrator' => true ); + $options['content_helper']['traffic_boost']['allowed_user_roles'] = array( 'administrator' => true ); // Transform traffic_boost options for validation.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (2)
build/admin-settings.asset.php
is excluded by!build/**
build/admin-settings.js
is excluded by!build/**
📒 Files selected for processing (8)
src/UI/class-dashboard-page.php
(3 hunks)src/UI/class-settings-page.php
(3 hunks)src/class-parsely.php
(2 hunks)src/class-permissions.php
(2 hunks)src/js/admin-settings.ts
(1 hunks)tests/Integration/PermissionsTest.php
(1 hunks)tests/Integration/UI/SettingsPageTest.php
(1 hunks)wp-parsely.php
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
src/UI/class-dashboard-page.php (1)
Pattern **/*.{html,php}
: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/UI/class-settings-page.php (1)
Pattern **/*.{html,php}
: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/class-parsely.php (1)
Pattern **/*.{html,php}
: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/class-permissions.php (1)
Pattern **/*.{html,php}
: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/js/admin-settings.ts (1)
Pattern **/*.{js,ts,tsx,jsx}
: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the code to ensure it is well-structured and adheres to best practices.
- Verify compliance with WordPress coding standards.
- Ensure the code is well-documented.
- Check for security vulnerabilities and confirm the code is secure.
- Optimize the code for performance, removing any unnecessary elements.
- Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
- Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
tests/Integration/PermissionsTest.php (1)
Pattern **/*.{html,php}
: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
tests/Integration/UI/SettingsPageTest.php (1)
Pattern **/*.{html,php}
: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
wp-parsely.php (1)
Pattern **/*.{html,php}
: "Perform a detailed review of the provided code with following key aspects in mind:
- Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
- Ensure the code follows WordPress coding standards and is well-documented.
- Confirm the code is secure and free from vulnerabilities.
- Optimize the code for performance, removing any unnecessary elements.
- Validate comments for accuracy, currency, and adherence to WordPress coding standards.
- Ensure each line comment concludes with a period.
- Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
🔇 Additional comments (10)
wp-parsely.php (2)
112-112
: Verify Dashboard_Page constructor implementation.
Ensure that the Dashboard_Page constructor properly handles the Parsely instance parameter.
#!/bin/bash
# Check Dashboard_Page constructor implementation
ast-grep --pattern 'class Dashboard_Page {
$$$
function __construct($parsely) {
$$$
}
$$$
}'
112-112
: LGTM! Verify backward compatibility.
The update to pass the Parsely instance to Dashboard_Page is correct and aligns with the Traffic Boost permissions infrastructure requirements.
Let's verify backward compatibility with older versions:
✅ Verification successful
No backward compatibility concerns - change is safe
The Dashboard_Page
class has been designed from the start (since version 3.18.0) to require a Parsely
instance in its constructor, and there's only one instantiation of this class in the entire codebase. The change in wp-parsely.php
correctly aligns with the existing constructor signature.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any other instantiations of Dashboard_Page that might need updating
rg "new\s+Dashboard_Page\s*\(" --type php
Length of output: 106
Script:
#!/bin/bash
# Let's try a more comprehensive search for Dashboard_Page instantiation
rg -i "dashboard_page" --type php -A 2 -B 2
# Also search for the class definition to understand constructor
ast-grep --pattern 'class Dashboard_Page {
$$$
function __construct($_) {
$$$
}
$$$
}'
Length of output: 5215
Script:
#!/bin/bash
# Let's check the constructor implementation in Dashboard_Page
rg -A 10 "class Dashboard_Page" src/UI/class-dashboard-page.php
# Also check git history for any recent changes to the constructor
git log -p src/UI/class-dashboard-page.php | rg -A 5 -B 5 "__construct"
Length of output: 940
src/js/admin-settings.ts (1)
72-73
: LGTM: Traffic Boost checkbox selector added correctly.
The addition of the Traffic Boost checkbox selector follows the established pattern and maintains consistency with other feature selectors.
src/UI/class-dashboard-page.php (1)
25-41
: LGTM! Well-structured property and constructor implementation.
The code follows WordPress coding standards with proper type declarations and comprehensive PHPDoc documentation.
tests/Integration/PermissionsTest.php (1)
48-48
: LGTM! Comprehensive test coverage for Traffic Boost permissions.
The addition of 'traffic_boost' to $features_to_test
ensures that the new feature will be automatically tested across all permission scenarios, including:
- Enabled/disabled feature states
- Allowed/disallowed user roles
- Super admin access
- Filter hook behavior
- Invalid configurations
Let's verify the test coverage:
✅ Verification successful
Verified: Traffic Boost feature is thoroughly tested across all permission scenarios
The test coverage is comprehensive as the traffic_boost
feature will be automatically tested in all test methods through the $features_to_test
array:
- Super admin access verification
- Editor role permissions check
- Disabled feature state testing
- Multisite environment handling
- Invalid configuration testing
- Permission denial scenarios
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that all test methods handle the traffic_boost feature
# Test: Search for test methods that will process traffic_boost. Expect: Multiple test methods.
rg -B 2 -A 2 'foreach.*features_to_test' tests/Integration/PermissionsTest.php
Length of output: 902
src/class-parsely.php (2)
56-57
: LGTM: PHPDoc type definition is correct and consistent.
The addition of traffic_boost
to the Parsely_Options_Content_Helper
type definition follows the established pattern and correctly references the Parsely_Options_Content_Helper_Feature
type.
132-135
: LGTM: Option defaults are properly configured.
The addition of traffic_boost
to the content helper options maintains consistency with other features:
- Default enabled state is set to true
- Default user role is set to administrator
- Follows the same structure and indentation as other feature configurations
src/UI/class-settings-page.php (3)
75-75
: LGTM: Type definition addition is consistent and well-documented.
The new traffic_boost
type follows the established pattern for Content Helper features.
122-122
: LGTM: Feature addition is consistent with existing pattern.
The traffic_boost
feature is properly added to the configurable features array.
511-526
: LGTM: Settings field registration is well-implemented.
The Traffic Boost settings field is properly registered with:
- Consistent implementation pattern
- Proper sanitization and escaping
- Internationalization support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I believe we should limit only the "Traffic Boost" functionality if disabled, by removing that submenu item. But we can extend that once we start implementing TB.
Yes, we'll see how we handle TB disablement once we have more elements. |
Description
This PR adds the Traffic Boost permissions infrastructure.
Permissions can be changed in the plugin's settings page, and (to facilitate manual testing) the Traffic Boost enabled status is currently shown in our dashboard page.
Motivation and context
Being able to set permissions for Traffic Boost, like for other PCH features.
How has this been tested?
Screenshots
Summary by CodeRabbit