Skip to content

PY-76: Möglichkeit default Workspace zu setzen#91

Open
kaesetoast wants to merge 1 commit into
mainfrom
py-76-moglichkeit-default-workspace-zu-setzen
Open

PY-76: Möglichkeit default Workspace zu setzen#91
kaesetoast wants to merge 1 commit into
mainfrom
py-76-moglichkeit-default-workspace-zu-setzen

Conversation

@kaesetoast

@kaesetoast kaesetoast commented Jul 17, 2026

Copy link
Copy Markdown
Member

Task

PY-76: Möglichkeit default Workspace zu setzen

Summary

Summary by CodeRabbit

  • New Features

    • Remembers the last active workspace and restores it when signing in.
    • Automatically switches to the appropriate workspace when opening workspace links.
    • Activates the relevant workspace after accepting an invitation.
    • Falls back to Personal when a saved workspace is no longer accessible.
  • Bug Fixes

    • Prevents inaccessible or outdated workspace selections from being restored.
  • Tests

    • Added coverage for workspace restoration, deep links, membership validation, and Personal fallback.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds last-active organization preferences, server persistence, session restoration, centralized workspace resolution, and activation updates for organization switching, route hints, and invitation acceptance.

Changes

Last active organization

Layer / File(s) Summary
Workspace resolution rules
src/lib/last-active-organization.ts, src/lib/last-active-organization.test.ts
Adds pure helpers for selecting valid last-active organizations and resolving workspace activation from route hints, with coverage for membership and personal-workspace cases.
Preference persistence and session restoration
src/db/schema.ts, src/lib/last-active-organization.server.ts, src/db/mutations/last-active-organization.ts, src/lib/auth.ts
Stores the last active organization in user preferences, exposes a validated POST mutation, resolves stale memberships, and injects the resolved organization into newly created sessions.
Route-driven organization activation
src/lib/ensure-active-organization.server.ts
Uses centralized route-hint resolution and membership checks before activating and persisting the selected organization.
Organization switch persistence
src/hooks/use-organization-switch.ts
Persists successful organization switches and logs persistence failures without interrupting the switch flow.
Invitation organization activation
src/lib/invitation-accept.ts
Carries organization IDs through invitation results and activates and persists the organization during invitation acceptance or already-member handling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • pnodev/project-y#7: Refactors the authentication setup that this change extends with session-based organization restoration.
  • pnodev/project-y#51: Overlaps with the route-based active-organization activation flow.
  • pnodev/project-y#61: Introduces the organization-switching hook extended here with persistence.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is related to the workspace-selection change, though it doesn't mention that it restores the last used workspace after login.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch py-76-moglichkeit-default-workspace-zu-setzen

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/lib/invitation-accept.ts (1)

170-184: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Isolate organization activation to prevent partial failure errors.

If activateInvitedOrganization throws an error, it is currently caught by the outer try...catch block. This means if a user successfully accepts an invitation but the subsequent activation fails, they will see an error page instead of being redirected to the dashboard. Retrying the acceptance will then fail because they are already a member, resulting in a broken user flow.

Wrap the activation step in its own try...catch block (similar to the already_member branch) so that non-critical activation errors do not break the main invitation acceptance flow.

🐛 Proposed fix
-  try {
-    await acceptResolvedInvitation(resolved.invitationId);
-    await activateInvitedOrganization(
-      session.user.id,
-      resolved.organizationId
-    );
-    return { status: "success", redirectTo: "/dashboard" };
-  } catch (error) {
-    console.error("Failed to accept invitation", error);
-    return {
-      status: "error",
-      email: session.user.email,
-      message: mapAcceptApiError(error),
-    };
-  }
+  try {
+    await acceptResolvedInvitation(resolved.invitationId);
+  } catch (error) {
+    console.error("Failed to accept invitation", error);
+    return {
+      status: "error",
+      email: session.user.email,
+      message: mapAcceptApiError(error),
+    };
+  }
+
+  try {
+    await activateInvitedOrganization(
+      session.user.id,
+      resolved.organizationId
+    );
+  } catch (error) {
+    console.error("Failed to activate invited organization", error);
+  }
+
+  return { status: "success", redirectTo: "/dashboard" };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/invitation-accept.ts` around lines 170 - 184, Isolate
activateInvitedOrganization from the outer invitation-acceptance error path by
wrapping it in its own try/catch, following the handling used in the
already_member branch. Preserve the successful accept flow by returning the
dashboard redirect even when activation fails, while keeping
acceptResolvedInvitation failures handled by the existing outer catch.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/lib/invitation-accept.ts`:
- Around line 170-184: Isolate activateInvitedOrganization from the outer
invitation-acceptance error path by wrapping it in its own try/catch, following
the handling used in the already_member branch. Preserve the successful accept
flow by returning the dashboard redirect even when activation fails, while
keeping acceptResolvedInvitation failures handled by the existing outer catch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 729cadf1-5ad7-4f5e-861b-2039e544e70a

📥 Commits

Reviewing files that changed from the base of the PR and between b3dfb9c and 216eadb.

📒 Files selected for processing (9)
  • src/db/mutations/last-active-organization.ts
  • src/db/schema.ts
  • src/hooks/use-organization-switch.ts
  • src/lib/auth.ts
  • src/lib/ensure-active-organization.server.ts
  • src/lib/invitation-accept.ts
  • src/lib/last-active-organization.server.ts
  • src/lib/last-active-organization.test.ts
  • src/lib/last-active-organization.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant