diff --git a/pyproject.toml b/pyproject.toml index de1cb687a3a0d2..fca22dbf49f5c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/src/sentry/api/endpoints/integrations/sentry_apps/__init__.py b/src/sentry/api/endpoints/integrations/sentry_apps/__init__.py index 140934cc533b6e..a6a8d05d8ed9dc 100644 --- a/src/sentry/api/endpoints/integrations/sentry_apps/__init__.py +++ b/src/sentry/api/endpoints/integrations/sentry_apps/__init__.py @@ -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 @@ -26,12 +20,6 @@ "SentryAppComponentsEndpoint", "SentryAppDetailsEndpoint", "SentryAppFeaturesEndpoint", - "SentryAppInstallationDetailsEndpoint", - "SentryAppInstallationExternalIssueActionsEndpoint", - "SentryAppInstallationExternalIssueDetailsEndpoint", - "SentryAppInstallationExternalIssuesEndpoint", - "SentryAppInstallationExternalRequestsEndpoint", - "SentryAppInstallationsEndpoint", "SentryAppInteractionEndpoint", "SentryAppPublishRequestEndpoint", "SentryAppRequestsEndpoint", diff --git a/src/sentry/api/urls.py b/src/sentry/api/urls.py index 7ed0ee60551096..483654466288ed 100644 --- a/src/sentry/api/urls.py +++ b/src/sentry/api/urls.py @@ -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 @@ -368,12 +384,6 @@ SentryAppComponentsEndpoint, SentryAppDetailsEndpoint, SentryAppFeaturesEndpoint, - SentryAppInstallationDetailsEndpoint, - SentryAppInstallationExternalIssueActionsEndpoint, - SentryAppInstallationExternalIssueDetailsEndpoint, - SentryAppInstallationExternalIssuesEndpoint, - SentryAppInstallationExternalRequestsEndpoint, - SentryAppInstallationsEndpoint, SentryAppInteractionEndpoint, SentryAppPublishRequestEndpoint, SentryAppRequestsEndpoint, diff --git a/src/sentry/conf/server.py b/src/sentry/conf/server.py index c5fab0be9d00b6..18e383acd1fe07 100644 --- a/src/sentry/conf/server.py +++ b/src/sentry/conf/server.py @@ -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" diff --git a/src/sentry/api/endpoints/integrations/sentry_apps/installation/__init__.py b/src/sentry/sentry_apps/api/endpoints/__init__.py similarity index 100% rename from src/sentry/api/endpoints/integrations/sentry_apps/installation/__init__.py rename to src/sentry/sentry_apps/api/endpoints/__init__.py diff --git a/src/sentry/api/endpoints/integrations/sentry_apps/installation/details.py b/src/sentry/sentry_apps/api/endpoints/installation_details.py similarity index 100% rename from src/sentry/api/endpoints/integrations/sentry_apps/installation/details.py rename to src/sentry/sentry_apps/api/endpoints/installation_details.py diff --git a/src/sentry/api/endpoints/integrations/sentry_apps/installation/external_issue/actions.py b/src/sentry/sentry_apps/api/endpoints/installation_external_issue_actions.py similarity index 100% rename from src/sentry/api/endpoints/integrations/sentry_apps/installation/external_issue/actions.py rename to src/sentry/sentry_apps/api/endpoints/installation_external_issue_actions.py diff --git a/src/sentry/api/endpoints/integrations/sentry_apps/installation/external_issue/details.py b/src/sentry/sentry_apps/api/endpoints/installation_external_issue_details.py similarity index 100% rename from src/sentry/api/endpoints/integrations/sentry_apps/installation/external_issue/details.py rename to src/sentry/sentry_apps/api/endpoints/installation_external_issue_details.py diff --git a/src/sentry/api/endpoints/integrations/sentry_apps/installation/external_issue/index.py b/src/sentry/sentry_apps/api/endpoints/installation_external_issues.py similarity index 100% rename from src/sentry/api/endpoints/integrations/sentry_apps/installation/external_issue/index.py rename to src/sentry/sentry_apps/api/endpoints/installation_external_issues.py diff --git a/src/sentry/api/endpoints/integrations/sentry_apps/installation/external_requests.py b/src/sentry/sentry_apps/api/endpoints/installation_external_requests.py similarity index 100% rename from src/sentry/api/endpoints/integrations/sentry_apps/installation/external_requests.py rename to src/sentry/sentry_apps/api/endpoints/installation_external_requests.py diff --git a/src/sentry/api/endpoints/integrations/sentry_apps/installation/index.py b/src/sentry/sentry_apps/api/endpoints/sentry_app_installations.py similarity index 94% rename from src/sentry/api/endpoints/integrations/sentry_apps/installation/index.py rename to src/sentry/sentry_apps/api/endpoints/sentry_app_installations.py index 5e2be9dfecbdfa..6c82deffaf59c1 100644 --- a/src/sentry/api/endpoints/integrations/sentry_apps/installation/index.py +++ b/src/sentry/sentry_apps/api/endpoints/sentry_app_installations.py @@ -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): @@ -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, RpcUser) + ), "user must be authenticated to create a SentryAppInstallation" install = SentryAppInstallationCreator( organization_id=organization.id, slug=slug, notify=True ).run(user=request.user, request=request) diff --git a/src/sentry/sentry_apps/installations.py b/src/sentry/sentry_apps/installations.py index 777f91b6bffe30..9cf122a680c301 100644 --- a/src/sentry/sentry_apps/installations.py +++ b/src/sentry/sentry_apps/installations.py @@ -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 @@ -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() @@ -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, diff --git a/tests/sentry/api/endpoints/test_organization_sentry_app_installation_details.py b/tests/sentry/sentry_apps/api/endpoints/test_organization_sentry_app_installation_details.py similarity index 100% rename from tests/sentry/api/endpoints/test_organization_sentry_app_installation_details.py rename to tests/sentry/sentry_apps/api/endpoints/test_organization_sentry_app_installation_details.py diff --git a/tests/sentry/api/endpoints/test_organization_sentry_app_installations.py b/tests/sentry/sentry_apps/api/endpoints/test_organization_sentry_app_installations.py similarity index 100% rename from tests/sentry/api/endpoints/test_organization_sentry_app_installations.py rename to tests/sentry/sentry_apps/api/endpoints/test_organization_sentry_app_installations.py diff --git a/tests/sentry/api/endpoints/test_sentry_app_installation_external_issue_actions.py b/tests/sentry/sentry_apps/api/endpoints/test_sentry_app_installation_external_issue_actions.py similarity index 100% rename from tests/sentry/api/endpoints/test_sentry_app_installation_external_issue_actions.py rename to tests/sentry/sentry_apps/api/endpoints/test_sentry_app_installation_external_issue_actions.py diff --git a/tests/sentry/api/endpoints/test_sentry_app_installation_external_issue_details.py b/tests/sentry/sentry_apps/api/endpoints/test_sentry_app_installation_external_issue_details.py similarity index 100% rename from tests/sentry/api/endpoints/test_sentry_app_installation_external_issue_details.py rename to tests/sentry/sentry_apps/api/endpoints/test_sentry_app_installation_external_issue_details.py diff --git a/tests/sentry/api/endpoints/test_sentry_app_installation_external_issues.py b/tests/sentry/sentry_apps/api/endpoints/test_sentry_app_installation_external_issues.py similarity index 100% rename from tests/sentry/api/endpoints/test_sentry_app_installation_external_issues.py rename to tests/sentry/sentry_apps/api/endpoints/test_sentry_app_installation_external_issues.py diff --git a/tests/sentry/api/endpoints/test_sentry_app_installation_external_requests.py b/tests/sentry/sentry_apps/api/endpoints/test_sentry_app_installation_external_requests.py similarity index 100% rename from tests/sentry/api/endpoints/test_sentry_app_installation_external_requests.py rename to tests/sentry/sentry_apps/api/endpoints/test_sentry_app_installation_external_requests.py