You've already forked focalboard
mirror of
https://github.com/mattermost/focalboard.git
synced 2025-07-15 23:54:29 +02:00
fix crash in DeleteBlock (#2040)
* fix crash in deleteblock * fix unit test
This commit is contained in:
@ -1594,8 +1594,8 @@ func (a *API) handleCreateSubscription(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check for valid block
|
// check for valid block
|
||||||
_, err = a.app.GetBlockWithID(*container, sub.BlockID)
|
block, err := a.app.GetBlockWithID(*container, sub.BlockID)
|
||||||
if err != nil {
|
if err != nil || block == nil {
|
||||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "invalid blockID", err)
|
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "invalid blockID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,11 @@ func (a *App) DeleteBlock(c store.Container, blockID string, modifiedBy string)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if block == nil {
|
||||||
|
// deleting non-existing block not considered an error
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
err = a.store.DeleteBlock(c, blockID, modifiedBy)
|
err = a.store.DeleteBlock(c, blockID, modifiedBy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -20,10 +20,37 @@ func createTestSubscriptions(client *client.Client, num int, workspaceID string)
|
|||||||
return nil, "", fmt.Errorf("cannot get current user: %w", resp.Error)
|
return nil, "", fmt.Errorf("cannot get current user: %w", resp.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
board := model.Block{
|
||||||
|
ID: utils.NewID(utils.IDTypeBoard),
|
||||||
|
RootID: workspaceID,
|
||||||
|
CreateAt: 1,
|
||||||
|
UpdateAt: 1,
|
||||||
|
Type: model.TypeBoard,
|
||||||
|
}
|
||||||
|
boards, resp := client.InsertBlocks([]model.Block{board})
|
||||||
|
if resp.Error != nil {
|
||||||
|
return nil, "", fmt.Errorf("cannot insert test board block: %w", resp.Error)
|
||||||
|
}
|
||||||
|
board = boards[0]
|
||||||
|
|
||||||
for n := 0; n < num; n++ {
|
for n := 0; n < num; n++ {
|
||||||
|
newBlock := model.Block{
|
||||||
|
ID: utils.NewID(utils.IDTypeCard),
|
||||||
|
RootID: board.ID,
|
||||||
|
CreateAt: 1,
|
||||||
|
UpdateAt: 1,
|
||||||
|
Type: model.TypeCard,
|
||||||
|
}
|
||||||
|
|
||||||
|
newBlocks, resp := client.InsertBlocks([]model.Block{newBlock})
|
||||||
|
if resp.Error != nil {
|
||||||
|
return nil, "", fmt.Errorf("cannot insert test card block: %w", resp.Error)
|
||||||
|
}
|
||||||
|
newBlock = newBlocks[0]
|
||||||
|
|
||||||
sub := &model.Subscription{
|
sub := &model.Subscription{
|
||||||
BlockType: model.TypeCard,
|
BlockType: newBlock.Type,
|
||||||
BlockID: utils.NewID(utils.IDTypeCard),
|
BlockID: newBlock.ID,
|
||||||
WorkspaceID: workspaceID,
|
WorkspaceID: workspaceID,
|
||||||
SubscriberType: model.SubTypeUser,
|
SubscriberType: model.SubTypeUser,
|
||||||
SubscriberID: user.ID,
|
SubscriberID: user.ID,
|
||||||
|
Reference in New Issue
Block a user