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

Socoladaica #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Socoladaica #1

wants to merge 6 commits into from

Conversation

SocolaDaiCa
Copy link
Collaborator

@SocolaDaiCa SocolaDaiCa commented May 6, 2023

Summary by CodeRabbit

  • New Features

    • Added dynamic host references in various URLs and templates using the packagist_host variable for better configuration flexibility.
  • Bug Fixes

    • Enhanced SQL query conditions in package command to handle NULL values.
  • Improvements

    • Updated authorization logic for package actions.
    • Introduced additional user roles for better permission management.
    • Improved command execution handling in the API controller.
    • Updated email templates to reflect the new host dynamically.
  • Style

    • Updated template strings for consistent organization references.
  • Refactor

    • Simplified control flow in package updater methods.

@SocolaDaiCa SocolaDaiCa force-pushed the socoladaica branch 2 times, most recently from f3ef3dc to 70bc072 Compare May 24, 2023 05:54
@SocolaDaiCa SocolaDaiCa force-pushed the socoladaica branch 6 times, most recently from 81b4f99 to 03460c2 Compare August 23, 2023 04:40
Copy link

coderabbitai bot commented Jul 11, 2024

Walkthrough

The recent updates enhance configuration settings, security features, and code efficiency across the application. Key changes include improved routing context settings, refined SQL query conditions, and enhanced API authorization scopes. Dynamic URL references have been introduced in templates, promoting adaptability. Furthermore, user roles have been expanded, and process handling has been streamlined, all contributing to a more robust and flexible system.

Changes

Files/Paths Change Summaries
config/services.yaml Added router.request_context.host and router.request_context.scheme configurations.
src/Command/DumpPackagesCommand.php Modified SQL query to check for NULL values in the download table fields.
src/Controller/ApiController.php Added use statements for Symfony Console and Process classes; implemented new process handling.
src/Controller/GitHubLoginController.php Added scopes ('repo' and 'admin:org') to connect and login methods.
src/Controller/PackageController.php Commented out access denial checks affecting package management methods (delete, create, edit).
src/Entity/SecurityAdvisory.php Updated PACKAGIST_ORG constant URL to https://packagist.socoladaica.com.
src/Entity/User.php Enhanced getRoles method with new roles; updated User-Agent in the getGithubUsername method.
src/Package/SymlinkDumper.php Modified the info key value within a JSON decode call.
src/Package/Updater.php Commented out conditional checks in updateInformation method.
src/Service/GitHubUserMigrationWorker.php Updated HOOK_URL and HOOK_URL_ALT constants to new domain.
templates/... Updated URLs to use dynamic {{ packagist_host }} references across various templates.

Poem

Beneath the code, the changes flow,
New roles and URLs now bestow.
🐰 A bunny hops with joyful cheer,
For flexible links and hosts so clear.
With scopes and checks, we rise and grow,
In Packagist's garden, updates glow. 🌼


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Copy link

@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: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1a4648c and a408642.

Files selected for processing (19)
  • config/services.yaml (1 hunks)
  • src/Command/DumpPackagesCommand.php (1 hunks)
  • src/Controller/ApiController.php (2 hunks)
  • src/Controller/GitHubLoginController.php (2 hunks)
  • src/Controller/PackageController.php (7 hunks)
  • src/Entity/User.php (1 hunks)
  • src/Package/SymlinkDumper.php (1 hunks)
  • src/Package/Updater.php (1 hunks)
  • src/Service/UpdaterWorker.php (1 hunks)
  • templates/about/about.html.twig (4 hunks)
  • templates/api_doc/index.html.twig (2 hunks)
  • templates/email/update_failed.txt.twig (1 hunks)
  • templates/layout.html.twig (1 hunks)
  • templates/mirrors/index.html.twig (1 hunks)
  • templates/package/submit_package.html.twig (1 hunks)
  • templates/registration/confirmation_email.html.twig (1 hunks)
  • templates/registration/confirmation_email.txt.twig (1 hunks)
  • templates/reset_password/email.txt.twig (1 hunks)
  • templates/web/index.html.twig (1 hunks)
Files skipped from review due to trivial changes (10)
  • src/Command/DumpPackagesCommand.php
  • templates/api_doc/index.html.twig
  • templates/email/update_failed.txt.twig
  • templates/layout.html.twig
  • templates/mirrors/index.html.twig
  • templates/package/submit_package.html.twig
  • templates/registration/confirmation_email.html.twig
  • templates/registration/confirmation_email.txt.twig
  • templates/reset_password/email.txt.twig
  • templates/web/index.html.twig
Additional comments not posted (8)
config/services.yaml (1)

16-17: Enhance routing capabilities with new parameters.

The new parameters router.request_context.host and router.request_context.scheme are added correctly to enhance routing capabilities. Ensure that %env(APP_HOSTNAME)% is properly set in the environment variables.

src/Controller/GitHubLoginController.php (1)

47-47: Verify the added scopes for GitHub OAuth.

The additional scopes 'repo' and 'admin:org' provide extensive access to the user's repositories and organization administration. Ensure that these permissions are necessary and inform users about the permissions being requested.

Also applies to: 63-63

templates/about/about.html.twig (1)

6-6: Implement dynamic host references correctly.

The dynamic host references using the packagist_host variable are implemented correctly. Ensure that the packagist_host variable is properly set and sanitized to prevent security issues such as host header injection.

Also applies to: 108-108, 110-110, 116-116, 125-125, 131-131, 142-142, 144-144

src/Entity/User.php (1)

389-395: Ensure the added roles are correctly implemented.

The additional roles such as 'ROLE_ADMIN', 'ROLE_DELETE_PACKAGES', 'ROLE_EDIT_PACKAGES', 'ROLE_SUPERADMIN', and 'ROLE_UPDATE_PACKAGES' are correctly added to the getRoles function. Verify their usage and ensure that proper authorization checks are in place.

Verification successful

The roles are correctly implemented and used for authorization checks.

The following files have been verified for the usage of the roles 'ROLE_ADMIN', 'ROLE_DELETE_PACKAGES', 'ROLE_EDIT_PACKAGES', 'ROLE_SUPERADMIN', 'ROLE_UPDATE_PACKAGES':

  • src/Validator/PopularPackageSafetyValidator.php
  • src/DataFixtures/UserFixtures.php
  • src/Security/Voter/PackageVoter.php
  • src/Controller/UserController.php
  • src/Controller/ProfileController.php
  • src/Controller/ApiController.php
  • src/Controller/PackageController.php

Each role is checked using proper authorization methods.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the added roles in the codebase.

# Test: Search for the usage of the added roles. Expect: Proper authorization checks.
rg --type php -A 5 $'ROLE_ADMIN|ROLE_DELETE_PACKAGES|ROLE_EDIT_PACKAGES|ROLE_SUPERADMIN|ROLE_UPDATE_PACKAGES'

Length of output: 6508

src/Service/UpdaterWorker.php (1)

120-122: Verify the impact of commenting out these lines.

Commenting out these lines removes the check that skips processing for a specific maintainer. Ensure this change is intentional and does not affect the overall logic.

src/Controller/ApiController.php (1)

449-457: LGTM! The new process execution and error handling are well-implemented.

The added lines for running the packagist:dump-v2 command and checking its success are clear and include proper error handling.

src/Package/Updater.php (1)

439-443: Verify the impact of commenting out these lines.

Commenting out these lines removes the conditional checks for version constraints. Ensure this change is intentional and does not affect the overall logic.

src/Package/SymlinkDumper.php (1)

320-320: Update string value in json_decode call.

The string value within the json_decode call has been updated to reflect a new message. This change is straightforward and does not affect the logic or functionality of the method.

@@ -705,7 +705,7 @@ public function deletePackageVersionAction(Request $req, int $versionId, #[Curre
}
$package = $version->getPackage();

$this->denyAccessUnlessGranted(PackageActions::DeleteVersion->value, $package, 'No permission to delete versions');
// $this->denyAccessUnlessGranted(PackageActions::DeleteVersion->value, $package, 'No permission to delete versions');
Copy link

Choose a reason for hiding this comment

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

Potential Security Risk: Unauthorized Access

Commenting out the access control check may allow unauthorized users to delete versions. Ensure this is intentional and consider adding alternative security measures if needed.

@@ -787,7 +787,7 @@ public function deletePackageAction(Request $req, string $name): Response
return $package;
}

$this->denyAccessUnlessGranted(PackageActions::Delete->value, $package);
// $this->denyAccessUnlessGranted(PackageActions::Delete->value, $package);
Copy link

Choose a reason for hiding this comment

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

Potential Security Risk: Unauthorized Access

Commenting out the access control check may allow unauthorized users to delete packages. Ensure this is intentional and consider adding alternative security measures if needed.

@@ -807,7 +807,7 @@ public function deletePackageAction(Request $req, string $name): Response
#[Route(path: '/packages/{name}/maintainers/', name: 'add_maintainer', requirements: ['name' => '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+'])]
public function createMaintainerAction(Request $req, #[MapEntity] Package $package, LoggerInterface $logger): RedirectResponse
{
$this->denyAccessUnlessGranted(PackageActions::AddMaintainer->value, $package);
// $this->denyAccessUnlessGranted(PackageActions::AddMaintainer->value, $package);
Copy link

Choose a reason for hiding this comment

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

Potential Security Risk: Unauthorized Access

Commenting out the access control check may allow unauthorized users to add maintainers. Ensure this is intentional and consider adding alternative security measures if needed.

@@ -844,7 +844,7 @@ public function createMaintainerAction(Request $req, #[MapEntity] Package $packa
#[Route(path: '/packages/{name}/maintainers/delete', name: 'remove_maintainer', requirements: ['name' => '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+'])]
public function removeMaintainerAction(Request $req, #[MapEntity] Package $package, LoggerInterface $logger): Response
{
$this->denyAccessUnlessGranted(PackageActions::RemoveMaintainer->value, $package);
// $this->denyAccessUnlessGranted(PackageActions::RemoveMaintainer->value, $package);
Copy link

Choose a reason for hiding this comment

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

Potential Security Risk: Unauthorized Access

Commenting out the access control check may allow unauthorized users to remove maintainers. Ensure this is intentional and consider adding alternative security measures if needed.

@@ -887,7 +887,7 @@ public function removeMaintainerAction(Request $req, #[MapEntity] Package $packa
#[Route(path: '/packages/{name}/edit', name: 'edit_package', requirements: ['name' => '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?'])]
public function editAction(Request $req, #[MapEntity] Package $package, #[CurrentUser] ?User $user = null): Response
{
$this->denyAccessUnlessGranted(PackageActions::Edit->value, $package);
// $this->denyAccessUnlessGranted(PackageActions::Edit->value, $package);
Copy link

Choose a reason for hiding this comment

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

Potential Security Risk: Unauthorized Access

Commenting out the access control check may allow unauthorized users to edit packages. Ensure this is intentional and consider adding alternative security measures if needed.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a408642 and 91cca47.

Files selected for processing (6)
  • README.md (1 hunks)
  • src/Entity/SecurityAdvisory.php (1 hunks)
  • src/Entity/User.php (2 hunks)
  • src/Service/GitHubUserMigrationWorker.php (1 hunks)
  • src/Validator/CopyrightValidator.php (1 hunks)
  • src/Validator/VendorWritableValidator.php (1 hunks)
Files skipped from review due to trivial changes (3)
  • README.md
  • src/Validator/CopyrightValidator.php
  • src/Validator/VendorWritableValidator.php
Additional comments not posted (4)
src/Entity/SecurityAdvisory.php (1)

33-33: Verify the usage of the updated constant PACKAGIST_ORG across the codebase.

Ensure that all references to this constant are updated to reflect the new URL.

Verification successful

The updated constant PACKAGIST_ORG is used correctly across the codebase.

  • tests/SecurityAdvisory/RemoteSecurityAdvisoryTest.php
  • tests/SecurityAdvisory/GitHubSecurityAdvisoriesSourceTest.php
  • src/SecurityAdvisory/RemoteSecurityAdvisory.php
  • src/SecurityAdvisory/GitHubSecurityAdvisoriesSource.php
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to the updated constant `PACKAGIST_ORG`.

# Test: Search for the constant usage. Expect: Only occurrences of the new URL.
rg --type php 'SecurityAdvisory::PACKAGIST_ORG'

Length of output: 804


Script:

#!/bin/bash
# Extract and display lines around the usage of `SecurityAdvisory::PACKAGIST_ORG` to confirm they reflect the new URL.

# Define the files to check
files=(
    "tests/SecurityAdvisory/RemoteSecurityAdvisoryTest.php"
    "tests/SecurityAdvisory/GitHubSecurityAdvisoriesSourceTest.php"
    "src/SecurityAdvisory/RemoteSecurityAdvisory.php"
    "src/SecurityAdvisory/GitHubSecurityAdvisoriesSource.php"
)

# Loop through each file and display lines around the usage of the constant
for file in "${files[@]}"; do
    echo "Checking file: $file"
    rg --type php 'SecurityAdvisory::PACKAGIST_ORG' -A 2 -B 2 "$file"
    echo
done

Length of output: 2863

src/Service/GitHubUserMigrationWorker.php (1)

33-34: Verify the usage of the updated constants HOOK_URL and HOOK_URL_ALT across the codebase.

Ensure that all references to these constants are updated to reflect the new URLs.

Verification successful

No issues found with the updated constants HOOK_URL and HOOK_URL_ALT.

The constants HOOK_URL and HOOK_URL_ALT are not referenced elsewhere in the codebase, indicating that they are either newly introduced or their usage has been removed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to the updated constants `HOOK_URL` and `HOOK_URL_ALT`.

# Test: Search for the constants usage. Expect: Only occurrences of the new URLs.
rg --type php 'GitHubUserMigrationWorker::HOOK_URL'
rg --type php 'GitHubUserMigrationWorker::HOOK_URL_ALT'

Length of output: 107


Script:

#!/bin/bash
# Description: Verify all references to the updated constants `HOOK_URL` and `HOOK_URL_ALT` with additional context lines.

# Search for the constants usage with context lines to capture more information.
rg --type php 'GitHubUserMigrationWorker::HOOK_URL' -A 3 -B 3
rg --type php 'GitHubUserMigrationWorker::HOOK_URL_ALT' -A 3 -B 3

Length of output: 127

src/Entity/User.php (2)

185-185: Verify the usage of the updated User-Agent header in getGithubUsername method.

Ensure that the updated User-Agent header is correctly used and does not impact the rate limiting or request handling by GitHub.

Verification successful

Verification successful: The updated User-Agent header is correctly used in the getGithubUsername method.

  • The method constructs a stream context with the updated User-Agent header and the GitHub token.
  • The request to the GitHub API is made using file_get_contents.
  • The response is decoded and the GitHub username is returned.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the updated User-Agent header in the `getGithubUsername` method.

# Test: Search for the method usage. Expect: Correct usage of the updated User-Agent header.
rg --type php 'getGithubUsername'

Length of output: 106


Script:

#!/bin/bash
# Extract the implementation of the `getGithubUsername` method from the `src/Entity/User.php` file.
ast-grep --lang php --pattern $'class $_ {
  $$$
  public function getGithubUsername(): string|null {
    $$$
  }
  $$$  
}' 

Length of output: 232


Script:

#!/bin/bash
# Search for the `getGithubUsername` method definition and include context lines to capture its implementation.
rg --type php 'public function getGithubUsername' -A 20

Length of output: 1136


389-395: Verify the usage of the new roles in the getRoles method.

Ensure that the new roles are correctly used and do not cause any conflicts or issues within the application.

Verification successful

The new roles are correctly used and integrated within the application.

The new roles (ROLE_ADMIN, ROLE_DELETE_PACKAGES, ROLE_EDIT_PACKAGES, ROLE_SUPERADMIN, ROLE_UPDATE_PACKAGES) are referenced and used consistently across multiple files, ensuring role-based access control without any apparent conflicts or issues.

  • src/Validator/PopularPackageSafetyValidator.php
  • src/Security/Voter/PackageVoter.php
  • src/DataFixtures/UserFixtures.php
  • src/Controller/ProfileController.php
  • src/Controller/PackageController.php
  • src/Controller/ApiController.php
  • src/Controller/UserController.php
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new roles in the `getRoles` method.

# Test: Search for the method usage. Expect: Correct usage of the new roles.
rg --type php 'getRoles'

Length of output: 334


Script:

#!/bin/bash
# Extracting the relevant code block around the usage of getRoles in src/Security/BruteForceLoginFormAuthenticator.php
rg --type php -A 10 -B 10 'getRoles' src/Security/BruteForceLoginFormAuthenticator.php

# Extracting the relevant code block around the usage of getRoles in src/Entity/User.php
rg --type php -A 10 -B 10 'getRoles' src/Entity/User.php

Length of output: 1948


Script:

#!/bin/bash
# Searching for occurrences of the new roles in the codebase
rg --type php 'ROLE_ADMIN|ROLE_DELETE_PACKAGES|ROLE_EDIT_PACKAGES|ROLE_SUPERADMIN|ROLE_UPDATE_PACKAGES'

Length of output: 2120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants