summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
Diffstat (limited to 'api4')
-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
4 files changed, 62 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)
+}