|
@@ -638,29 +638,10 @@ def update_groups(
|
|
|
result["isBookmarked"], group_list, group_ids, project_lookup, acting_user
|
|
|
)
|
|
|
|
|
|
- # TODO(dcramer): we could make these more efficient by first
|
|
|
- # querying for rich rows are present (if N > 2), flipping the flag
|
|
|
- # on those rows, and then creating the missing rows
|
|
|
if result.get("isSubscribed") in (True, False):
|
|
|
- is_subscribed = result["isSubscribed"]
|
|
|
- for group in group_list:
|
|
|
- # NOTE: Subscribing without an initiating event (assignment,
|
|
|
- # commenting, etc.) clears out the previous subscription reason
|
|
|
- # to avoid showing confusing messaging as a result of this
|
|
|
- # action. It'd be jarring to go directly from "you are not
|
|
|
- # subscribed" to "you were subscribed due since you were
|
|
|
- # assigned" just by clicking the "subscribe" button (and you
|
|
|
- # may no longer be assigned to the issue anyway.)
|
|
|
- GroupSubscription.objects.create_or_update(
|
|
|
- user_id=acting_user.id,
|
|
|
- group=group,
|
|
|
- project=project_lookup[group.project_id],
|
|
|
- values={"is_active": is_subscribed, "reason": GroupSubscriptionReason.unknown},
|
|
|
- )
|
|
|
-
|
|
|
- result["subscriptionDetails"] = {
|
|
|
- "reason": SUBSCRIPTION_REASON_MAP.get(GroupSubscriptionReason.unknown, "unknown")
|
|
|
- }
|
|
|
+ result["subscriptionDetails"] = handle_is_subscribed(
|
|
|
+ result["isSubscribed"], group_list, project_lookup, acting_user
|
|
|
+ )
|
|
|
|
|
|
if "isPublic" in result:
|
|
|
result["shareId"] = handle_is_public(
|
|
@@ -700,6 +681,33 @@ def update_groups(
|
|
|
return Response(result)
|
|
|
|
|
|
|
|
|
+def handle_is_subscribed(
|
|
|
+ is_subscribed: bool,
|
|
|
+ group_list: Sequence[Group],
|
|
|
+ project_lookup: dict[int, Any],
|
|
|
+ acting_user: User,
|
|
|
+) -> dict[str, str]:
|
|
|
+ # TODO(dcramer): we could make these more efficient by first
|
|
|
+ # querying for which `GroupSubscription` rows are present (if N > 2),
|
|
|
+ # flipping the flag on those rows, and then creating the missing rows
|
|
|
+ for group in group_list:
|
|
|
+ # NOTE: Subscribing without an initiating event (assignment,
|
|
|
+ # commenting, etc.) clears out the previous subscription reason
|
|
|
+ # to avoid showing confusing messaging as a result of this
|
|
|
+ # action. It'd be jarring to go directly from "you are not
|
|
|
+ # subscribed" to "you were subscribed since you were
|
|
|
+ # assigned" just by clicking the "subscribe" button (and you
|
|
|
+ # may no longer be assigned to the issue anyway).
|
|
|
+ GroupSubscription.objects.create_or_update(
|
|
|
+ user_id=acting_user.id,
|
|
|
+ group=group,
|
|
|
+ project=project_lookup[group.project_id],
|
|
|
+ values={"is_active": is_subscribed, "reason": GroupSubscriptionReason.unknown},
|
|
|
+ )
|
|
|
+
|
|
|
+ return {"reason": SUBSCRIPTION_REASON_MAP.get(GroupSubscriptionReason.unknown, "unknown")}
|
|
|
+
|
|
|
+
|
|
|
def handle_is_bookmarked(
|
|
|
is_bookmarked: bool,
|
|
|
group_list: Sequence[Group],
|