-
Notifications
You must be signed in to change notification settings - Fork 881
chore: add organization member api + cli #13577
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
Changes from all commits
e1a0b0f
3b60247
9aff25d
2db1953
1002c6b
ce367e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,65 @@ import ( | |
"github.com/coder/coder/v2/testutil" | ||
) | ||
|
||
func TestAddMember(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("OK", func(t *testing.T) { | ||
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. I think testing to error cases like missing user and org 404, etc for posterity could be good as well |
||
t.Parallel() | ||
owner := coderdtest.New(t, nil) | ||
first := coderdtest.CreateFirstUser(t, owner) | ||
ctx := testutil.Context(t, testutil.WaitMedium) | ||
org, err := owner.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{ | ||
Name: "other", | ||
DisplayName: "", | ||
Description: "", | ||
Icon: "", | ||
}) | ||
require.NoError(t, err) | ||
|
||
// Make a user not in the second organization | ||
_, user := coderdtest.CreateAnotherUser(t, owner, first.OrganizationID) | ||
|
||
members, err := owner.OrganizationMembers(ctx, org.ID) | ||
require.NoError(t, err) | ||
require.Len(t, members, 1) // Verify just the 1 member | ||
|
||
// Add user to org | ||
_, err = owner.PostOrganizationMember(ctx, org.ID, user.Username) | ||
require.NoError(t, err) | ||
|
||
members, err = owner.OrganizationMembers(ctx, org.ID) | ||
require.NoError(t, err) | ||
// Owner + new member | ||
require.Len(t, members, 2) | ||
require.ElementsMatch(t, | ||
[]uuid.UUID{first.UserID, user.ID}, | ||
db2sdk.List(members, onlyIDs)) | ||
}) | ||
|
||
t.Run("UserNotExists", func(t *testing.T) { | ||
t.Parallel() | ||
owner := coderdtest.New(t, nil) | ||
_ = coderdtest.CreateFirstUser(t, owner) | ||
ctx := testutil.Context(t, testutil.WaitMedium) | ||
|
||
org, err := owner.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{ | ||
Name: "other", | ||
DisplayName: "", | ||
Description: "", | ||
Icon: "", | ||
}) | ||
require.NoError(t, err) | ||
|
||
// Add user to org | ||
_, err = owner.PostOrganizationMember(ctx, org.ID, uuid.NewString()) | ||
require.Error(t, err) | ||
var apiErr *codersdk.Error | ||
require.ErrorAs(t, err, &apiErr) | ||
require.Contains(t, apiErr.Message, "must be an existing") | ||
}) | ||
} | ||
|
||
func TestListMembers(t *testing.T) { | ||
t.Parallel() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a future PR: I think a new permission would be nice here, I don't think it's intuitive for developers to know that a read permission on a site user grants them access to add new org members.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@f0ssel one option is just to not require the read permission to add a user, using the system context to fetch a user.
I agree it is not intuitive at present. Since orgs are still a ways out, I'm not spending too much time on these details atm.