Add GET /teams/invite/{invite_id} endpoint for v4 (#6685)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
effaeee830
Коммит
2e6fd031d1
@@ -350,6 +350,17 @@ func (c *Context) RequireTeamId() *Context {
|
|||||||
return c
|
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 {
|
func (c *Context) RequireChannelId() *Context {
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
return c
|
return c
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const (
|
|||||||
type ApiParams struct {
|
type ApiParams struct {
|
||||||
UserId string
|
UserId string
|
||||||
TeamId string
|
TeamId string
|
||||||
|
InviteId string
|
||||||
ChannelId string
|
ChannelId string
|
||||||
PostId string
|
PostId string
|
||||||
FileId string
|
FileId string
|
||||||
@@ -55,6 +56,10 @@ func ApiParamsFromRequest(r *http.Request) *ApiParams {
|
|||||||
params.TeamId = val
|
params.TeamId = val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if val, ok := props["invite_id"]; ok {
|
||||||
|
params.InviteId = val
|
||||||
|
}
|
||||||
|
|
||||||
if val, ok := props["channel_id"]; ok {
|
if val, ok := props["channel_id"]; ok {
|
||||||
params.ChannelId = val
|
params.ChannelId = val
|
||||||
}
|
}
|
||||||
|
|||||||
25
api4/team.go
25
api4/team.go
@@ -49,6 +49,7 @@ func InitTeam() {
|
|||||||
|
|
||||||
BaseRoutes.Team.Handle("/import", ApiSessionRequired(importTeam)).Methods("POST")
|
BaseRoutes.Team.Handle("/import", ApiSessionRequired(importTeam)).Methods("POST")
|
||||||
BaseRoutes.Team.Handle("/invite/email", ApiSessionRequired(inviteUsersToTeam)).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) {
|
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)
|
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)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -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
|
// Channel Section
|
||||||
|
|
||||||
// CreateChannel creates a channel based on the provided channel struct.
|
// CreateChannel creates a channel based on the provided channel struct.
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user