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

ref(hc): Remove get_orgs() #54635

Merged
merged 8 commits into from
Aug 12, 2023
Merged

ref(hc): Remove get_orgs() #54635

merged 8 commits into from
Aug 12, 2023

Conversation

corps
Copy link
Contributor

@corps corps commented Aug 11, 2023

user.get_orgs() is problematic, because the Organization objects associated to a user via OrganizationMember can only ever be per region, and not contain all organizations a user belongs to globally.

This PR attempts to use separate means of getting the same question answered but with more specific implementations, so we can extract the user.get_orgs() which is ambiguous.

For instance, Organization.get_for_user_ids can only mean within a region scope. but user_service.get_organizations will include global organizations.

@corps corps requested a review from a team August 11, 2023 16:13
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 11, 2023
@codecov
Copy link

codecov bot commented Aug 11, 2023

Codecov Report

Merging #54635 (623bc23) into master (31516cd) will decrease coverage by 0.01%.
Report is 45 commits behind head on master.
The diff coverage is 87.30%.

❗ Current head 623bc23 differs from pull request most recent head d8e9ace. Consider uploading reports for the commit d8e9ace to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #54635      +/-   ##
==========================================
- Coverage   79.75%   79.75%   -0.01%     
==========================================
  Files        4995     5001       +6     
  Lines      212163   212385     +222     
  Branches    36163    36196      +33     
==========================================
+ Hits       169206   169380     +174     
- Misses      37750    37793      +43     
- Partials     5207     5212       +5     
Files Changed Coverage Δ
src/sentry/features/helpers.py 85.71% <ø> (-4.77%) ⬇️
src/sentry/models/user.py 91.44% <ø> (-0.27%) ⬇️
src/sentry/api/endpoints/user_organizations.py 75.00% <74.07%> (-11.67%) ⬇️
src/sentry/api/bases/sentryapps.py 88.49% <94.73%> (-0.06%) ⬇️
src/sentry/api/bases/user.py 84.00% <100.00%> (+0.66%) ⬆️
...ry/api/endpoints/integrations/sentry_apps/index.py 100.00% <100.00%> (ø)
...try/api/endpoints/user_notification_fine_tuning.py 100.00% <100.00%> (ø)
src/sentry/api/serializers/models/sentry_app.py 97.22% <100.00%> (ø)

... and 34 files with indirect coverage changes

@corps corps marked this pull request as ready for review August 11, 2023 21:38
@corps corps requested review from a team as code owners August 11, 2023 21:38
@@ -77,17 +80,17 @@ class SentryAppsPermission(SentryPermission):
"POST": ("org:write", "org:admin"),
}

def has_object_permission(self, request: Request, view, organization):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SentryApps will be control silo, which means they won't have direct access to organizations. the context here represents an RPC lookup of org details.

@@ -89,28 +93,11 @@ def put(self, request: Request, user, notification_type) -> Response:

# Make sure that the IDs we are going to update are a subset of the
# user's list of organizations or projects.
parents = (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Requiring validation of project is and organization ids forces a fan out across all regions for a user. In reality, these values are not foreign keys. We also frequently "leave behind" notification settings without clearing them in all cases, so letting arbitrary values from a user isn't particularly problematic. Having notification settings for a project or org you don't belong to doesn't grant any access or necessarily grant any notifications.

from sentry.services.hybrid_cloud.user.service import user_service


@region_silo_endpoint
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Swapping this to a region endpoint. In the future, we plan to have the frontend query a user's organization settings per non single tenant region they belong to. Pushing this to the frontend makes sense in the long term.

@getsantry getsantry bot requested a review from a team as a code owner August 12, 2023 01:31
def requires_feature(
feature: str, any_org: Optional[bool] = None
) -> Callable[[EndpointFunc], EndpointFunc]:
def requires_feature(feature: str) -> Callable[[EndpointFunc], EndpointFunc]:
Copy link
Member

Choose a reason for hiding this comment

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

@corps We can just delete this function as it's no longer used anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, thanks!

@corps corps enabled auto-merge (squash) August 12, 2023 01:48
@corps corps merged commit de831d0 into master Aug 12, 2023
55 checks passed
@corps corps deleted the zc/remove-get-orgs-usages branch August 12, 2023 02:01
@corps corps added the Trigger: Revert Add to a merged PR to revert it (skips CI) label Aug 12, 2023
@getsentry-bot
Copy link
Contributor

PR reverted: 4235ed0

getsentry-bot added a commit that referenced this pull request Aug 12, 2023
This reverts commit de831d0.

Co-authored-by: corps <593850+corps@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components Trigger: Revert Add to a merged PR to revert it (skips CI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants