Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(subscribers): guests subscribe and unsubscribe only themselves (MUL-9869) (#11202)

Jiayuan Zhangcb43d70e3336
diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsx
index 32af0b4358..3180e65541 100644
--- a/packages/views/issues/components/issue-detail.test.tsx
+++ b/packages/views/issues/components/issue-detail.test.tsx
@@ -94,7 +94,7 @@ vi.mock("@multica/core/workspace/hooks", () => ({
vi.mock("@multica/core/workspace/queries", () => ({
memberListOptions: () => ({
queryKey: ["workspaces", "ws-1", "members"],
- queryFn: () => Promise.resolve([{ user_id: "user-1", name: "Test User", email: "[email protected]", role: "admin" }]),
+ queryFn: () => mockApiObj.listMembers(),
}),
agentListOptions: () => ({
queryKey: ["workspaces", "ws-1", "agents"],
@@ -4612,6 +4612,30 @@ describe("IssueDetail (shared)", () => {
});
});
+ // A guest changes only its own subscription (MUL-9869): it sees who follows
+ // the issue, but gets no picker that would subscribe someone else.
+ it("shows a guest the subscribers without the picker", async () => {
+ mockApiObj.listMembers.mockResolvedValue([
+ { user_id: "user-1", name: "Test User", email: "[email protected]", role: "guest" },
+ ]);
+ mockApiObj.listIssueSubscribers.mockResolvedValue([
+ {
+ issue_id: "issue-1",
+ user_type: "agent" as const,
+ user_id: "agent-1",
+ reason: "manual" as const,
+ created_at: "2026-01-01T00:00:00Z",
+ },
+ ]);
+ renderIssueDetail();
+
+ expect(await screen.findByText("Subscribe")).toBeTruthy();
+ const header = (await screen.findByText("Activity")).parentElement?.parentElement;
+ await waitFor(() => expect(header?.querySelector('[data-slot="avatar-group"]')).not.toBeNull());
+ expect(header?.querySelector('[data-trigger="popover"]')).toBeNull();
+ document.body.innerHTML = "";
+ });
+
it("keeps the initial assignment block before a later mention and its run (MUL-7632)", async () => {
const assignment: AgentTask = {
id: "initial-assignment", agent_id: "agent-1", runtime_id: "rt-1", issue_id: "issue-1",
diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsx
index 1a7f0f1f11..3f6a72e504 100644
--- a/packages/views/issues/components/issue-detail.tsx
+++ b/packages/views/issues/components/issue-detail.tsx
@@ -84,7 +84,7 @@ import { PropRow } from "../../common/prop-row";
import { useIsGuest } from "@multica/core/permissions";
import { TimelineHandoff } from "../../workflows/timeline-handoff";
import { PropertyIcon } from "../../common/property-icon";
-import type { Attachment, InboxItem, Issue, IssueProperty, IssueStatus, IssueStatusCategory, IssuePriority, TimelineEntry, UpdateIssueRequest } from "@multica/core/types";
+import type { Attachment, InboxItem, Issue, IssueProperty, IssueStatus, IssueStatusCategory, IssuePriority, IssueSubscriber, TimelineEntry, UpdateIssueRequest } from "@multica/core/types";
import { contentReferencesAttachment } from "@multica/core/types";
import { commentLandingTarget, isDeletedComment } from "@multica/core/issues/comment-deletion";
import { formatDateOnly, isPastDateOnly } from "@multica/core/issues/date";
@@ -249,6 +249,25 @@ export function issueHighlightMementoKey(issueId: string): string {
const SUBSCRIPTION_ACTION_CLASS =
"text-label text-muted-foreground hover:text-foreground transition-colors disabled:pointer-events-none disabled:opacity-50";
+function SubscriberAvatars({ subscribers }: { subscribers: IssueSubscriber[] }) {
+ return (
+ <AvatarGroup>
+ {subscribers.slice(0, 4).map((sub) => (
+ <ActorAvatar
+ key={`${sub.user_type}-${sub.user_id}`}
+ actorType={sub.user_type}
+ actorId={sub.user_id}
+ size="md"
+ enableHoverCard
+ />
+ ))}
+ {subscribers.length > 4 && (
+ <AvatarGroupCount>+{subscribers.length - 4}</AvatarGroupCount>
+ )}
+ </AvatarGroup>
+ );
+}
+
function SubscriberPopoverContent({
members,
agents,
@@ -4405,40 +4424,33 @@ export function IssueDetail({ issueId, onDelete, onArchive, onUnsubscribeArchive
</DropdownMenuContent>
</DropdownMenu>
))}
- <Popover>
- <PopoverTrigger className="cursor-pointer hover:opacity-80 transition-opacity">
- {subscribers.length > 0 ? (
- <AvatarGroup>
- {subscribers.slice(0, 4).map((sub) => (
- <ActorAvatar
- key={`${sub.user_type}-${sub.user_id}`}
- actorType={sub.user_type}
- actorId={sub.user_id}
- size="md"
- enableHoverCard
- />
- ))}
- {subscribers.length > 4 && (
- <AvatarGroupCount>+{subscribers.length - 4}</AvatarGroupCount>
- )}
- </AvatarGroup>
- ) : (
- <span className="flex items-center justify-center h-6 w-6 rounded-full border border-dashed border-muted-foreground/30 text-muted-foreground">
- <Users className="h-3 w-3" />
- </span>
- )}
- </PopoverTrigger>
- <SubscriberPopoverContent
- members={members}
- agents={agents}
- subscribers={subscribers}
- toggleSubscriber={toggleSubscriber}
- togglesDisabled={
- !subscriptionKnown || togglePending || !user?.id
- }
- t={t}
- />
- </Popover>
+ {/* A guest sees who follows the issue but changes only its own
+ subscription; the server refuses the rest. */}
+ {guest ? (
+ subscribers.length > 0 && <SubscriberAvatars subscribers={subscribers} />
+ ) : (
+ <Popover>
+ <PopoverTrigger className="cursor-pointer hover:opacity-80 transition-opacity">
+ {subscribers.length > 0 ? (
+ <SubscriberAvatars subscribers={subscribers} />
+ ) : (
+ <span className="flex items-center justify-center h-6 w-6 rounded-full border border-dashed border-muted-foreground/30 text-muted-foreground">
+ <Users className="h-3 w-3" />
+ </span>
+ )}
+ </PopoverTrigger>
+ <SubscriberPopoverContent
+ members={members}
+ agents={agents}
+ subscribers={subscribers}
+ toggleSubscriber={toggleSubscriber}
+ togglesDisabled={
+ !subscriptionKnown || togglePending || !user?.id
+ }
+ t={t}
+ />
+ </Popover>
+ )}
</div>
</div>
diff --git a/server/internal/handler/guest_boundaries_test.go b/server/internal/handler/guest_boundaries_test.go
index bad1f9747a..67e4d88571 100644
--- a/server/internal/handler/guest_boundaries_test.go
+++ b/server/internal/handler/guest_boundaries_test.go
@@ -504,6 +504,61 @@ func TestGuestUnsubscribesItselfFromASubtree(t *testing.T) {
}
}
+// A guest subscribes and unsubscribes itself only: subscribing a member
+// notifies them, and unsubscribing one hides replies and mentions from them.
+// A member may still change anyone's subscription.
+func TestGuestChangesOnlyItsOwnSubscription(t *testing.T) {
+ f := newGuestFixture(t)
+ agent := dbfx.Agent(t, f.marker+" watcher", "")
+ t.Cleanup(func() {
+ dbfx.Exec(t, `DELETE FROM issue_subscriber WHERE issue_id = $1`, f.sharedIssue)
+ })
+ subscribed := func(userType, user string) bool {
+ t.Helper()
+ var n int
+ dbfx.QueryRow(t, `SELECT count(*) FROM issue_subscriber
+ WHERE issue_id = $1 AND user_type = $2 AND user_id = $3 AND unsubscribed_at IS NULL`,
+ f.sharedIssue, userType, user).Scan(&n)
+ return n > 0
+ }
+ post := func(h http.HandlerFunc, suffix string, body any) *testutil.Response {
+ t.Helper()
+ return guestRequest(t, h, f.guest, http.MethodPost, "/api/issues/"+f.sharedIssue+suffix, body, "id", f.sharedIssue)
+ }
+ target := func(userType, user string) map[string]string {
+ return map[string]string{"user_id": user, "user_type": userType}
+ }
+
+ post(testHandler.SubscribeToIssue, "/subscribe", target("member", testUserID)).Want(http.StatusForbidden)
+ post(testHandler.SubscribeToIssue, "/subscribe", target("agent", agent)).Want(http.StatusForbidden)
+ if subscribed("member", testUserID) || subscribed("agent", agent) {
+ t.Fatal("a guest subscribed someone else")
+ }
+
+ dbfx.Exec(t, `INSERT INTO issue_subscriber (issue_id, user_type, user_id, reason) VALUES ($1, 'member', $2, 'commenter')`,
+ f.sharedIssue, testUserID)
+ post(testHandler.UnsubscribeFromIssue, "/unsubscribe", target("member", testUserID)).Want(http.StatusForbidden)
+ if !subscribed("member", testUserID) {
+ t.Fatal("a guest unsubscribed a member")
+ }
+
+ post(testHandler.SubscribeToIssue, "/subscribe", target("member", f.guest)).Want(http.StatusOK)
+ if !subscribed("member", f.guest) {
+ t.Fatal("the guest could not subscribe itself")
+ }
+ post(testHandler.UnsubscribeFromIssue, "/unsubscribe", target("member", strings.ToUpper(f.guest))).Want(http.StatusOK)
+ if subscribed("member", f.guest) {
+ t.Fatal("the guest could not unsubscribe itself")
+ }
+
+ asMember := withURLParams(newRequest(http.MethodPost, "/api/issues/"+f.sharedIssue+"/subscribe",
+ target("member", f.guest)), "id", f.sharedIssue)
+ testutil.Call(t, inboxWorkspaceHandler(testHandler.SubscribeToIssue), asMember).Want(http.StatusOK)
+ if !subscribed("member", f.guest) {
+ t.Fatal("a member could not subscribe someone else")
+ }
+}
+
// A guest settles the auto-archive prompt its Inbox shows it.
func TestGuestResolvesAutoArchivePrompt(t *testing.T) {
f := newGuestFixture(t)
diff --git a/server/internal/handler/subscriber.go b/server/internal/handler/subscriber.go
index 1cd84e34cc..e46576b863 100644
--- a/server/internal/handler/subscriber.go
+++ b/server/internal/handler/subscriber.go
@@ -199,6 +199,9 @@ func (h *Handler) SubscribeToIssue(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusForbidden, "target user is not a member of this workspace")
return
}
+ if h.refuseGuestForOthers(w, r, workspaceID, callerActorType, callerActorID, targetUserType, targetUserID) {
+ return
+ }
// Explicit action, so this CLEARS any earlier opt-out tombstone — the user
// is overriding their own unsubscribe. Rule-driven subscribes deliberately
@@ -224,6 +227,22 @@ func (h *Handler) SubscribeToIssue(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, map[string]bool{"subscribed": true})
}
+// refuseGuestForOthers writes a 403 when a guest targets a subscription other
+// than its own. Subscribing a member notifies them and unsubscribing one hides
+// replies and mentions from them, and a subtree may reach past the guest's
+// projects: none of that is a guest's to decide for someone else. Both ids
+// must already have passed isWorkspaceEntity, as parseUUID panics otherwise.
+func (h *Handler) refuseGuestForOthers(w http.ResponseWriter, r *http.Request, workspaceID, callerType, callerID, targetType, targetID string) bool {
+ if targetType == callerType && uuidToString(parseUUID(targetID)) == uuidToString(parseUUID(callerID)) {
+ return false
+ }
+ if !h.isGuest(r, workspaceID, requestUserID(r)) {
+ return false
+ }
+ writeError(w, http.StatusForbidden, "guests can only change their own subscription")
+ return true
+}
+
// UnsubscribeFromIssue removes a user's subscription from an issue.
// If request body contains user_id, unsubscribes that user; otherwise unsubscribes the caller.
func (h *Handler) UnsubscribeFromIssue(w http.ResponseWriter, r *http.Request) {
@@ -285,11 +304,7 @@ func (h *Handler) unsubscribeFromIssue(w http.ResponseWriter, r *http.Request, s
// (MUL-5483 review round 8).
targetUserID = uuidToString(parseUUID(targetUserID))
- // A guest leaves a tree for itself only: the tree may reach past its
- // projects, and other people's subscriptions there are not its to change.
- if subtree && (targetUserType != callerActorType || targetUserID != uuidToString(parseUUID(callerActorID))) &&
- h.isGuest(r, workspaceID, requestUserID(r)) {
- writeError(w, http.StatusForbidden, "guests can only unsubscribe themselves")
+ if h.refuseGuestForOthers(w, r, workspaceID, callerActorType, callerActorID, targetUserType, targetUserID) {
return
}