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

Validate JavaScript condition in Layer Rule on save (#12901) #12968

Merged

Conversation

sobotama
Copy link
Contributor

Fix #12901


try
{
_ = await _evaluator.EvaluateAsync(new()
Copy link
Contributor

Choose a reason for hiding this comment

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

use ParseScript instead of evaluate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I parse it first and then evaluate? Sébastien Roses second point in the issue is "ensure that evaluating the script is not breaking the full page..." so I have to evaluate and I thought that since EvaluateAsync parses it with ParseScript before evaluation then I only need to catch the exception, otherwise I would be parsing it twice.

Copy link

This pull request has merge conflicts. Please resolve those before requesting a review.

@Piedone
Copy link
Member

Piedone commented Mar 19, 2024

I sincerely apologize for us taking so much time here. I checked out the PR, going over old ones, and this would be quite useful. It needs some tweaks, and the merge conflict resolved though. And foremost, so we can do anything with the code, you'd need to accept the CLA (unfortunately, the CLA bot was broken for a while).

Is this something you'd like to revisit any time soon @sobotama or should we close?

@sobotama
Copy link
Contributor Author

sobotama commented Apr 2, 2024

Hello,

thanks for responding, I completely forgot that this was still unresovled.

I took care of the merge conflict, I'm currently figuring out the CLA with the company I work at and in the meantime, is there something else I should do @Piedone?

@sobotama
Copy link
Contributor Author

sobotama commented Apr 2, 2024

@dotnet-policy-service agree

@Piedone
Copy link
Member

Piedone commented Apr 2, 2024

Great, thank you! @ns8482e would you like to get back to the review, or should I take over?

Copy link

This pull request has merge conflicts. Please resolve those before requesting a review.

@Piedone
Copy link
Member

Piedone commented Apr 19, 2024

@ns8482e could you reply here, please?

…-condition-validation

# Conflicts:
#	src/OrchardCore.Modules/OrchardCore.Rules/Drivers/JavascriptConditionDisplayDriver.cs
Copy link
Member

@Piedone Piedone left a comment

Choose a reason for hiding this comment

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

Let me take over the review here, and thank you for your patience! I have some small remarks; once you address those, I'll merge ASAP.

When addressing review feedback, please adhere to the following:

  • Please update your pull request according to feedback until it is approved by one of the core team members.
  • Apply suggested changes directly so the reviewer doesn't have to eyeball the changes. These resolve themselves after applying them, and that's fine.
  • Don't resolve other conversations so it's easier to track for the reviewer. Then, the reviewer will resolve them.
  • Feel free to mark conversations that you addressed to keep track of them with an emoji or otherwise, just don't resolve them.
  • Please keep conversations happening in line comments in those convos, otherwise, communication will be a mess. If you have trouble finding them, see this video.
  • When you're done addressing all feedback of a review, click "Re-request review" in the top-right corner for each reviewer when you're ready for another round of review, so they know that you're done.

Changed error messages, comment moved to more meaningfull place

Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
Copy link
Contributor

coderabbitai bot commented Apr 24, 2024

Walkthrough

Walkthrough

The update primarily enhances the JavascriptConditionDisplayDriver in the OrchardCore.Rules module by integrating additional dependencies and improving script validation. It incorporates new using directives and dependencies like Jint for JavaScript parsing and execution, and localizer interfaces for better message handling. The UpdateAsync method now robustly manages script errors, ensuring user feedback through notifications.

Changes

File Path Change Summary
.../JavascriptConditionDisplayDriver.cs Added new using directives, private fields for localizers and notifier, constructor updates, and enhanced script validation in UpdateAsync.
.../OrchardCore.Rules/OrchardCore.Rules.csproj Added PackageReference for Jint.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 57bf155 and 9e249c2.
Files selected for processing (2)
  • src/OrchardCore.Modules/OrchardCore.Rules/Drivers/JavascriptConditionDisplayDriver.cs (2 hunks)
  • src/OrchardCore.Modules/OrchardCore.Rules/OrchardCore.Rules.csproj (1 hunks)
Additional comments not posted (4)
src/OrchardCore.Modules/OrchardCore.Rules/OrchardCore.Rules.csproj (1)

18-18: The addition of the Jint package reference is appropriate for the JavaScript validation functionality.

src/OrchardCore.Modules/OrchardCore.Rules/Drivers/JavascriptConditionDisplayDriver.cs (3)

1-13: The addition of new using directives supports the new functionalities introduced, such as localization, notifications, and JavaScript condition evaluation.


25-35: The constructor is well-implemented, correctly initializing all necessary services for the driver's functionality.


60-93: The updates to the UpdateAsync method correctly implement the script validation logic. However, consider moving the general comment about CodeMirror to a more appropriate place above the whole code block, as previously suggested.


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration 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.

@Piedone
Copy link
Member

Piedone commented Apr 24, 2024

@allcontributors please add @sobotama for code

Copy link
Contributor

@Piedone

I've put up a pull request to add @sobotama! 🎉

@Piedone
Copy link
Member

Piedone commented Apr 24, 2024

Thank you, and congrats on your first contribution to Orchard Core! I promise the next one won't take us two years to accept :). We implemented a lot of improvements in managing PRs since then: #15029.

Once the docs page build finishes, you'll also show up in the hall of fame here: https://docs.orchardcore.net/en/latest/docs/community/contributors/.

@Piedone Piedone merged commit 9a39f30 into OrchardCMS:main Apr 24, 2024
5 checks passed
@Piedone Piedone changed the title Validate JavaScript condition while saving (#12901) Validate JavaScript condition in Layer Rule on save (#12901) Apr 24, 2024
Copy link

Congratulations on your first PR merge! 🎉 Thank you for your contribution! We're looking forward to welcome other contributions of yours in the future. @all-contributors please add @sobotama for code.

If you like Orchard Core, please star our repo and join our community channels

Copy link
Contributor

@github-actions[bot]

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

@sobotama already contributed before to code

@Piedone
Copy link
Member

Piedone commented Apr 24, 2024

Ah, I forgot that adding contributors is now automated :).

@sobotama sobotama deleted the sobotama/javascript-condition-validation branch April 25, 2024 13:26
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.

Layers - Invalid javascript condition
3 participants