Skip to content

Commit

Permalink
update typing to accept RpcUser
Browse files Browse the repository at this point in the history
  • Loading branch information
Christinarlong committed Sep 21, 2024
1 parent cd07b84 commit fa5f862
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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 @@ -91,9 +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
), f"user must be authenticated to create a SentryAppInstallation, currently is {type(request.user)}"
assert isinstance(request.user, User) or isinstance(
request.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)
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

0 comments on commit fa5f862

Please sign in to comment.