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

Develop #618

Merged
merged 29 commits into from
Sep 3, 2024
Merged

Develop #618

merged 29 commits into from
Sep 3, 2024

Conversation

PooyaFekri
Copy link
Collaborator

@PooyaFekri PooyaFekri commented Sep 3, 2024

Summary by Sourcery

Add new constraint verifications for hCaptcha and Zora NFT minting, integrate Cloudflare Images storage, and enhance existing serializers and models. Fix Twitter connection integrity issues and update tests accordingly.

New Features:

  • Introduce a new constraint verification class HasVerifiedHCaptcha for verifying hCaptcha tokens.
  • Add a new constraint DidMintZoraNFT to verify if a user has minted a Zora NFT.
  • Implement ZoraUtil for interacting with the Zora API to check token transfers.
  • Add support for Cloudflare Images storage in the project settings and models.

Bug Fixes:

  • Fix potential integrity error when saving Twitter connection by adding a unique twitter_id field.

Enhancements:

  • Refactor the is_valid method in serializers to explicitly pass the raise_exception parameter.
  • Update the Subgraph class to use paths instead of path for better clarity.
  • Improve caching logic in constraint verification by ensuring consistent parameter passing.

Build:

  • Add environment variables for Cloudflare and hCaptcha configurations.

Tests:

  • Update tests to reflect changes in model fields, particularly the renaming of image_url to image.

Chores:

  • Remove unnecessary blank lines in validators and other minor code cleanup.

alimaktabi and others added 29 commits August 25, 2024 18:07
…m package

upgrade django to 5 and other dependencies

refactored deprecated utc import
…ter-connection

Add twitter_id filed to TwitterConnection
…ter-connection

Fix test in twitter constraint
Copy link
Contributor

sourcery-ai bot commented Sep 3, 2024

Reviewer's Guide by Sourcery

This pull request introduces several significant changes across multiple files, including new features, refactoring, and improvements to existing functionality. The main changes include adding support for HCaptcha, implementing Zora NFT minting verification, updating image handling to use Cloudflare Images, refactoring constraint handling, and making various improvements to models and serializers.

File-Level Changes

Change Details Files
Added support for HCaptcha verification
  • Implemented HasVerifiedHCaptcha constraint
  • Created HCaptchaUtil class for verification
  • Added H_CAPTCHA_SECRET to settings
  • Updated constraint choices to include HasVerifiedHCaptcha
core/constraints/captcha.py
core/thirdpartyapp/hcaptcha.py
brightIDfaucet/settings.py
core/models.py
prizetap/migrations/0078_alter_constraint_name.py
tokenTap/migrations/0064_alter_constraint_name.py
Implemented Zora NFT minting verification
  • Added DidMintZoraNFT constraint
  • Created ZoraUtil class for API interactions
  • Updated constraint choices to include DidMintZoraNFT
  • Added ZORA_BASE_URL to settings
core/constraints/zora.py
core/thirdpartyapp/zora.py
core/thirdpartyapp/config.py
core/models.py
prizetap/migrations/0077_alter_constraint_name.py
tokenTap/migrations/0063_alter_constraint_name.py
Updated image handling to use Cloudflare Images
  • Replaced image_url and token_image_url fields with CloudflareImagesField
  • Added Cloudflare Images configuration to settings
  • Updated serializers to use new image fields
tokenTap/models.py
prizetap/models.py
brightIDfaucet/settings.py
tokenTap/serializers.py
prizetap/serializers.py
tokenTap/migrations/0063_remove_tokendistribution_token_image_url_and_more.py
prizetap/migrations/0077_remove_raffle_image_url_raffle_image.py
Refactored constraint handling
  • Updated ConstraintVerification class to include obj parameter
  • Modified constraint validation logic in validators
  • Updated constraint choices in models
core/constraints/abstract.py
tokenTap/validators.py
prizetap/validators.py
core/models.py
Improved Twitter connection handling
  • Added twitter_id field to TwitterConnection model
  • Updated TwitterConnection methods to use twitter_id
  • Modified Twitter connection view to handle IntegrityError
authentication/models.py
authentication/views.py
authentication/migrations/0042_twitterconnection_twitter_id.py
Refactored and improved serializers
  • Updated is_valid methods to properly handle raise_exception parameter
  • Modified field names in serializers to match model changes
authentication/serializers.py
tokenTap/serializers.py
prizetap/serializers.py
Added BigNumField for handling large numeric values
  • Implemented BigNumField class
  • Updated models to use BigNumField where appropriate
core/fields.py
tokenTap/models.py
prizetap/models.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 @PooyaFekri - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding more comprehensive error handling and logging in the new HCaptchaUtil and ZoraUtil classes to improve debugging and monitoring capabilities.
  • It might be beneficial to add unit tests for the newly introduced functionality, especially for the Zora NFT minting verification and HCaptcha integration.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 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.




class HasVerifiedHCaptcha(ConstraintVerification):
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider extracting common captcha verification logic

The is_observed method in HasVerifiedHCaptcha is very similar to the one in HasVerifiedCloudflareCaptcha. Consider extracting common functionality to a base class or utility function to reduce code duplication.

class BaseCaptchaVerification(ConstraintVerification):
    _param_keys = []
    app_name = ConstraintApp.GENERAL.value

class HasVerifiedHCaptcha(BaseCaptchaVerification):
    pass

from core.thirdpartyapp import config


class ZoraUtil:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Enhance Zora API interaction with rate limiting and error handling

Consider implementing rate limiting and more robust error handling in the Zora API interaction to improve reliability and prevent potential issues with external API calls.

class ZoraUtil:
    def __init__(self):
        self.request = RequestHelper(base_url=config.ZORA_BASE_URL)
        self.paths = {"get-address-token-transfer": "api/v2/addresses/{address}/token-transfers"}
        self.rate_limiter = RateLimiter(max_calls=100, period=60)

    @retry(exceptions=RequestException, tries=3, delay=1, backoff=2)
    def make_request(self, method, path, **kwargs):
        with self.rate_limiter:
            return self.request.request(method, path, **kwargs)

Comment on lines +23 to +26
if isinstance(value, str):
return int(value)

return value
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): We've found these issues:

Suggested change
if isinstance(value, str):
return int(value)
return value
return int(value) if isinstance(value, str) else value

@PooyaFekri PooyaFekri merged commit 445888b into main Sep 3, 2024
2 checks 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.

3 participants