MM-21727 add an endpoint to move a command to another team (#13624)
* MM-21727 add an endpoint to move a command to another team * endpoint * mock / client * unit tests * MM-21727 PR feedback, addressed nits * MM-21727 remove CommandMove base route * MM-21272 replace TeamId struct with CommandMoveRequest struct * MM-21727 fixed typo in CommandMoveRequest struct name * MM-21727 return not-found for all getCommandById calls * MM-21727 ensure no command ids leak * when calling GetCommandById with invalid id return not_found * when checking perms to manage commands for team return same not_found * update unit tests to check for not_found * MM-21727 Rename TeamIdFromCommandMoveRequestJson -> CommandMoveRequestFromJson
Этот коммит содержится в:
@@ -352,6 +352,10 @@ func (c *Client4) GetCommandRoute(commandId string) string {
|
||||
return fmt.Sprintf(c.GetCommandsRoute()+"/%v", commandId)
|
||||
}
|
||||
|
||||
func (c *Client4) GetCommandMoveRoute(commandId string) string {
|
||||
return fmt.Sprintf(c.GetCommandsRoute()+"/%v/move", commandId)
|
||||
}
|
||||
|
||||
func (c *Client4) GetEmojisRoute() string {
|
||||
return fmt.Sprintf("/emoji")
|
||||
}
|
||||
@@ -4019,6 +4023,17 @@ func (c *Client4) UpdateCommand(cmd *Command) (*Command, *Response) {
|
||||
return CommandFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// MoveCommand moves a command to a different team.
|
||||
func (c *Client4) MoveCommand(teamId string, commandId string) (bool, *Response) {
|
||||
cmr := CommandMoveRequest{TeamId: teamId}
|
||||
r, err := c.DoApiPut(c.GetCommandMoveRoute(commandId), cmr.ToJson())
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// DeleteCommand deletes a command based on the provided command id string.
|
||||
func (c *Client4) DeleteCommand(commandId string) (bool, *Response) {
|
||||
r, err := c.DoApiDelete(c.GetCommandRoute(commandId))
|
||||
|
||||
31
model/command_request.go
Обычный файл
31
model/command_request.go
Обычный файл
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type CommandMoveRequest struct {
|
||||
TeamId string `json:"team_id"`
|
||||
}
|
||||
|
||||
func CommandMoveRequestFromJson(data io.Reader) (*CommandMoveRequest, error) {
|
||||
decoder := json.NewDecoder(data)
|
||||
var cmr CommandMoveRequest
|
||||
err := decoder.Decode(&cmr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cmr, nil
|
||||
}
|
||||
|
||||
func (cmr *CommandMoveRequest) ToJson() string {
|
||||
b, err := json.Marshal(cmr)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user