Skip to content

Commit

Permalink
Bugfixes for Teams endpoint (#23)
Browse files Browse the repository at this point in the history
that coulda been bad

Signed-off-by: Lasse Gaardsholt <[email protected]>

Signed-off-by: Lasse Gaardsholt <[email protected]>
  • Loading branch information
Gaardsholt authored Dec 12, 2022
1 parent b8581f7 commit 9b5a0cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
25 changes: 14 additions & 11 deletions invitations/Create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type InvitationsCreateOptions struct {
type InvitationsCreateRole string

const (
Owner InvitationsCreateRole = "manager"
Manager InvitationsCreateRole = "member"
Member InvitationsCreateRole = "viewer"
Viewer InvitationsCreateRole = "restricted"
Manager InvitationsCreateRole = "manager"
Member InvitationsCreateRole = "member"
Viewer InvitationsCreateRole = "viewer"
Restricted InvitationsCreateRole = "restricted"
)

func (c *InvitationsClient) Create(lo InvitationsCreateOptions) (*InvitationsCreateResult, error) {
Expand All @@ -51,7 +51,7 @@ func (c *InvitationsClient) Create(lo InvitationsCreateOptions) (*InvitationsCre
}
defer r.Body.Close()

if r.StatusCode != http.StatusOK {
if r.StatusCode != http.StatusCreated && r.StatusCode != http.StatusOK {
var target Error
decode := json.NewDecoder(r.Body)
err = decode.Decode(&target)
Expand All @@ -61,12 +61,15 @@ func (c *InvitationsClient) Create(lo InvitationsCreateOptions) (*InvitationsCre
return &InvitationsCreateResult{Error: &target}, fmt.Errorf("%s", target.Detail)
}

var target []InvitationsCreateResponse
decode := json.NewDecoder(r.Body)
err = decode.Decode(&target)
if err != nil {
return nil, err
if r.StatusCode == http.StatusCreated {
var target InvitationsCreateResponse
decode := json.NewDecoder(r.Body)
err = decode.Decode(&target)
if err != nil {
return nil, err
}
return &InvitationsCreateResult{Result: []InvitationsCreateResponse{target}}, nil
}

return &InvitationsCreateResult{Result: target}, nil
return nil, fmt.Errorf("user already in the workspace")
}
4 changes: 2 additions & 2 deletions teams/AddMember.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type TeamsAddMemberOptions struct {
MemberId string `json:"member_id"`
MemberId int64 `json:"member_id"`
TeamPermission TeamPermission `json:"team_permission"`
IncidentPermission IncidentPermission `json:"incident_permission"`
}
Expand All @@ -20,7 +20,7 @@ func (c *TeamsClient) AddMember(TeamId int, lo TeamsAddMemberOptions) (*ListMemb
return nil, err
}

req, err := c.client.NewRequest("POST", "/v1/teams/%d/team_memberships", b)
req, err := c.client.NewRequest("POST", fmt.Sprintf("/v1/teams/%d/team_memberships", TeamId), b)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion teams/ListMemberships.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type TeamPermission string

const (
CanManage TeamPermission = "can_manage"
CannotManage TeamPermission = "cannot_manage"
CanNotManage TeamPermission = "cannot_manage"
)

type IncidentPermission string
Expand Down

0 comments on commit 9b5a0cf

Please sign in to comment.