Skip to content

Commit e6764bc

Browse files
Fixed Invite New User endpoints for organizations and projects (#232)
1 parent ee23c06 commit e6764bc

File tree

6 files changed

+38
-40
lines changed

6 files changed

+38
-40
lines changed

mongodbatlas/organization_invitations.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ func (s *OrganizationsServiceOp) Invitation(ctx context.Context, orgID, invitati
102102
// InviteUser invites one user to the Atlas organization that you specify.
103103
//
104104
// See more: https://docs.atlas.mongodb.com/reference/api/organization-create-one-invitation/
105-
func (s *OrganizationsServiceOp) InviteUser(ctx context.Context, invitation *Invitation) (*Invitation, *Response, error) {
106-
if invitation.OrgID == "" {
105+
func (s *OrganizationsServiceOp) InviteUser(ctx context.Context, orgID string, invitation *Invitation) (*Invitation, *Response, error) {
106+
if orgID == "" {
107107
return nil, nil, NewArgError("orgID", "must be set")
108108
}
109109

110-
path := fmt.Sprintf(invitationBasePath, invitation.OrgID)
110+
path := fmt.Sprintf(invitationBasePath, orgID)
111111

112112
req, err := s.Client.NewRequest(ctx, http.MethodPost, path, invitation)
113113
if err != nil {
@@ -126,29 +126,27 @@ func (s *OrganizationsServiceOp) InviteUser(ctx context.Context, invitation *Inv
126126
// UpdateInvitation updates one pending invitation to the Atlas organization that you specify.
127127
//
128128
// See more: https://docs.atlas.mongodb.com/reference/api/organization-update-one-invitation/
129-
func (s *OrganizationsServiceOp) UpdateInvitation(ctx context.Context, invitation *Invitation) (*Invitation, *Response, error) {
130-
if invitation.OrgID == "" {
129+
func (s *OrganizationsServiceOp) UpdateInvitation(ctx context.Context, orgID string, invitation *Invitation) (*Invitation, *Response, error) {
130+
if orgID == "" {
131131
return nil, nil, NewArgError("orgID", "must be set")
132132
}
133133

134-
return s.updateInvitation(ctx, invitation)
134+
return s.updateInvitation(ctx, orgID, "", invitation)
135135
}
136136

137137
// UpdateInvitationByID updates one invitation to the Atlas organization.
138138
//
139139
// See more: https://docs.atlas.mongodb.com/reference/api/organization-update-one-invitation-by-id/
140-
func (s *OrganizationsServiceOp) UpdateInvitationByID(ctx context.Context, invitationID string, invitation *Invitation) (*Invitation, *Response, error) {
141-
if invitation.OrgID == "" {
140+
func (s *OrganizationsServiceOp) UpdateInvitationByID(ctx context.Context, orgID, invitationID string, invitation *Invitation) (*Invitation, *Response, error) {
141+
if orgID == "" {
142142
return nil, nil, NewArgError("orgID", "must be set")
143143
}
144144

145145
if invitationID == "" {
146146
return nil, nil, NewArgError("invitationID", "must be set")
147147
}
148148

149-
invitation.ID = invitationID
150-
151-
return s.updateInvitation(ctx, invitation)
149+
return s.updateInvitation(ctx, orgID, invitationID, invitation)
152150
}
153151

154152
// DeleteInvitation deletes one unaccepted invitation to the specified Atlas organization. You can't delete an invitation that a user has accepted.
@@ -176,11 +174,11 @@ func (s *OrganizationsServiceOp) DeleteInvitation(ctx context.Context, orgID, in
176174
return resp, err
177175
}
178176

179-
func (s *OrganizationsServiceOp) updateInvitation(ctx context.Context, invitation *Invitation) (*Invitation, *Response, error) {
180-
path := fmt.Sprintf(invitationBasePath, invitation.OrgID)
177+
func (s *OrganizationsServiceOp) updateInvitation(ctx context.Context, orgID, invitationID string, invitation *Invitation) (*Invitation, *Response, error) {
178+
path := fmt.Sprintf(invitationBasePath, orgID)
181179

182-
if invitation.ID != "" {
183-
path = fmt.Sprintf("%s/%s", path, invitation.ID)
180+
if invitationID != "" {
181+
path = fmt.Sprintf("%s/%s", path, invitationID)
184182
}
185183

186184
req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, invitation)

mongodbatlas/organization_invitations_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func TestOrganizations_InviteUser(t *testing.T) {
160160
Roles: []string{"ORG_OWNER"},
161161
}
162162

163-
invitation, _, err := client.Organizations.InviteUser(ctx, body)
163+
invitation, _, err := client.Organizations.InviteUser(ctx, orgID, body)
164164
if err != nil {
165165
t.Fatalf("Organizations.InviteUser returned error: %v", err)
166166
}
@@ -211,7 +211,7 @@ func TestOrganizations_UpdateInvitation(t *testing.T) {
211211
Roles: []string{"ORG_OWNER"},
212212
}
213213

214-
invitation, _, err := client.Organizations.UpdateInvitation(ctx, body)
214+
invitation, _, err := client.Organizations.UpdateInvitation(ctx, orgID, body)
215215
if err != nil {
216216
t.Fatalf("Organizations.UpdateInvitation returned error: %v", err)
217217
}
@@ -263,7 +263,7 @@ func TestOrganizations_UpdateInvitationByID(t *testing.T) {
263263
Roles: []string{"ORG_OWNER"},
264264
}
265265

266-
invitation, _, err := client.Organizations.UpdateInvitationByID(ctx, invitationID, body)
266+
invitation, _, err := client.Organizations.UpdateInvitationByID(ctx, orgID, invitationID, body)
267267
if err != nil {
268268
t.Fatalf("Organizations.UpdateInvitationByID returned error: %v", err)
269269
}

mongodbatlas/organizations.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ type OrganizationsService interface {
3333
Projects(context.Context, string, *ListOptions) (*Projects, *Response, error)
3434
Users(context.Context, string, *ListOptions) (*AtlasUsersResponse, *Response, error)
3535
Delete(context.Context, string) (*Response, error)
36-
InviteUser(context.Context, *Invitation) (*Invitation, *Response, error)
37-
UpdateInvitation(context.Context, *Invitation) (*Invitation, *Response, error)
38-
UpdateInvitationByID(context.Context, string, *Invitation) (*Invitation, *Response, error)
36+
InviteUser(context.Context, string, *Invitation) (*Invitation, *Response, error)
37+
UpdateInvitation(context.Context, string, *Invitation) (*Invitation, *Response, error)
38+
UpdateInvitationByID(context.Context, string, string, *Invitation) (*Invitation, *Response, error)
3939
DeleteInvitation(context.Context, string, string) (*Response, error)
4040
}
4141

mongodbatlas/project_invitations.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ func (s *ProjectsServiceOp) Invitation(ctx context.Context, groupID, invitationI
8080
}
8181

8282
// InviteUser invites one user to the Atlas project that you specify.
83-
func (s *ProjectsServiceOp) InviteUser(ctx context.Context, invitation *Invitation) (*Invitation, *Response, error) {
84-
if invitation.GroupID == "" {
83+
func (s *ProjectsServiceOp) InviteUser(ctx context.Context, groupID string, invitation *Invitation) (*Invitation, *Response, error) {
84+
if groupID == "" {
8585
return nil, nil, NewArgError("groupID", "must be set")
8686
}
8787

88-
path := fmt.Sprintf(projectInvitationBasePath, invitation.GroupID)
88+
path := fmt.Sprintf(projectInvitationBasePath, groupID)
8989

9090
req, err := s.Client.NewRequest(ctx, http.MethodPost, path, invitation)
9191
if err != nil {
@@ -104,19 +104,19 @@ func (s *ProjectsServiceOp) InviteUser(ctx context.Context, invitation *Invitati
104104
// UpdateInvitation updates one pending invitation to the Atlas project that you specify.
105105
//
106106
// See more: https://docs.atlas.mongodb.com/reference/api/project-update-one-invitation/
107-
func (s *ProjectsServiceOp) UpdateInvitation(ctx context.Context, invitation *Invitation) (*Invitation, *Response, error) {
108-
if invitation.GroupID == "" {
107+
func (s *ProjectsServiceOp) UpdateInvitation(ctx context.Context, groupID string, invitation *Invitation) (*Invitation, *Response, error) {
108+
if groupID == "" {
109109
return nil, nil, NewArgError("groupID", "must be set")
110110
}
111111

112-
return s.updateInvitation(ctx, invitation)
112+
return s.updateInvitation(ctx, groupID, "", invitation)
113113
}
114114

115115
// UpdateInvitationByID updates one invitation to the Atlas project.
116116
//
117117
// See more: https://docs.atlas.mongodb.com/reference/api/project-update-one-invitation-by-id/
118-
func (s *ProjectsServiceOp) UpdateInvitationByID(ctx context.Context, invitationID string, invitation *Invitation) (*Invitation, *Response, error) {
119-
if invitation.GroupID == "" {
118+
func (s *ProjectsServiceOp) UpdateInvitationByID(ctx context.Context, groupID, invitationID string, invitation *Invitation) (*Invitation, *Response, error) {
119+
if groupID == "" {
120120
return nil, nil, NewArgError("groupID", "must be set")
121121
}
122122

@@ -126,7 +126,7 @@ func (s *ProjectsServiceOp) UpdateInvitationByID(ctx context.Context, invitation
126126

127127
invitation.ID = invitationID
128128

129-
return s.updateInvitation(ctx, invitation)
129+
return s.updateInvitation(ctx, groupID, invitationID, invitation)
130130
}
131131

132132
// DeleteInvitation deletes one unaccepted invitation to the specified Atlas project. You can't delete an invitation that a user has accepted.
@@ -154,11 +154,11 @@ func (s *ProjectsServiceOp) DeleteInvitation(ctx context.Context, groupID, invit
154154
return resp, err
155155
}
156156

157-
func (s *ProjectsServiceOp) updateInvitation(ctx context.Context, invitation *Invitation) (*Invitation, *Response, error) {
158-
path := fmt.Sprintf(projectInvitationBasePath, invitation.GroupID)
157+
func (s *ProjectsServiceOp) updateInvitation(ctx context.Context, groupID, invitationID string, invitation *Invitation) (*Invitation, *Response, error) {
158+
path := fmt.Sprintf(projectInvitationBasePath, groupID)
159159

160-
if invitation.ID != "" {
161-
path = fmt.Sprintf("%s/%s", path, invitation.ID)
160+
if invitationID != "" {
161+
path = fmt.Sprintf("%s/%s", path, invitationID)
162162
}
163163

164164
req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, invitation)

mongodbatlas/project_invitations_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func TestProjects_InviteUser(t *testing.T) {
158158
Roles: []string{"ORG_OWNER"},
159159
}
160160

161-
invitation, _, err := client.Projects.InviteUser(ctx, body)
161+
invitation, _, err := client.Projects.InviteUser(ctx, groupID, body)
162162
if err != nil {
163163
t.Fatalf("Projects.InviteUser returned error: %v", err)
164164
}
@@ -209,7 +209,7 @@ func TestProjects_UpdateInvitation(t *testing.T) {
209209
Roles: []string{"ORG_OWNER"},
210210
}
211211

212-
invitation, _, err := client.Projects.UpdateInvitation(ctx, body)
212+
invitation, _, err := client.Projects.UpdateInvitation(ctx, groupID, body)
213213
if err != nil {
214214
t.Fatalf("Projects.UpdateInvitation returned error: %v", err)
215215
}
@@ -261,7 +261,7 @@ func TestProjects_UpdateInvitationByID(t *testing.T) {
261261
Roles: []string{"ORG_OWNER"},
262262
}
263263

264-
invitation, _, err := client.Projects.UpdateInvitationByID(ctx, invitationID, body)
264+
invitation, _, err := client.Projects.UpdateInvitationByID(ctx, groupID, invitationID, body)
265265
if err != nil {
266266
t.Fatalf("Projects.UpdateInvitationByID returned error: %v", err)
267267
}

mongodbatlas/projects.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ type ProjectsService interface {
4949
RemoveUserFromProject(context.Context, string, string) (*Response, error)
5050
Invitations(context.Context, string, *InvitationOptions) ([]*Invitation, *Response, error)
5151
Invitation(context.Context, string, string) (*Invitation, *Response, error)
52-
InviteUser(context.Context, *Invitation) (*Invitation, *Response, error)
53-
UpdateInvitation(context.Context, *Invitation) (*Invitation, *Response, error)
54-
UpdateInvitationByID(context.Context, string, *Invitation) (*Invitation, *Response, error)
52+
InviteUser(context.Context, string, *Invitation) (*Invitation, *Response, error)
53+
UpdateInvitation(context.Context, string, *Invitation) (*Invitation, *Response, error)
54+
UpdateInvitationByID(context.Context, string, string, *Invitation) (*Invitation, *Response, error)
5555
DeleteInvitation(context.Context, string, string) (*Response, error)
5656
}
5757

0 commit comments

Comments
 (0)