Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 872f4a2

Browse files
committed
fix: assign new oauth users to default org
This is not a final solution, as we eventually want to be able to map to different orgs. This makes it so multi-org does not break oauth/oidc.
1 parent a67362f commit 872f4a2

25 files changed

+191
-37
lines changed

coderd/apidoc/docs.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbauthz/dbauthz.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,12 @@ func (q *querier) GetDERPMeshKey(ctx context.Context) (string, error) {
10161016
return q.db.GetDERPMeshKey(ctx)
10171017
}
10181018

1019+
func (q *querier) GetDefaultOrganization(ctx context.Context) (database.Organization, error) {
1020+
return fetch(q.log, q.auth, func(ctx context.Context, _ any) (database.Organization, error) {
1021+
return q.db.GetDefaultOrganization(ctx)
1022+
})(ctx, nil)
1023+
}
1024+
10191025
func (q *querier) GetDefaultProxyConfig(ctx context.Context) (database.GetDefaultProxyConfigRow, error) {
10201026
// No authz checks
10211027
return q.db.GetDefaultProxyConfig(ctx)

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ func (s *MethodTestSuite) TestOrganization() {
570570
o := dbgen.Organization(s.T(), db, database.Organization{})
571571
check.Args(o.ID).Asserts(o, rbac.ActionRead).Returns(o)
572572
}))
573+
s.Run("GetDefaultOrganization", s.Subtest(func(db database.Store, check *expects) {
574+
o := dbgen.Organization(s.T(), db, database.Organization{})
575+
check.Args().Asserts(o, rbac.ActionRead).Returns(o)
576+
}))
573577
s.Run("GetOrganizationByName", s.Subtest(func(db database.Store, check *expects) {
574578
o := dbgen.Organization(s.T(), db, database.Organization{})
575579
check.Args(o.Name).Asserts(o, rbac.ActionRead).Returns(o)

coderd/database/dbmem/dbmem.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,18 @@ func (q *FakeQuerier) GetDERPMeshKey(_ context.Context) (string, error) {
16571657
return q.derpMeshKey, nil
16581658
}
16591659

1660+
func (q *FakeQuerier) GetDefaultOrganization(_ context.Context) (database.Organization, error) {
1661+
q.mutex.RLock()
1662+
defer q.mutex.RUnlock()
1663+
1664+
for _, org := range q.organizations {
1665+
if org.IsDefault {
1666+
return org, nil
1667+
}
1668+
}
1669+
return database.Organization{}, sql.ErrNoRows
1670+
}
1671+
16601672
func (q *FakeQuerier) GetDefaultProxyConfig(_ context.Context) (database.GetDefaultProxyConfigRow, error) {
16611673
return database.GetDefaultProxyConfigRow{
16621674
DisplayName: q.defaultProxyDisplayName,
@@ -5285,6 +5297,7 @@ func (q *FakeQuerier) InsertOrganization(_ context.Context, arg database.InsertO
52855297
Name: arg.Name,
52865298
CreatedAt: arg.CreatedAt,
52875299
UpdatedAt: arg.UpdatedAt,
5300+
IsDefault: len(q.organizations) == 0,
52885301
}
52895302
q.organizations = append(q.organizations, organization)
52905303
return organization, nil

coderd/database/dbmetrics/dbmetrics.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dump.sql

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)