Add GET /teams/invite/{invite_id} endpoint for v4 (#6685)

This commit is contained in:
Joram Wilander
2017-06-20 09:55:43 -04:00
committed by George Goldberg
parent effaeee830
commit 2e6fd031d1
5 changed files with 72 additions and 0 deletions

View File

@@ -350,6 +350,17 @@ func (c *Context) RequireTeamId() *Context {
return c
}
func (c *Context) RequireInviteId() *Context {
if c.Err != nil {
return c
}
if len(c.Params.InviteId) != 26 {
c.SetInvalidUrlParam("invite_id")
}
return c
}
func (c *Context) RequireChannelId() *Context {
if c.Err != nil {
return c

View File

@@ -19,6 +19,7 @@ const (
type ApiParams struct {
UserId string
TeamId string
InviteId string
ChannelId string
PostId string
FileId string
@@ -55,6 +56,10 @@ func ApiParamsFromRequest(r *http.Request) *ApiParams {
params.TeamId = val
}
if val, ok := props["invite_id"]; ok {
params.InviteId = val
}
if val, ok := props["channel_id"]; ok {
params.ChannelId = val
}

View File

@@ -49,6 +49,7 @@ func InitTeam() {
BaseRoutes.Team.Handle("/import", ApiSessionRequired(importTeam)).Methods("POST")
BaseRoutes.Team.Handle("/invite/email", ApiSessionRequired(inviteUsersToTeam)).Methods("POST")
BaseRoutes.Teams.Handle("/invite/{invite_id:[A-Za-z0-9]+}", ApiHandler(getInviteInfo)).Methods("GET")
}
func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -687,3 +688,27 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
ReturnStatusOK(w)
}
func getInviteInfo(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireInviteId()
if c.Err != nil {
return
}
if team, err := app.GetTeamByInviteId(c.Params.InviteId); err != nil {
c.Err = err
return
} else {
if !(team.Type == model.TEAM_OPEN) {
c.Err = model.NewAppError("getInviteInfo", "api.team.get_invite_info.not_open_team", nil, "id="+c.Params.InviteId, http.StatusForbidden)
return
}
result := map[string]string{}
result["display_name"] = team.DisplayName
result["description"] = team.Description
result["name"] = team.Name
result["id"] = team.Id
w.Write([]byte(model.MapToJson(result)))
}
}

View File

@@ -1453,3 +1453,24 @@ func TestInviteUsersToTeam(t *testing.T) {
}
}
}
func TestGetTeamInviteInfo(t *testing.T) {
th := Setup().InitBasic()
defer TearDown()
Client := th.Client
team := th.BasicTeam
team, resp := Client.GetTeamInviteInfo(team.InviteId)
CheckNoError(t, resp)
if team.DisplayName == "" {
t.Fatal("should not be empty")
}
if team.Email != "" {
t.Fatal("should be empty")
}
_, resp = Client.GetTeamInviteInfo("junk")
CheckBadRequestStatus(t, resp)
}

View File

@@ -1204,6 +1204,16 @@ func (c *Client4) InviteUsersToTeam(teamId string, userEmails []string) (bool, *
}
}
// GetTeamInviteInfo returns a team object from an invite id containing sanitized information.
func (c *Client4) GetTeamInviteInfo(inviteId string) (*Team, *Response) {
if r, err := c.DoApiGet(c.GetTeamsRoute()+"/invite/"+inviteId, ""); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return TeamFromJson(r.Body), BuildResponse(r)
}
}
// Channel Section
// CreateChannel creates a channel based on the provided channel struct.