summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-06-20 09:55:43 -0400
committerGeorge Goldberg <george@gberg.me>2017-06-20 14:55:43 +0100
commit2e6fd031d15a9502e7a7a4536febfe49780c0697 (patch)
tree644ad924de6ac441eee9f941683a6f92859229b6
parenteffaeee830efa78cd15218f6ba3920031ff8a5c1 (diff)
downloadchat-2e6fd031d15a9502e7a7a4536febfe49780c0697.tar.gz
chat-2e6fd031d15a9502e7a7a4536febfe49780c0697.tar.bz2
chat-2e6fd031d15a9502e7a7a4536febfe49780c0697.zip
Add GET /teams/invite/{invite_id} endpoint for v4 (#6685)
-rw-r--r--api4/context.go11
-rw-r--r--api4/params.go5
-rw-r--r--api4/team.go25
-rw-r--r--api4/team_test.go21
-rw-r--r--model/client4.go10
5 files changed, 72 insertions, 0 deletions
diff --git a/api4/context.go b/api4/context.go
index 7a908c588..35f343b7a 100644
--- a/api4/context.go
+++ b/api4/context.go
@@ -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
diff --git a/api4/params.go b/api4/params.go
index d952eb65a..999bf8e77 100644
--- a/api4/params.go
+++ b/api4/params.go
@@ -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
}
diff --git a/api4/team.go b/api4/team.go
index 57a715937..00a16d5c1 100644
--- a/api4/team.go
+++ b/api4/team.go
@@ -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)))
+ }
+}
diff --git a/api4/team_test.go b/api4/team_test.go
index 2aee4ba5f..78ddc8e84 100644
--- a/api4/team_test.go
+++ b/api4/team_test.go
@@ -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)
+}
diff --git a/model/client4.go b/model/client4.go
index efe12a3b9..be8a689f2 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -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.