From d5f243dad694d6746ec2b6560a81212a78d8c975 Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Wed, 6 Jul 2016 13:40:59 -0800 Subject: PLT-2863 adding remove user from team (#3429) * PLT-2863 adding remove user from team * PLT-2863 adding the client side UI * Fixing trailing space * Fixing reported issues * Adding documentatino * Switching to final javascript driver --- model/client.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'model/client.go') diff --git a/model/client.go b/model/client.go index 1882fd0ab..2f1e846c2 100644 --- a/model/client.go +++ b/model/client.go @@ -345,10 +345,18 @@ func (c *Client) FindTeamByName(name string) (*Result, *AppError) { } } -func (c *Client) AddUserToTeam(userId string) (*Result, *AppError) { +// Adds a user directly to the team without sending an invite. +// The teamId and userId are required. You must be a valid member of the team and/or +// have the correct role to add new users to the team. Returns a map of user_id=userId +// if successful, otherwise returns an AppError. +func (c *Client) AddUserToTeam(teamId string, userId string) (*Result, *AppError) { + if len(teamId) == 0 { + teamId = c.GetTeamId() + } + data := make(map[string]string) data["user_id"] = userId - if r, err := c.DoApiPost(c.GetTeamRoute()+"/add_user_to_team", MapToJson(data)); err != nil { + if r, err := c.DoApiPost(fmt.Sprintf("/teams/%v", teamId)+"/add_user_to_team", MapToJson(data)); err != nil { return nil, err } else { defer closeBody(r) @@ -371,6 +379,26 @@ func (c *Client) AddUserToTeamFromInvite(hash, dataToHash, inviteId string) (*Re } } +// Removes a user directly from the team. +// The teamId and userId are required. You must be a valid member of the team and/or +// have the correct role to remove a user from the team. Returns a map of user_id=userId +// if successful, otherwise returns an AppError. +func (c *Client) RemoveUserFromTeam(teamId string, userId string) (*Result, *AppError) { + if len(teamId) == 0 { + teamId = c.GetTeamId() + } + + data := make(map[string]string) + data["user_id"] = userId + if r, err := c.DoApiPost(fmt.Sprintf("/teams/%v", teamId)+"/remove_user_from_team", MapToJson(data)); err != nil { + return nil, err + } else { + defer closeBody(r) + return &Result{r.Header.Get(HEADER_REQUEST_ID), + r.Header.Get(HEADER_ETAG_SERVER), MapFromJson(r.Body)}, nil + } +} + func (c *Client) InviteMembers(invites *Invites) (*Result, *AppError) { if r, err := c.DoApiPost(c.GetTeamRoute()+"/invite_members", invites.ToJson()); err != nil { return nil, err -- cgit v1.2.3-1-g7c22