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

chore(sentry_apps): Move over installation endpoints to sentry_apps #77869

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ module = [
"sentry.api.endpoints.index",
"sentry.api.endpoints.integrations.sentry_apps.details",
"sentry.api.endpoints.integrations.sentry_apps.index",
"sentry.api.endpoints.integrations.sentry_apps.installation.index",
"sentry.api.endpoints.integrations.sentry_apps.internal_app_token.index",
"sentry.api.endpoints.integrations.sentry_apps.publish_request",
"sentry.api.endpoints.integrations.sentry_apps.requests",
Expand Down
12 changes: 0 additions & 12 deletions src/sentry/api/endpoints/integrations/sentry_apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
from .details import SentryAppDetailsEndpoint
from .features import SentryAppFeaturesEndpoint
from .index import SentryAppsEndpoint
from .installation.details import SentryAppInstallationDetailsEndpoint
from .installation.external_issue.actions import SentryAppInstallationExternalIssueActionsEndpoint
from .installation.external_issue.details import SentryAppInstallationExternalIssueDetailsEndpoint
from .installation.external_issue.index import SentryAppInstallationExternalIssuesEndpoint
from .installation.external_requests import SentryAppInstallationExternalRequestsEndpoint
from .installation.index import SentryAppInstallationsEndpoint
from .interaction import SentryAppInteractionEndpoint
from .internal_app_token.details import SentryInternalAppTokenDetailsEndpoint
from .internal_app_token.index import SentryInternalAppTokensEndpoint
Expand All @@ -26,12 +20,6 @@
"SentryAppComponentsEndpoint",
"SentryAppDetailsEndpoint",
"SentryAppFeaturesEndpoint",
"SentryAppInstallationDetailsEndpoint",
"SentryAppInstallationExternalIssueActionsEndpoint",
"SentryAppInstallationExternalIssueDetailsEndpoint",
"SentryAppInstallationExternalIssuesEndpoint",
"SentryAppInstallationExternalRequestsEndpoint",
"SentryAppInstallationsEndpoint",
"SentryAppInteractionEndpoint",
"SentryAppPublishRequestEndpoint",
"SentryAppRequestsEndpoint",
Expand Down
22 changes: 16 additions & 6 deletions src/sentry/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@
from sentry.scim.endpoints.members import OrganizationSCIMMemberDetails, OrganizationSCIMMemberIndex
from sentry.scim.endpoints.schemas import OrganizationSCIMSchemaIndex
from sentry.scim.endpoints.teams import OrganizationSCIMTeamDetails, OrganizationSCIMTeamIndex
from sentry.sentry_apps.api.endpoints.installation_details import (
SentryAppInstallationDetailsEndpoint,
)
from sentry.sentry_apps.api.endpoints.installation_external_issue_actions import (
SentryAppInstallationExternalIssueActionsEndpoint,
)
from sentry.sentry_apps.api.endpoints.installation_external_issue_details import (
SentryAppInstallationExternalIssueDetailsEndpoint,
)
from sentry.sentry_apps.api.endpoints.installation_external_issues import (
SentryAppInstallationExternalIssuesEndpoint,
)
from sentry.sentry_apps.api.endpoints.installation_external_requests import (
SentryAppInstallationExternalRequestsEndpoint,
)
from sentry.sentry_apps.api.endpoints.sentry_app_installations import SentryAppInstallationsEndpoint
from sentry.uptime.endpoints.project_uptime_alert_details import ProjectUptimeAlertDetailsEndpoint
from sentry.uptime.endpoints.project_uptime_alert_index import ProjectUptimeAlertIndexEndpoint
from sentry.users.api.endpoints.authenticator_index import AuthenticatorIndexEndpoint
Expand Down Expand Up @@ -368,12 +384,6 @@
SentryAppComponentsEndpoint,
SentryAppDetailsEndpoint,
SentryAppFeaturesEndpoint,
SentryAppInstallationDetailsEndpoint,
SentryAppInstallationExternalIssueActionsEndpoint,
SentryAppInstallationExternalIssueDetailsEndpoint,
SentryAppInstallationExternalIssuesEndpoint,
SentryAppInstallationExternalRequestsEndpoint,
SentryAppInstallationsEndpoint,
SentryAppInteractionEndpoint,
SentryAppPublishRequestEndpoint,
SentryAppRequestsEndpoint,
Expand Down
1 change: 1 addition & 0 deletions src/sentry/conf/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2971,6 +2971,7 @@ def custom_parameter_sort(parameter: dict) -> tuple[str, int]:
"sentry.issues.endpoints",
"sentry.integrations.api.endpoints",
"sentry.users.api.endpoints",
"sentry.sentry_apps.api.endpoints",
)
SENTRY_MAIL_ADAPTER_BACKEND = "sentry.mail.adapter.MailAdapter"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from sentry.sentry_apps.installations import SentryAppInstallationCreator
from sentry.sentry_apps.models.sentry_app import SentryApp
from sentry.sentry_apps.models.sentry_app_installation import SentryAppInstallation
from sentry.users.models.user import User
from sentry.users.services.user.model import RpcUser


class SentryAppInstallationsSerializer(serializers.Serializer):
Expand Down Expand Up @@ -90,6 +92,9 @@ def post(self, request: Request, organization) -> Response:
sentry_app__slug=slug, organization_id=organization.id
)
except SentryAppInstallation.DoesNotExist:
assert isinstance(request.user, User) or isinstance(
request.user, RpcUser
), "user must be authenticated to create a SentryAppInstallation"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this typing too narrow? -> are there other types of users (RpcUser, User, AnonymousUser)? Is it even true that being authenticated == being a User/RpcUser.

Copy link
Member

Choose a reason for hiding this comment

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

are there other types of users (RpcUser, User, AnonymousUser)?

No, those are all the type options for request.user

Is it even true that being authenticated == being a User/RpcUser.

Yes, if a request is not authenticated request.user will be AnonymousUser.

Christinarlong marked this conversation as resolved.
Show resolved Hide resolved
install = SentryAppInstallationCreator(
organization_id=organization.id, slug=slug, notify=True
).run(user=request.user, request=request)
Expand Down
5 changes: 3 additions & 2 deletions src/sentry/sentry_apps/installations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from sentry.sentry_apps.services.hook import hook_service
from sentry.tasks.sentry_apps import installation_webhook
from sentry.users.models.user import User
from sentry.users.services.user.model import RpcUser
from sentry.utils import metrics


Expand Down Expand Up @@ -100,7 +101,7 @@ class SentryAppInstallationCreator:
slug: str
notify: bool = True

def run(self, *, user: User, request: HttpRequest | None) -> SentryAppInstallation:
def run(self, *, user: User | RpcUser, request: HttpRequest | None) -> SentryAppInstallation:
metrics.incr("sentry_apps.installation.attempt")
with transaction.atomic(router.db_for_write(ApiGrant)):
api_grant = self._create_api_grant()
Expand Down Expand Up @@ -157,7 +158,7 @@ def audit(self, request: HttpRequest | None) -> None:
data={"sentry_app": self.sentry_app.name},
)

def record_analytics(self, user: User) -> None:
def record_analytics(self, user: User | RpcUser) -> None:
analytics.record(
"sentry_app.installed",
user_id=user.id,
Expand Down
Loading