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

fixed passing context argument to is_observed #607

Merged
merged 2 commits into from
Aug 26, 2024

Conversation

alimaktabi
Copy link
Collaborator

@alimaktabi alimaktabi commented Aug 26, 2024

Summary by Sourcery

Fix the handling of the context argument in the is_observed method and enhance the verification process by including an IP address check.

Bug Fixes:

  • Fix passing of the context argument to the is_observed method to ensure correct context handling.

Enhancements:

  • Improve the is_observed method by checking for a non-null IP address before verifying the turnstile token.

Copy link
Contributor

sourcery-ai bot commented Aug 26, 2024

Reviewer's Guide by Sourcery

This pull request fixes the passing of the context argument to the is_observed method in various constraint-related files. The main changes involve removing the context from the ConstraintVerification constructor and passing it directly to the is_observed method instead.

File-Level Changes

Change Details Files
Refactored context handling in HasVerifiedCloudflareCaptcha class
  • Removed context from class attributes
  • Added context as a parameter to is_observed method
  • Updated references to use the new context parameter
  • Added a check for request_context.ip in the return statement
core/constraints/captcha.py
Updated constraint initialization and verification in validators
  • Removed context from ConstraintVerification constructor call
  • Added context to is_observed method call
  • Updated context passing in check_user_constraints and check_user_permissions methods
prizetap/validators.py
tokenTap/validators.py
Modified ConstraintVerification base class
  • Removed context parameter from constructor
  • Removed self.context attribute
core/constraints/abstract.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @alimaktabi - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider removing the unused 'context' parameter from the constructor calls where it's still present, such as in tokenTap/validators.py.
  • The change to pass context to is_observed() instead of storing it in the object is good, but it might be worth creating a separate task to ensure this pattern is consistently applied throughout the codebase.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

if self.context is None or self.context.get("requset") is None:
context = kwargs.get("context")

if context is None or context.get("requset") is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (typo): Fix typo in 'requset'

The word 'request' is misspelled as 'requset' here and in the line below. This typo could cause issues with accessing the correct data.

@@ -16,17 +16,19 @@ class HasVerifiedCloudflareCaptcha(ConstraintVerification):

def is_observed(self, *args, **kwargs) -> bool:

if self.context is None or self.context.get("requset") is None:
context = kwargs.get("context")
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring to use self.context directly.

The new code introduces unnecessary complexity by using kwargs to extract context, which is redundant since self.context is already available. This adds an extra layer of indirection without clear benefits and can lead to inconsistencies, especially if the rest of the class relies on instance variables. Additionally, the code does not check if context is provided in kwargs, potentially leading to errors. Consider refactoring to maintain simplicity and consistency with the original design, using self.context directly. This approach reduces complexity and aligns with object-oriented principles.

@PooyaFekri PooyaFekri merged commit 2071b98 into develop Aug 26, 2024
1 check passed
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