Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 13 additions & 15 deletions mongodbatlas/organization_invitations.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ func (s *OrganizationsServiceOp) Invitation(ctx context.Context, orgID, invitati
// InviteUser invites one user to the Atlas organization that you specify.
//
// See more: https://docs.atlas.mongodb.com/reference/api/organization-create-one-invitation/
func (s *OrganizationsServiceOp) InviteUser(ctx context.Context, invitation *Invitation) (*Invitation, *Response, error) {
if invitation.OrgID == "" {
func (s *OrganizationsServiceOp) InviteUser(ctx context.Context, orgID string, invitation *Invitation) (*Invitation, *Response, error) {
if orgID == "" {
return nil, nil, NewArgError("orgID", "must be set")
}

path := fmt.Sprintf(invitationBasePath, invitation.OrgID)
path := fmt.Sprintf(invitationBasePath, orgID)

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

return s.updateInvitation(ctx, invitation)
return s.updateInvitation(ctx, orgID, "", invitation)
}

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

if invitationID == "" {
return nil, nil, NewArgError("invitationID", "must be set")
}

invitation.ID = invitationID

return s.updateInvitation(ctx, invitation)
return s.updateInvitation(ctx, orgID, invitationID, invitation)
}

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

func (s *OrganizationsServiceOp) updateInvitation(ctx context.Context, invitation *Invitation) (*Invitation, *Response, error) {
path := fmt.Sprintf(invitationBasePath, invitation.OrgID)
func (s *OrganizationsServiceOp) updateInvitation(ctx context.Context, orgID, invitationID string, invitation *Invitation) (*Invitation, *Response, error) {
path := fmt.Sprintf(invitationBasePath, orgID)

if invitation.ID != "" {
path = fmt.Sprintf("%s/%s", path, invitation.ID)
if invitationID != "" {
path = fmt.Sprintf("%s/%s", path, invitationID)
}

req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, invitation)
Expand Down
6 changes: 3 additions & 3 deletions mongodbatlas/organization_invitations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestOrganizations_InviteUser(t *testing.T) {
Roles: []string{"ORG_OWNER"},
}

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

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

invitation, _, err := client.Organizations.UpdateInvitationByID(ctx, invitationID, body)
invitation, _, err := client.Organizations.UpdateInvitationByID(ctx, orgID, invitationID, body)
if err != nil {
t.Fatalf("Organizations.UpdateInvitationByID returned error: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions mongodbatlas/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ type OrganizationsService interface {
Projects(context.Context, string, *ListOptions) (*Projects, *Response, error)
Users(context.Context, string, *ListOptions) (*AtlasUsersResponse, *Response, error)
Delete(context.Context, string) (*Response, error)
InviteUser(context.Context, *Invitation) (*Invitation, *Response, error)
UpdateInvitation(context.Context, *Invitation) (*Invitation, *Response, error)
UpdateInvitationByID(context.Context, string, *Invitation) (*Invitation, *Response, error)
InviteUser(context.Context, string, *Invitation) (*Invitation, *Response, error)
UpdateInvitation(context.Context, string, *Invitation) (*Invitation, *Response, error)
UpdateInvitationByID(context.Context, string, string, *Invitation) (*Invitation, *Response, error)
DeleteInvitation(context.Context, string, string) (*Response, error)
}

Expand Down
26 changes: 13 additions & 13 deletions mongodbatlas/project_invitations.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func (s *ProjectsServiceOp) Invitation(ctx context.Context, groupID, invitationI
}

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

path := fmt.Sprintf(projectInvitationBasePath, invitation.GroupID)
path := fmt.Sprintf(projectInvitationBasePath, groupID)

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

return s.updateInvitation(ctx, invitation)
return s.updateInvitation(ctx, groupID, "", invitation)
}

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

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

invitation.ID = invitationID

return s.updateInvitation(ctx, invitation)
return s.updateInvitation(ctx, groupID, invitationID, invitation)
}

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

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

if invitation.ID != "" {
path = fmt.Sprintf("%s/%s", path, invitation.ID)
if invitationID != "" {
path = fmt.Sprintf("%s/%s", path, invitationID)
}

req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, invitation)
Expand Down
6 changes: 3 additions & 3 deletions mongodbatlas/project_invitations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestProjects_InviteUser(t *testing.T) {
Roles: []string{"ORG_OWNER"},
}

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

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

invitation, _, err := client.Projects.UpdateInvitationByID(ctx, invitationID, body)
invitation, _, err := client.Projects.UpdateInvitationByID(ctx, groupID, invitationID, body)
if err != nil {
t.Fatalf("Projects.UpdateInvitationByID returned error: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions mongodbatlas/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ type ProjectsService interface {
RemoveUserFromProject(context.Context, string, string) (*Response, error)
Invitations(context.Context, string, *InvitationOptions) ([]*Invitation, *Response, error)
Invitation(context.Context, string, string) (*Invitation, *Response, error)
InviteUser(context.Context, *Invitation) (*Invitation, *Response, error)
UpdateInvitation(context.Context, *Invitation) (*Invitation, *Response, error)
UpdateInvitationByID(context.Context, string, *Invitation) (*Invitation, *Response, error)
InviteUser(context.Context, string, *Invitation) (*Invitation, *Response, error)
UpdateInvitation(context.Context, string, *Invitation) (*Invitation, *Response, error)
UpdateInvitationByID(context.Context, string, string, *Invitation) (*Invitation, *Response, error)
DeleteInvitation(context.Context, string, string) (*Response, error)
}

Expand Down