feat: implement organization "disable workspace sharing" option #21297
+520
−65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
wip: the PR is currently in draft mode to discuss the migration of the org-member role to the DB
Migrating Org-Member Role to Database
Problem
The
organization-memberrole is hardcoded. This makes it easy to keep it in sync with resource types supported by Coder, but prevents per-org customization (e.g.,workspace_sharing_disabled).Solution: Database-Backed System Roles
Store
organization-memberroles per-org in thecustom_rolestable with anis_systemflag. Create the roles during org creation and reconcile them at startup to keep permissions in sync with the codebase.is_systemboolean column to thecustom_rolestable — marks Coder-managed rolesmember_permissions— for member-scoped permissions (resources owned by the user)workspace_sharing_disabledtoorganizations— per-org settingorganization-membersystem roles for all existing organizationsOrgMemberPermissions(workspaceSharingDisabled bool)is the source of truthActionSharewhen disabled)organization-memberrole is created in the same transactionOrgMemberPermissions(false)since new orgs have sharing enabled by defaultReconcileOrgMemberRoles()runs at startup with an advisory lockKey Design Decisions
is_system=truemakes them transparent to the CRUD APIcloses: coder/internal#1073