Skip to content

feat: set groupsync to use default org #12146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "fix: assign new oauth users to default org"
This reverts commit 872f4a2.
  • Loading branch information
Emyrk committed Feb 15, 2024
commit acda012a14165daacce89b1d8df0e38ba52d467c
4 changes: 0 additions & 4 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,12 +1016,6 @@ func (q *querier) GetDERPMeshKey(ctx context.Context) (string, error) {
return q.db.GetDERPMeshKey(ctx)
}

func (q *querier) GetDefaultOrganization(ctx context.Context) (database.Organization, error) {
return fetch(q.log, q.auth, func(ctx context.Context, _ any) (database.Organization, error) {
return q.db.GetDefaultOrganization(ctx)
})(ctx, nil)
}

func (q *querier) GetDefaultProxyConfig(ctx context.Context) (database.GetDefaultProxyConfigRow, error) {
// No authz checks
return q.db.GetDefaultProxyConfig(ctx)
Expand Down
4 changes: 0 additions & 4 deletions coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,6 @@ func (s *MethodTestSuite) TestOrganization() {
o := dbgen.Organization(s.T(), db, database.Organization{})
check.Args(o.ID).Asserts(o, rbac.ActionRead).Returns(o)
}))
s.Run("GetDefaultOrganization", s.Subtest(func(db database.Store, check *expects) {
o := dbgen.Organization(s.T(), db, database.Organization{})
check.Args().Asserts(o, rbac.ActionRead).Returns(o)
}))
s.Run("GetOrganizationByName", s.Subtest(func(db database.Store, check *expects) {
o := dbgen.Organization(s.T(), db, database.Organization{})
check.Args(o.Name).Asserts(o, rbac.ActionRead).Returns(o)
Expand Down
13 changes: 0 additions & 13 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -1657,18 +1657,6 @@ func (q *FakeQuerier) GetDERPMeshKey(_ context.Context) (string, error) {
return q.derpMeshKey, nil
}

func (q *FakeQuerier) GetDefaultOrganization(_ context.Context) (database.Organization, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

for _, org := range q.organizations {
if org.IsDefault {
return org, nil
}
}
return database.Organization{}, sql.ErrNoRows
}

func (q *FakeQuerier) GetDefaultProxyConfig(_ context.Context) (database.GetDefaultProxyConfigRow, error) {
return database.GetDefaultProxyConfigRow{
DisplayName: q.defaultProxyDisplayName,
Expand Down Expand Up @@ -5297,7 +5285,6 @@ func (q *FakeQuerier) InsertOrganization(_ context.Context, arg database.InsertO
Name: arg.Name,
CreatedAt: arg.CreatedAt,
UpdatedAt: arg.UpdatedAt,
IsDefault: len(q.organizations) == 0,
}
q.organizations = append(q.organizations, organization)
return organization, nil
Expand Down
7 changes: 0 additions & 7 deletions coderd/database/dbmetrics/dbmetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions coderd/database/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,34 +494,6 @@ func TestUserChangeLoginType(t *testing.T) {
require.Equal(t, bobExpPass, bob.HashedPassword, "hashed password should not change")
}

func TestDefaultOrg(t *testing.T) {
t.Parallel()
if testing.Short() {
t.SkipNow()
}

sqlDB := testSQLDB(t)
err := migrations.Up(sqlDB)
require.NoError(t, err)
db := database.New(sqlDB)
ctx := context.Background()

// Should start with 0 orgs
all, err := db.GetOrganizations(ctx)
require.NoError(t, err)
require.Len(t, all, 0)

org, err := db.InsertOrganization(ctx, database.InsertOrganizationParams{
ID: uuid.New(),
Name: "default",
Description: "",
CreatedAt: dbtime.Now(),
UpdatedAt: dbtime.Now(),
})
require.NoError(t, err)
require.True(t, org.IsDefault, "first org should always be default")
}

type tvArgs struct {
Status database.ProvisionerJobStatus
// CreateWorkspace is true if we should create a workspace for the template version
Expand Down
43 changes: 6 additions & 37 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 2 additions & 13 deletions coderd/database/queries/organizations.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
-- name: GetDefaultOrganization :one
SELECT
*
FROM
organizations
WHERE
is_default = true
LIMIT
1;

-- name: GetOrganizations :many
SELECT
*
Expand Down Expand Up @@ -49,7 +39,6 @@ WHERE

-- name: InsertOrganization :one
INSERT INTO
organizations (id, "name", description, created_at, updated_at, is_default)
organizations (id, "name", description, created_at, updated_at)
VALUES
-- If no organizations exist, and this is the first, make it the default.
($1, $2, $3, $4, $5, (SELECT TRUE FROM organizations LIMIT 1) IS NULL) RETURNING *;
($1, $2, $3, $4, $5) RETURNING *;
1 change: 0 additions & 1 deletion coderd/database/unique_constraint.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion coderd/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,5 @@ func convertOrganization(organization database.Organization) codersdk.Organizati
Name: organization.Name,
CreatedAt: organization.CreatedAt,
UpdatedAt: organization.UpdatedAt,
IsDefault: organization.IsDefault,
}
}
8 changes: 0 additions & 8 deletions coderd/organizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ func TestOrganizationsByUser(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, orgs)
require.Len(t, orgs, 1)
require.True(t, orgs[0].IsDefault, "first org is always default")

// Make an extra org, and it should not be defaulted.
notDefault, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
Name: "another",
})
require.NoError(t, err)
require.False(t, notDefault.IsDefault, "only 1 default org allowed")
}

func TestOrganizationByUserAndName(t *testing.T) {
Expand Down
15 changes: 8 additions & 7 deletions coderd/userauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1343,12 +1343,13 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
if user.ID == uuid.Nil {
var organizationID uuid.UUID
//nolint:gocritic
organization, _ := tx.GetDefaultOrganization(dbauthz.AsSystemRestricted(ctx))

// Add the user to the default organization.
// Once multi-organization we should check some configuration to see
// if we should add the user to a different organization.
organizationID = organization.ID
organizations, _ := tx.GetOrganizations(dbauthz.AsSystemRestricted(ctx))
if len(organizations) > 0 {
// Add the user to the first organization. Once multi-organization
// support is added, we should enable a configuration map of user
// email to organization.
organizationID = organizations[0].ID
}

//nolint:gocritic
_, err := tx.GetUserByEmailOrUsername(dbauthz.AsSystemRestricted(ctx), database.GetUserByEmailOrUsernameParams{
Expand Down Expand Up @@ -1394,7 +1395,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
// All of the userauth tests depend on this being able to create
// the first organization. It shouldn't be possible in normal
// operation.
CreateOrganization: organizationID == uuid.Nil,
CreateOrganization: len(organizations) == 0,
LoginType: params.LoginType,
})
if err != nil {
Expand Down
Loading