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

feat: Add tokenless mutation and field in owner #826

Merged
merged 10 commits into from
Oct 8, 2024
Merged

Conversation

RulaKhaled
Copy link
Contributor

@RulaKhaled RulaKhaled commented Sep 16, 2024

Purpose/Motivation

What is the feature? Why is this being done?
The user will set tokenless to either true or false. We need tokens_required to reflect the current status of tokenless within the organization, and we need a mutation to set tokenless to either required or not

this PR depends on:

Links to relevant tickets

[API] Expose new tokens_required field via graphql
[API] Add new require token mutation

What does this PR do?

Include a brief description of the changes in this PR. Bullet points are your friend.

  • mutation
  • new field under owner query
  • tests

Notes to Reviewer

Anything to note to the team? Any tips on how to review, or where to start?

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@RulaKhaled RulaKhaled requested a review from a team as a code owner September 16, 2024 12:23
@RulaKhaled RulaKhaled marked this pull request as draft September 16, 2024 12:23
@@ -37,4 +37,5 @@ type Owner {
): RepositoryConnection! @cost(complexity: 25, multipliers: ["first", "last"])
username: String
yaml: String
tokensRequierd: Boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo

Copy link
Contributor

@adrian-codecov adrian-codecov Sep 16, 2024

Choose a reason for hiding this comment

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

Also, when would this field be set to Null instead of true/false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, when user is not part of the org (decorator rules)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed 👍


self.validate(owner_obj)

owner_obj.tokens_required = typed_input.tokens_required
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on this being token_required? And even to be more explicit, upload_token required?

We use the github/providers token for other things, so differentiating this as the "codecov_token" or "upload_token" would make more sense. I also don't know if this exclusively a coverage token or if it also applies to bundle_analysis/test_results, so I'd confirm what's the expected behavior, and if it is exclusively for coverage (and we don't intend to do it for BA/TR), then I'd call it coverage_token or upload_coverage_token or something like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a draft PR not the final code, just put tokens_required as it's the suggested name by Trent for Nora, so i will change the name according to what it's called in the DB to avoid any confusion

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good! 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to upload_token_required!

@RulaKhaled RulaKhaled marked this pull request as ready for review October 4, 2024 14:18
@codecov-notifications
Copy link

codecov-notifications bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.34%. Comparing base (f46d73a) to head (fe1ec6b).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #826      +/-   ##
==========================================
+ Coverage   96.33%   96.34%   +0.01%     
==========================================
  Files         820      823       +3     
  Lines       19102    19157      +55     
==========================================
+ Hits        18402    18457      +55     
  Misses        700      700              
Flag Coverage Δ
unit 92.71% <100.00%> (+0.02%) ⬆️
unit-latest-uploader 92.71% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

if not current_user_part_of_org(self.current_owner, owner_obj):
raise Unauthorized()
if not owner_obj.is_admin(self.current_owner):
raise Unauthorized("Admin authorization required")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can upload_token_required be null? If not maybe do some validation here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on it

self.owner_with_admins.refresh_from_db()
assert self.owner_with_admins.upload_token_required_for_public_repos == True

def test_set_upload_token_required_to_false(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add a test here for the null case based on the above

}

input SetUploadTokenRequiredInput {
org_username: String!
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this snake and the below camel 👀 could we follow the camel convention pls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch

@@ -39,4 +39,5 @@ type Owner {
yaml: String
aiFeaturesEnabled: Boolean!
aiEnabledRepos: [String]
uploadTokenRequired: Boolean
Copy link
Contributor

@adrian-codecov adrian-codecov Oct 7, 2024

Choose a reason for hiding this comment

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

Is it intentional for this to be null? Seems the interactor only expects bool, and afaik we were going to backfill/default everyone to have false weren't we? That's what I recall from Nora

Copy link
Contributor Author

@RulaKhaled RulaKhaled Oct 8, 2024

Choose a reason for hiding this comment

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

The decorator @require_part_of_org should return null if user is not part of the org!

@codecov-qa
Copy link

codecov-qa bot commented Oct 8, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2563 1 2562 6
View the top 1 failed tests by shortest run time
billing.tests.test_views.StripeWebhookHandlerTests test_customer_subscription_deleted_deactivates_all_repos_multiple_owner
Stack Traces | 0.034s run time
self = &lt;billing.tests.test_views.StripeWebhookHandlerTests testMethod=test_customer_subscription_deleted_deactivates_all_repos_multiple_owner&gt;

    def test_customer_subscription_deleted_deactivates_all_repos_multiple_owner(self):
        self.add_second_owner()
        RepositoryFactory(author=self.owner, activated=True, active=True)
        RepositoryFactory(author=self.owner, activated=True, active=True)
        RepositoryFactory(author=self.owner, activated=True, active=True)
        RepositoryFactory(author=self.other_owner, activated=True, active=True)
        RepositoryFactory(author=self.other_owner, activated=True, active=True)
        RepositoryFactory(author=self.other_owner, activated=True, active=True)
    
        self.owner.refresh_from_db()
        self.other_owner.refresh_from_db()
    
&gt;       assert (
            self.owner.repository_set.filter(activated=True, active=True).count() == 3
        )
E       assert 2 == 3
E        +  where 2 = &lt;bound method QuerySet.count of &lt;RepositoryQuerySet [&lt;Repository: Repo&lt;Owner&lt;github/stephen88&gt;/push&gt;&gt;, &lt;Repository: Repo&lt;Owner&lt;github/stephen88&gt;/nature&gt;&gt;]&gt;&gt;()
E        +    where &lt;bound method QuerySet.count of &lt;RepositoryQuerySet [&lt;Repository: Repo&lt;Owner&lt;github/stephen88&gt;/push&gt;&gt;, &lt;Repository: Repo&lt;Owner&lt;github/stephen88&gt;/nature&gt;&gt;]&gt;&gt; = &lt;RepositoryQuerySet [&lt;Repository: Repo&lt;Owner&lt;github/stephen88&gt;/push&gt;&gt;, &lt;Repository: Repo&lt;Owner&lt;github/stephen88&gt;/nature&gt;&gt;]&gt;.count
E        +      where &lt;RepositoryQuerySet [&lt;Repository: Repo&lt;Owner&lt;github/stephen88&gt;/push&gt;&gt;, &lt;Repository: Repo&lt;Owner&lt;github/stephen88&gt;/nature&gt;&gt;]&gt; = &lt;bound method QuerySet.filter of &lt;django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.&lt;locals&gt;.RelatedManager object at 0x7f6477d34620&gt;&gt;(activated=True, active=True)
E        +        where &lt;bound method QuerySet.filter of &lt;django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.&lt;locals&gt;.RelatedManager object at 0x7f6477d34620&gt;&gt; = &lt;django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.&lt;locals&gt;.RelatedManager object at 0x7f6477d34620&gt;.filter
E        +          where &lt;django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.&lt;locals&gt;.RelatedManager object at 0x7f6477d34620&gt; = &lt;Owner: Owner&lt;github/stephen88&gt;&gt;.repository_set
E        +            where &lt;Owner: Owner&lt;github/stephen88&gt;&gt; = &lt;billing.tests.test_views.StripeWebhookHandlerTests testMethod=test_customer_subscription_deleted_deactivates_all_repos_multiple_owner&gt;.owner

billing/tests/test_views.py:276: AssertionError

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

Copy link

Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time.

❌ Failed Test Results:

Completed 2569 tests with 1 failed, 2562 passed and 6 skipped.

View the full list of failed tests

pytest

  • Class name: billing.tests.test_views.StripeWebhookHandlerTests
    Test name: test_customer_subscription_deleted_deactivates_all_repos_multiple_owner

    self = <billing.tests.test_views.StripeWebhookHandlerTests testMethod=test_customer_subscription_deleted_deactivates_all_repos_multiple_owner>

    def test_customer_subscription_deleted_deactivates_all_repos_multiple_owner(self):
    self.add_second_owner()
    RepositoryFactory(author=self.owner, activated=True, active=True)
    RepositoryFactory(author=self.owner, activated=True, active=True)
    RepositoryFactory(author=self.owner, activated=True, active=True)
    RepositoryFactory(author=self.other_owner, activated=True, active=True)
    RepositoryFactory(author=self.other_owner, activated=True, active=True)
    RepositoryFactory(author=self.other_owner, activated=True, active=True)

    self.owner.refresh_from_db()
    self.other_owner.refresh_from_db()

    > assert (
    self.owner.repository_set.filter(activated=True, active=True).count() == 3
    )
    E assert 2 == 3
    E + where 2 = <bound method QuerySet.count of <RepositoryQuerySet [<Repository: Repo<Owner<github/stephen88>/push>>, <Repository: Repo<Owner<github/stephen88>/nature>>]>>()
    E + where <bound method QuerySet.count of <RepositoryQuerySet [<Repository: Repo<Owner<github/stephen88>/push>>, <Repository: Repo<Owner<github/stephen88>/nature>>]>> = <RepositoryQuerySet [<Repository: Repo<Owner<github/stephen88>/push>>, <Repository: Repo<Owner<github/stephen88>/nature>>]>.count
    E + where <RepositoryQuerySet [<Repository: Repo<Owner<github/stephen88>/push>>, <Repository: Repo<Owner<github/stephen88>/nature>>]> = <bound method QuerySet.filter of <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f6477d34620>>(activated=True, active=True)
    E + where <bound method QuerySet.filter of <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f6477d34620>> = <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f6477d34620>.filter
    E + where <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f6477d34620> = <Owner: Owner<github/stephen88>>.repository_set
    E + where <Owner: Owner<github/stephen88>> = <billing.tests.test_views.StripeWebhookHandlerTests testMethod=test_customer_subscription_deleted_deactivates_all_repos_multiple_owner>.owner

    billing/tests/test_views.py:276: AssertionError

@RulaKhaled RulaKhaled added this pull request to the merge queue Oct 8, 2024
Merged via the queue into main with commit b6b028c Oct 8, 2024
19 of 20 checks passed
@RulaKhaled RulaKhaled deleted the tokens-required branch October 8, 2024 14:35
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