@@ -648,11 +648,11 @@ func CreateFirstUser(t testing.TB, client *codersdk.Client) codersdk.CreateFirst
648
648
// CreateAnotherUser creates and authenticates a new user.
649
649
// Roles can include org scoped roles with 'roleName:<organization_id>'
650
650
func CreateAnotherUser (t testing.TB , client * codersdk.Client , organizationID uuid.UUID , roles ... rbac.RoleIdentifier ) (* codersdk.Client , codersdk.User ) {
651
- return createAnotherUserRetry (t , client , organizationID , 5 , roles )
651
+ return createAnotherUserRetry (t , client , []uuid. UUID { organizationID } , 5 , roles )
652
652
}
653
653
654
- func CreateAnotherUserMutators (t testing.TB , client * codersdk.Client , organizationID uuid.UUID , roles []rbac.RoleIdentifier , mutators ... func (r * codersdk.CreateUserRequest )) (* codersdk.Client , codersdk.User ) {
655
- return createAnotherUserRetry (t , client , organizationID , 5 , roles , mutators ... )
654
+ func CreateAnotherUserMutators (t testing.TB , client * codersdk.Client , organizationID uuid.UUID , roles []rbac.RoleIdentifier , mutators ... func (r * codersdk.CreateUserRequestWithOrgs )) (* codersdk.Client , codersdk.User ) {
655
+ return createAnotherUserRetry (t , client , []uuid. UUID { organizationID } , 5 , roles , mutators ... )
656
656
}
657
657
658
658
// AuthzUserSubject does not include the user's groups.
@@ -678,31 +678,31 @@ func AuthzUserSubject(user codersdk.User, orgID uuid.UUID) rbac.Subject {
678
678
}
679
679
}
680
680
681
- func createAnotherUserRetry (t testing.TB , client * codersdk.Client , organizationID uuid.UUID , retries int , roles []rbac.RoleIdentifier , mutators ... func (r * codersdk.CreateUserRequest )) (* codersdk.Client , codersdk.User ) {
682
- req := codersdk.CreateUserRequest {
683
- Email : namesgenerator .GetRandomName (10 ) + "@coder.com" ,
684
- Username : RandomUsername (t ),
685
- Name : RandomName (t ),
686
- Password : "SomeSecurePassword!" ,
687
- OrganizationID : organizationID ,
681
+ func createAnotherUserRetry (t testing.TB , client * codersdk.Client , organizationIDs [] uuid.UUID , retries int , roles []rbac.RoleIdentifier , mutators ... func (r * codersdk.CreateUserRequestWithOrgs )) (* codersdk.Client , codersdk.User ) {
682
+ req := codersdk.CreateUserRequestWithOrgs {
683
+ Email : namesgenerator .GetRandomName (10 ) + "@coder.com" ,
684
+ Username : RandomUsername (t ),
685
+ Name : RandomName (t ),
686
+ Password : "SomeSecurePassword!" ,
687
+ OrganizationIDs : organizationIDs ,
688
688
}
689
689
for _ , m := range mutators {
690
690
m (& req )
691
691
}
692
692
693
- user , err := client .CreateUser (context .Background (), req )
693
+ user , err := client .CreateUserWithOrgs (context .Background (), req )
694
694
var apiError * codersdk.Error
695
695
// If the user already exists by username or email conflict, try again up to "retries" times.
696
696
if err != nil && retries >= 0 && xerrors .As (err , & apiError ) {
697
697
if apiError .StatusCode () == http .StatusConflict {
698
698
retries --
699
- return createAnotherUserRetry (t , client , organizationID , retries , roles )
699
+ return createAnotherUserRetry (t , client , organizationIDs , retries , roles )
700
700
}
701
701
}
702
702
require .NoError (t , err )
703
703
704
704
var sessionToken string
705
- if req .DisableLogin || req . UserLoginType == codersdk .LoginTypeNone {
705
+ if req .UserLoginType == codersdk .LoginTypeNone {
706
706
// Cannot log in with a disabled login user. So make it an api key from
707
707
// the client making this user.
708
708
token , err := client .CreateToken (context .Background (), user .ID .String (), codersdk.CreateTokenRequest {
@@ -765,8 +765,9 @@ func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationI
765
765
require .NoError (t , err , "update site roles" )
766
766
767
767
// isMember keeps track of which orgs the user was added to as a member
768
- isMember := map [uuid.UUID ]bool {
769
- organizationID : true ,
768
+ isMember := make (map [uuid.UUID ]bool )
769
+ for _ , orgID := range organizationIDs {
770
+ isMember [orgID ] = true
770
771
}
771
772
772
773
// Update org roles
0 commit comments