- Notifications
You must be signed in to change notification settings - Fork926
chore: assign user to multiple orgs in coderdtest user create#13867
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,9 +3,12 @@ package coderdtest_test | ||
import ( | ||
"testing" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/goleak" | ||
"github.com/coder/coder/v2/coderd/coderdtest" | ||
"github.com/coder/coder/v2/coderd/rbac" | ||
) | ||
func TestMain(m *testing.M) { | ||
@@ -27,3 +30,20 @@ func TestNew(t *testing.T) { | ||
_, _ = coderdtest.NewGoogleInstanceIdentity(t, "example", false) | ||
_, _ = coderdtest.NewAWSInstanceIdentity(t, "an-instance") | ||
} | ||
// TestOrganizationMember checks the coderdtest helper can add organization members | ||
// to multiple orgs. | ||
func TestOrganizationMember(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, &coderdtest.Options{}) | ||
owner := coderdtest.CreateFirstUser(t, client) | ||
second := coderdtest.CreateOrganization(t, client, coderdtest.CreateOrganizationOptions{}) | ||
third := coderdtest.CreateOrganization(t, client, coderdtest.CreateOrganizationOptions{}) | ||
// Assign the user to 3 orgs in this 1 statement | ||
_, user := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.ScopedRoleOrgMember(second.ID), rbac.ScopedRoleOrgMember(third.ID)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This is the result of this change. This line creates a new user and assigns them to 3 organizations. Much easier than doing this manually. | ||
require.Len(t, user.OrganizationIDs, 3) | ||
require.ElementsMatch(t, user.OrganizationIDs, []uuid.UUID{owner.OrganizationID, second.ID, third.ID}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -33,10 +33,11 @@ func (api *API) postOrganizationMember(rw http.ResponseWriter, r *http.Request) | ||
user = httpmw.UserParam(r) | ||
auditor = api.Auditor.Load() | ||
aReq, commitAudit = audit.InitRequest[database.AuditableOrganizationMember](rw, &audit.RequestParams{ | ||
OrganizationID: organization.ID, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Noticed these org ID's were missing in the audit logs | ||
Audit: *auditor, | ||
Log: api.Logger, | ||
Request: r, | ||
Action: database.AuditActionCreate, | ||
}) | ||
) | ||
aReq.Old = database.AuditableOrganizationMember{} | ||
@@ -95,10 +96,11 @@ func (api *API) deleteOrganizationMember(rw http.ResponseWriter, r *http.Request | ||
member = httpmw.OrganizationMemberParam(r) | ||
auditor = api.Auditor.Load() | ||
aReq, commitAudit = audit.InitRequest[database.AuditableOrganizationMember](rw, &audit.RequestParams{ | ||
OrganizationID: organization.ID, | ||
Audit: *auditor, | ||
Log: api.Logger, | ||
Request: r, | ||
Action: database.AuditActionDelete, | ||
}) | ||
) | ||
aReq.Old = member.OrganizationMember.Auditable(member.Username) | ||
Uh oh!
There was an error while loading.Please reload this page.