Browse Source

chore(actor) Update usage of RpcActor -> Actor (#70575)

Complete the rename of RpcActor to Actor by updating all usage and
removing the shim path.
Mark Story 10 months ago
parent
commit
e311537fb4

+ 2 - 4
src/sentry/api/endpoints/event_owners.py

@@ -9,7 +9,7 @@ from sentry.api.bases.project import ProjectEndpoint
 from sentry.api.serializers import serialize
 from sentry.api.serializers.models.actor import ActorSerializer
 from sentry.models.projectownership import ProjectOwnership
-from sentry.services.hybrid_cloud.actor import RpcActor
+from sentry.types.actor import Actor
 
 
 @region_silo_endpoint
@@ -40,9 +40,7 @@ class EventOwnersEndpoint(ProjectEndpoint):
         if owners == ProjectOwnership.Everyone:
             owners = []
 
-        serialized_owners = serialize(
-            RpcActor.resolve_many(owners), request.user, ActorSerializer()
-        )
+        serialized_owners = serialize(Actor.resolve_many(owners), request.user, ActorSerializer())
 
         # Make sure the serialized owners are in the correct order
         ordered_owners = []

+ 2 - 2
src/sentry/api/endpoints/organization_unsubscribe.py

@@ -20,8 +20,8 @@ from sentry.notifications.types import (
     NotificationSettingEnum,
     NotificationSettingsOptionEnum,
 )
-from sentry.services.hybrid_cloud.actor import ActorType, RpcActor
 from sentry.services.hybrid_cloud.notifications.service import notifications_service
+from sentry.types.actor import Actor, ActorType
 
 T = TypeVar("T", bound=BaseModel)
 
@@ -103,7 +103,7 @@ class OrganizationUnsubscribeProject(OrganizationUnsubscribeBase[Project]):
 
     def unsubscribe(self, request: Request, instance: Project):
         notifications_service.update_notification_options(
-            actor=RpcActor(id=request.user.pk, actor_type=ActorType.USER),
+            actor=Actor(id=request.user.pk, actor_type=ActorType.USER),
             type=NotificationSettingEnum.ISSUE_ALERTS,
             scope_type=NotificationScopeEnum.PROJECT,
             scope_identifier=instance.id,

+ 2 - 2
src/sentry/api/endpoints/project_rule_details.py

@@ -43,9 +43,9 @@ from sentry.models.team import Team
 from sentry.models.user import User
 from sentry.rules.actions import trigger_sentry_app_action_creators_for_issues
 from sentry.rules.actions.utils import get_changed_data, get_updated_rule_data
-from sentry.services.hybrid_cloud.actor import RpcActor
 from sentry.signals import alert_rule_edited
 from sentry.tasks.integrations.slack import find_channel_id_for_rule
+from sentry.types.actor import Actor
 from sentry.utils import metrics
 
 logger = logging.getLogger(__name__)
@@ -235,7 +235,7 @@ class ProjectRuleDetailsEndpoint(RuleEndpoint):
         if rule.environment_id:
             rule_data_before["environment_id"] = rule.environment_id
         if rule.owner_team_id or rule.owner_user_id:
-            rule_data_before["owner"] = RpcActor.from_id(
+            rule_data_before["owner"] = Actor.from_id(
                 user_id=rule.owner_user_id, team_id=rule.owner_team_id
             )
         rule_data_before["label"] = rule.label

+ 2 - 2
src/sentry/api/fields/actor.py

@@ -4,7 +4,7 @@ from drf_spectacular.types import OpenApiTypes
 from drf_spectacular.utils import extend_schema_field
 from rest_framework import serializers
 
-from sentry.services.hybrid_cloud.actor import RpcActor, parse_and_validate_actor
+from sentry.types.actor import Actor, parse_and_validate_actor
 
 
 @extend_schema_field(field=OpenApiTypes.STR)
@@ -15,5 +15,5 @@ class ActorField(serializers.Field):
     def to_representation(self, value):
         return value.identifier
 
-    def to_internal_value(self, data) -> RpcActor | None:
+    def to_internal_value(self, data) -> Actor | None:
         return parse_and_validate_actor(data, self.context["organization"].id)

+ 5 - 5
src/sentry/api/helpers/group_index/update.py

@@ -46,13 +46,13 @@ from sentry.models.release import Release, follows_semver_versioning_scheme
 from sentry.models.user import User
 from sentry.notifications.types import SUBSCRIPTION_REASON_MAP, GroupSubscriptionReason
 from sentry.services.hybrid_cloud import coerce_id_from
-from sentry.services.hybrid_cloud.actor import ActorType, RpcActor
 from sentry.services.hybrid_cloud.user import RpcUser
 from sentry.services.hybrid_cloud.user.service import user_service
 from sentry.services.hybrid_cloud.user_option import user_option_service
 from sentry.signals import issue_resolved
 from sentry.tasks.integrations import kick_off_status_syncs
 from sentry.types.activity import ActivityType
+from sentry.types.actor import Actor, ActorType
 from sentry.types.group import SUBSTATUS_UPDATE_CHOICES, GroupSubStatus, PriorityLevel
 from sentry.utils import metrics
 
@@ -106,10 +106,10 @@ def handle_discard(
 
 def self_subscribe_and_assign_issue(
     acting_user: User | RpcUser | None, group: Group, self_assign_issue: str
-) -> RpcActor | None:
+) -> Actor | None:
     # Used during issue resolution to assign to acting user
     # returns None if the user didn't elect to self assign on resolution
-    # or the group is assigned already, otherwise returns RpcActor
+    # or the group is assigned already, otherwise returns Actor
     # representation of current user
     if acting_user:
         GroupSubscription.objects.subscribe(
@@ -117,7 +117,7 @@ def self_subscribe_and_assign_issue(
         )
 
         if self_assign_issue == "1" and not group.assignee_set.exists():
-            return RpcActor(id=acting_user.id, actor_type=ActorType.USER)
+            return Actor(id=acting_user.id, actor_type=ActorType.USER)
     return None
 
 
@@ -841,7 +841,7 @@ def handle_is_public(
 
 
 def handle_assigned_to(
-    assigned_actor: RpcActor,
+    assigned_actor: Actor,
     assigned_by: str | None,
     integration: str | None,
     group_list: list[Group],

+ 2 - 2
src/sentry/api/helpers/group_index/validators/group.py

@@ -5,7 +5,7 @@ from rest_framework import serializers
 
 from sentry.api.fields import ActorField
 from sentry.models.group import STATUS_UPDATE_CHOICES
-from sentry.services.hybrid_cloud.actor import RpcActor
+from sentry.types.actor import Actor
 from sentry.types.group import SUBSTATUS_UPDATE_CHOICES, PriorityLevel
 
 from . import InboxDetailsValidator, StatusDetailsValidator
@@ -49,7 +49,7 @@ class GroupValidator(serializers.Serializer):
     # for the moment, the CLI sends this for any issue update, so allow nulls
     snoozeDuration = serializers.IntegerField(allow_null=True)
 
-    def validate_assignedTo(self, value: RpcActor) -> RpcActor:
+    def validate_assignedTo(self, value: Actor) -> Actor:
         if (
             value
             and value.is_user

+ 2 - 2
src/sentry/api/serializers/models/alert_rule.py

@@ -26,11 +26,11 @@ from sentry.incidents.models.incident import Incident
 from sentry.models.rule import Rule
 from sentry.models.rulesnooze import RuleSnooze
 from sentry.models.user import User
-from sentry.services.hybrid_cloud.actor import RpcActor
 from sentry.services.hybrid_cloud.app import app_service
 from sentry.services.hybrid_cloud.user import RpcUser
 from sentry.services.hybrid_cloud.user.service import user_service
 from sentry.snuba.models import SnubaQueryEventType
+from sentry.types.actor import Actor
 
 logger = logging.getLogger(__name__)
 
@@ -198,7 +198,7 @@ class AlertRuleSerializer(Serializer):
             result[item]["activations"] = serialize(activations, **kwargs)
 
             if item.user_id or item.team_id:
-                actor = RpcActor.from_id(user_id=item.user_id, team_id=item.team_id)
+                actor = Actor.from_id(user_id=item.user_id, team_id=item.team_id)
                 result[item]["owner"] = actor.identifier
 
         if "original_alert_rule" in self.expand:

+ 2 - 2
src/sentry/api/serializers/models/rule.py

@@ -9,8 +9,8 @@ from sentry.models.environment import Environment
 from sentry.models.rule import NeglectedRule, Rule, RuleActivity, RuleActivityType
 from sentry.models.rulefirehistory import RuleFireHistory
 from sentry.models.rulesnooze import RuleSnooze
-from sentry.services.hybrid_cloud.actor import RpcActor
 from sentry.services.hybrid_cloud.user.service import user_service
+from sentry.types.actor import Actor
 
 
 def generate_rule_label(project, rule, data):
@@ -132,7 +132,7 @@ class RuleSerializer(Serializer):
 
         for rule in rules.values():
             if rule.owner_team_id or rule.owner_user_id:
-                actor = RpcActor.from_id(user_id=rule.owner_user_id, team_id=rule.owner_team_id)
+                actor = Actor.from_id(user_id=rule.owner_user_id, team_id=rule.owner_team_id)
                 result[rule]["owner"] = actor.identifier
 
             for action in rule.data.get("actions", []):

+ 4 - 4
src/sentry/api/serializers/rest_framework/mentions.py

@@ -7,21 +7,21 @@ from rest_framework import serializers
 from sentry.models.organizationmember import OrganizationMember
 from sentry.models.organizationmemberteam import OrganizationMemberTeam
 from sentry.models.team import Team
-from sentry.services.hybrid_cloud.actor import RpcActor
 from sentry.services.hybrid_cloud.user import RpcUser
 from sentry.services.hybrid_cloud.util import region_silo_function
+from sentry.types.actor import Actor
 
 
 @region_silo_function
 def extract_user_ids_from_mentions(organization_id, mentions):
     """
     Extracts user ids from a set of mentions. Mentions should be a list of
-    `RpcActor` instances. Returns a dictionary with 'users', 'team_users', and 'teams' keys.
+    `Actor` instances. Returns a dictionary with 'users', 'team_users', and 'teams' keys.
     'users' is the user ids for all explicitly mentioned users, 'team_users'
     is all user ids from explicitly mentioned teams, excluding any already
     mentioned users, and 'teams' is the team ids for all explicitly mentioned teams.
     """
-    actors: Sequence[RpcUser | Team] = RpcActor.resolve_many(mentions)
+    actors: Sequence[RpcUser | Team] = Actor.resolve_many(mentions)
     actor_mentions = separate_resolved_actors(actors)
 
     team_user_ids = set(
@@ -42,7 +42,7 @@ def extract_user_ids_from_mentions(organization_id, mentions):
     }
 
 
-def separate_actors(actors: Sequence[RpcActor]):
+def separate_actors(actors: Sequence[Actor]):
     users = [actor for actor in actors if actor.is_user]
     teams = [actor for actor in actors if actor.is_team]
 

+ 8 - 8
src/sentry/digests/utils.py

@@ -16,7 +16,7 @@ from sentry.models.rule import Rule
 from sentry.models.rulesnooze import RuleSnooze
 from sentry.notifications.types import ActionTargetType, FallthroughChoiceType
 from sentry.notifications.utils.participants import get_send_to
-from sentry.services.hybrid_cloud.actor import RpcActor
+from sentry.types.actor import Actor
 from sentry.types.integrations import ExternalProviders
 
 
@@ -69,12 +69,12 @@ def get_digest_as_context(digest: Digest) -> Mapping[str, Any]:
 
 
 def get_events_by_participant(
-    participants_by_provider_by_event: Mapping[Event, Mapping[ExternalProviders, set[RpcActor]]]
-) -> Mapping[RpcActor, set[Event]]:
+    participants_by_provider_by_event: Mapping[Event, Mapping[ExternalProviders, set[Actor]]]
+) -> Mapping[Actor, set[Event]]:
     """Invert a mapping of events to participants to a mapping of participants to events."""
     output = defaultdict(set)
     for event, participants_by_provider in participants_by_provider_by_event.items():
-        participants: set[RpcActor]
+        participants: set[Actor]
         for participants in participants_by_provider.values():
             for participant in participants:
                 output[participant].add(event)
@@ -83,8 +83,8 @@ def get_events_by_participant(
 
 def get_personalized_digests(
     digest: Digest,
-    participants_by_provider_by_event: Mapping[Event, Mapping[ExternalProviders, set[RpcActor]]],
-) -> Mapping[RpcActor, Digest]:
+    participants_by_provider_by_event: Mapping[Event, Mapping[ExternalProviders, set[Actor]]],
+) -> Mapping[Actor, Digest]:
     events_by_participant = get_events_by_participant(participants_by_provider_by_event)
 
     actor_to_digest = {}
@@ -108,7 +108,7 @@ def get_event_from_groups_in_digest(digest: Digest) -> Iterable[Event]:
 
 
 def build_custom_digest(
-    original_digest: Digest, events: Iterable[Event], participant: RpcActor
+    original_digest: Digest, events: Iterable[Event], participant: Actor
 ) -> Digest:
     """Given a digest and a set of events, filter the digest to only records that include the events."""
     user_digest: Digest = {}
@@ -138,7 +138,7 @@ def get_participants_by_event(
     target_type: ActionTargetType = ActionTargetType.ISSUE_OWNERS,
     target_identifier: int | None = None,
     fallthrough_choice: FallthroughChoiceType | None = None,
-) -> Mapping[Event, Mapping[ExternalProviders, set[RpcActor]]]:
+) -> Mapping[Event, Mapping[ExternalProviders, set[Actor]]]:
     """
     This is probably the slowest part in sending digests because we do a lot of
     DB calls while we iterate over every event. It would be great if we could

Some files were not shown because too many files changed in this diff