feat(workspace-vars): add workspace scoped environment + fix cancellation of assoc. workspace invites if org invite cancelled#1208
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR implements workspace-scoped environment variables that take precedence over personal environment variables, along with a bug fix for workspace invitation cancellation. The changes introduce a hierarchical environment variable system where workspace-level variables override personal ones during workflow execution.
The implementation adds a new workspace_environment database table to store workspace-scoped environment variables, following the same encryption patterns as personal environment variables but scoped to workspaces. The system maintains backward compatibility by continuing to support personal environment variables while adding workspace-level overrides.
Key architectural changes include:
- New API endpoints at
/api/workspaces/[id]/environmentfor CRUD operations on workspace environment variables - Updated environment store with three new methods:
loadWorkspaceEnvironment,upsertWorkspaceEnvironment, andremoveWorkspaceEnvironmentKeys - Enhanced workflow execution across all contexts (manual, scheduled, webhook, chat) to load both personal and workspace variables with workspace taking precedence
- New utility functions in
lib/environment/utils.tsfor merging environment variables with conflict detection - UI updates to the settings modal allowing users to manage workspace variables and promote personal variables to workspace scope
The workspace invitation fix addresses a data consistency issue by adding an orgInvitationId column to link workspace invitations with their parent organization invitations. This enables proper cascading cancellation when organization invitations are cancelled, preventing orphaned workspace invitations.
The changes integrate seamlessly with the existing workspace-based architecture, where workflows, chats, and other resources are already scoped to workspaces. This enables teams to share common environment configurations while maintaining individual personal overrides.
Confidence score: 2/5
- This PR has significant implementation inconsistencies and potential issues that could cause problems in production
- Score lowered due to type safety violations, inconsistent API implementation patterns, and critical logic bugs in invitation handling
- Pay close attention to
apps/sim/app/api/workspaces/[id]/environment/route.tsandapps/sim/app/api/organizations/invitations/accept/route.tsfor type assertions and inconsistent invitation logic
Context used:
Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)
24 files reviewed, 8 comments
...pp/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/settings-modal.tsx
Outdated
Show resolved
Hide resolved
...aceId]/w/components/sidebar/components/settings-modal/components/environment/environment.tsx
Outdated
Show resolved
Hide resolved
...aceId]/w/components/sidebar/components/settings-modal/components/environment/environment.tsx
Outdated
Show resolved
Hide resolved
…rkspace invites are created
…on workspace invitation accept
029c460 to
f032bdb
Compare
…tion of assoc. workspace invites if org invite cancelled (#1208) * feat(env-vars): workspace scoped environment variables * fix cascade delete or workspace invite if org invite with attached workspace invites are created * remove redundant refetch * feat(env-vars): workspace scoped environment variables * fix redirect for invitation error, remove check for validated emails on workspace invitation accept * styling improvements * remove random migration code * stronger typing, added helpers, parallelized envvar encryption --------- Co-authored-by: waleedlatif1 <walif6@gmail.com>
…tion of assoc. workspace invites if org invite cancelled (simstudioai#1208) * feat(env-vars): workspace scoped environment variables * fix cascade delete or workspace invite if org invite with attached workspace invites are created * remove redundant refetch * feat(env-vars): workspace scoped environment variables * fix redirect for invitation error, remove check for validated emails on workspace invitation accept * styling improvements * remove random migration code * stronger typing, added helpers, parallelized envvar encryption --------- Co-authored-by: waleedlatif1 <walif6@gmail.com>
Summary
Keeping migrations separate for clean separation of concerns.
Type of Change
Testing
In Progress
Checklist
Screenshots
Regular view:

Naming Conflict:

Trying to Save with naming conflict:

Tooltip for making a var workspace scoped:

Envvar dropdown that shows set of all available envvars:
