1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-07-12 23:50:27 +02:00

Add disableNotify param to client APIs, to match Rest APIs (#3723)

This commit is contained in:
Doug Lauder
2022-08-23 11:37:49 -04:00
committed by GitHub
parent bfde68c532
commit 0311cc91ad
4 changed files with 36 additions and 32 deletions

View File

@ -256,8 +256,14 @@ func (c *Client) GetAllBlocksForBoard(boardID string) ([]model.Block, *Response)
return model.BlocksFromJSON(r.Body), BuildResponse(r) return model.BlocksFromJSON(r.Body), BuildResponse(r)
} }
func (c *Client) PatchBlock(boardID, blockID string, blockPatch *model.BlockPatch) (bool, *Response) { const disableNotifyQueryParam = "disable_notify=true"
r, err := c.DoAPIPatch(c.GetBlockRoute(boardID, blockID), toJSON(blockPatch))
func (c *Client) PatchBlock(boardID, blockID string, blockPatch *model.BlockPatch, disableNotify bool) (bool, *Response) {
var queryParams string
if disableNotify {
queryParams = "?" + disableNotifyQueryParam
}
r, err := c.DoAPIPatch(c.GetBlockRoute(boardID, blockID)+queryParams, toJSON(blockPatch))
if err != nil { if err != nil {
return false, BuildErrorResponse(r, err) return false, BuildErrorResponse(r, err)
} }
@ -307,8 +313,12 @@ func (c *Client) UndeleteBlock(boardID, blockID string) (bool, *Response) {
return true, BuildResponse(r) return true, BuildResponse(r)
} }
func (c *Client) InsertBlocks(boardID string, blocks []model.Block) ([]model.Block, *Response) { func (c *Client) InsertBlocks(boardID string, blocks []model.Block, disableNotify bool) ([]model.Block, *Response) {
r, err := c.DoAPIPost(c.GetBlocksRoute(boardID), toJSON(blocks)) var queryParams string
if disableNotify {
queryParams = "?" + disableNotifyQueryParam
}
r, err := c.DoAPIPost(c.GetBlocksRoute(boardID)+queryParams, toJSON(blocks))
if err != nil { if err != nil {
return nil, BuildErrorResponse(r, err) return nil, BuildErrorResponse(r, err)
} }
@ -317,18 +327,12 @@ func (c *Client) InsertBlocks(boardID string, blocks []model.Block) ([]model.Blo
return model.BlocksFromJSON(r.Body), BuildResponse(r) return model.BlocksFromJSON(r.Body), BuildResponse(r)
} }
func (c *Client) InsertBlocksDisableNotify(boardID string, blocks []model.Block) ([]model.Block, *Response) { func (c *Client) DeleteBlock(boardID, blockID string, disableNotify bool) (bool, *Response) {
r, err := c.DoAPIPost(c.GetBlocksRoute(boardID)+"?disable_notify=true", toJSON(blocks)) var queryParams string
if err != nil { if disableNotify {
return nil, BuildErrorResponse(r, err) queryParams = "?" + disableNotifyQueryParam
} }
defer closeBody(r) r, err := c.DoAPIDelete(c.GetBlockRoute(boardID, blockID)+queryParams, "")
return model.BlocksFromJSON(r.Body), BuildResponse(r)
}
func (c *Client) DeleteBlock(boardID, blockID string) (bool, *Response) {
r, err := c.DoAPIDelete(c.GetBlockRoute(boardID, blockID), "")
if err != nil { if err != nil {
return false, BuildErrorResponse(r, err) return false, BuildErrorResponse(r, err)
} }

View File

@ -34,7 +34,7 @@ func TestGetBlocks(t *testing.T) {
Type: model.TypeCard, Type: model.TypeCard,
}, },
} }
newBlocks, resp := th.Client.InsertBlocks(board.ID, newBlocks) newBlocks, resp := th.Client.InsertBlocks(board.ID, newBlocks, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
require.Len(t, newBlocks, 2) require.Len(t, newBlocks, 2)
blockID1 := newBlocks[0].ID blockID1 := newBlocks[0].ID
@ -73,7 +73,7 @@ func TestPostBlock(t *testing.T) {
Title: "New title", Title: "New title",
} }
newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block}) newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block}, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
require.Len(t, newBlocks, 1) require.Len(t, newBlocks, 1)
blockID1 = newBlocks[0].ID blockID1 = newBlocks[0].ID
@ -109,7 +109,7 @@ func TestPostBlock(t *testing.T) {
}, },
} }
newBlocks, resp := th.Client.InsertBlocks(board.ID, newBlocks) newBlocks, resp := th.Client.InsertBlocks(board.ID, newBlocks, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
require.Len(t, newBlocks, 2) require.Len(t, newBlocks, 2)
blockID2 = newBlocks[0].ID blockID2 = newBlocks[0].ID
@ -140,7 +140,7 @@ func TestPostBlock(t *testing.T) {
Title: "Updated title", Title: "Updated title",
} }
newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block}) newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block}, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
require.Len(t, newBlocks, 1) require.Len(t, newBlocks, 1)
blockID4 := newBlocks[0].ID blockID4 := newBlocks[0].ID
@ -180,7 +180,7 @@ func TestPatchBlock(t *testing.T) {
Fields: map[string]interface{}{"test": "test value", "test2": "test value 2"}, Fields: map[string]interface{}{"test": "test value", "test2": "test value 2"},
} }
newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block}) newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block}, false)
th.CheckOK(resp) th.CheckOK(resp)
require.Len(t, newBlocks, 1) require.Len(t, newBlocks, 1)
blockID := newBlocks[0].ID blockID := newBlocks[0].ID
@ -191,7 +191,7 @@ func TestPatchBlock(t *testing.T) {
Title: &newTitle, Title: &newTitle,
} }
_, resp := th.Client.PatchBlock(board.ID, blockID, blockPatch) _, resp := th.Client.PatchBlock(board.ID, blockID, blockPatch, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
blocks, resp := th.Client.GetBlocksForBoard(board.ID) blocks, resp := th.Client.GetBlocksForBoard(board.ID)
@ -216,7 +216,7 @@ func TestPatchBlock(t *testing.T) {
}, },
} }
_, resp := th.Client.PatchBlock(board.ID, blockID, blockPatch) _, resp := th.Client.PatchBlock(board.ID, blockID, blockPatch, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
blocks, resp := th.Client.GetBlocksForBoard(board.ID) blocks, resp := th.Client.GetBlocksForBoard(board.ID)
@ -239,7 +239,7 @@ func TestPatchBlock(t *testing.T) {
DeletedFields: []string{"test", "test3", "test100"}, DeletedFields: []string{"test", "test3", "test100"},
} }
_, resp := th.Client.PatchBlock(board.ID, blockID, blockPatch) _, resp := th.Client.PatchBlock(board.ID, blockID, blockPatch, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
blocks, resp := th.Client.GetBlocksForBoard(board.ID) blocks, resp := th.Client.GetBlocksForBoard(board.ID)
@ -278,7 +278,7 @@ func TestDeleteBlock(t *testing.T) {
Title: "New title", Title: "New title",
} }
newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block}) newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block}, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
require.Len(t, newBlocks, 1) require.Len(t, newBlocks, 1)
require.NotZero(t, newBlocks[0].ID) require.NotZero(t, newBlocks[0].ID)
@ -301,7 +301,7 @@ func TestDeleteBlock(t *testing.T) {
// id,insert_at on block history // id,insert_at on block history
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
_, resp := th.Client.DeleteBlock(board.ID, blockID) _, resp := th.Client.DeleteBlock(board.ID, blockID, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
blocks, resp := th.Client.GetBlocksForBoard(board.ID) blocks, resp := th.Client.GetBlocksForBoard(board.ID)
@ -332,7 +332,7 @@ func TestUndeleteBlock(t *testing.T) {
Title: "New title", Title: "New title",
} }
newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block}) newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block}, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
require.Len(t, newBlocks, 1) require.Len(t, newBlocks, 1)
require.NotZero(t, newBlocks[0].ID) require.NotZero(t, newBlocks[0].ID)
@ -355,7 +355,7 @@ func TestUndeleteBlock(t *testing.T) {
// id,insert_at on block history // id,insert_at on block history
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
_, resp := th.Client.DeleteBlock(board.ID, blockID) _, resp := th.Client.DeleteBlock(board.ID, blockID, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
blocks, resp := th.Client.GetBlocksForBoard(board.ID) blocks, resp := th.Client.GetBlocksForBoard(board.ID)
@ -381,7 +381,7 @@ func TestUndeleteBlock(t *testing.T) {
// id,insert_at on block history // id,insert_at on block history
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
_, resp := th.Client.DeleteBlock(board.ID, blockID) _, resp := th.Client.DeleteBlock(board.ID, blockID, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
_, resp = th.Client2.UndeleteBlock(board.ID, blockID) _, resp = th.Client2.UndeleteBlock(board.ID, blockID)

View File

@ -450,7 +450,7 @@ func TestGetAllBlocksForBoard(t *testing.T) {
}, },
} }
insertedBlocks, resp := th.Client.InsertBlocks(board.ID, newBlocks) insertedBlocks, resp := th.Client.InsertBlocks(board.ID, newBlocks, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
require.Len(t, insertedBlocks, len(newBlocks)) require.Len(t, insertedBlocks, len(newBlocks))
@ -1905,7 +1905,7 @@ func TestDuplicateBoard(t *testing.T) {
}, },
} }
newBlocks, resp = th.Client.InsertBlocks(board.ID, newBlocks) newBlocks, resp = th.Client.InsertBlocks(board.ID, newBlocks, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
require.Len(t, newBlocks, 1) require.Len(t, newBlocks, 1)
@ -1990,7 +1990,7 @@ func TestDuplicateBoard(t *testing.T) {
}, },
} }
newBlocks, resp = th.Client.InsertBlocks(board.ID, newBlocks) newBlocks, resp = th.Client.InsertBlocks(board.ID, newBlocks, false)
require.NoError(t, resp.Error) require.NoError(t, resp.Error)
require.Len(t, newBlocks, 1) require.Len(t, newBlocks, 1)

View File

@ -39,7 +39,7 @@ func createTestSubscriptions(client *client.Client, num int) ([]*model.Subscript
Type: model.TypeCard, Type: model.TypeCard,
} }
newBlocks, resp := client.InsertBlocks(board.ID, []model.Block{newBlock}) newBlocks, resp := client.InsertBlocks(board.ID, []model.Block{newBlock}, false)
if resp.Error != nil { if resp.Error != nil {
return nil, "", fmt.Errorf("cannot insert test card block: %w", resp.Error) return nil, "", fmt.Errorf("cannot insert test card block: %w", resp.Error)
} }