mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-14 18:17:33 +02:00
Store modifiedBy for deleted blocks
This commit is contained in:
parent
7f3547dc02
commit
7052a022b3
@ -216,10 +216,14 @@ func (a *API) handleGetMe(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (a *API) handleDeleteBlock(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
session := ctx.Value("session").(*model.Session)
|
||||
userID := session.UserID
|
||||
|
||||
vars := mux.Vars(r)
|
||||
blockID := vars["blockID"]
|
||||
|
||||
err := a.app().DeleteBlock(blockID)
|
||||
err := a.app().DeleteBlock(blockID, userID)
|
||||
if err != nil {
|
||||
log.Printf(`ERROR: %v, REQUEST: %v`, err, r)
|
||||
errorResponse(w, http.StatusInternalServerError, nil)
|
||||
|
@ -63,7 +63,7 @@ func (a *App) GetAllBlocks() ([]model.Block, error) {
|
||||
return a.store.GetAllBlocks()
|
||||
}
|
||||
|
||||
func (a *App) DeleteBlock(blockID string) error {
|
||||
func (a *App) DeleteBlock(blockID string, modifiedBy string) error {
|
||||
blockIDsToNotify := []string{blockID}
|
||||
parentID, err := a.GetParentID(blockID)
|
||||
if err != nil {
|
||||
@ -74,7 +74,7 @@ func (a *App) DeleteBlock(blockID string) error {
|
||||
blockIDsToNotify = append(blockIDsToNotify, parentID)
|
||||
}
|
||||
|
||||
err = a.store.DeleteBlock(blockID)
|
||||
err = a.store.DeleteBlock(blockID, modifiedBy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -76,17 +76,17 @@ func (mr *MockStoreMockRecorder) CreateUser(arg0 interface{}) *gomock.Call {
|
||||
}
|
||||
|
||||
// DeleteBlock mocks base method
|
||||
func (m *MockStore) DeleteBlock(arg0 string) error {
|
||||
func (m *MockStore) DeleteBlock(arg0, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DeleteBlock", arg0)
|
||||
ret := m.ctrl.Call(m, "DeleteBlock", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DeleteBlock indicates an expected call of DeleteBlock
|
||||
func (mr *MockStoreMockRecorder) DeleteBlock(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockStoreMockRecorder) DeleteBlock(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteBlock", reflect.TypeOf((*MockStore)(nil).DeleteBlock), arg0)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteBlock", reflect.TypeOf((*MockStore)(nil).DeleteBlock), arg0, arg1)
|
||||
}
|
||||
|
||||
// DeleteSession mocks base method
|
||||
|
@ -324,9 +324,21 @@ func (s *SQLStore) InsertBlock(block model.Block) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) DeleteBlock(blockID string) error {
|
||||
func (s *SQLStore) DeleteBlock(blockID string, modifiedBy string) error {
|
||||
now := time.Now().Unix()
|
||||
query := s.getQueryBuilder().Insert("blocks").Columns("id", "update_at", "delete_at").Values(blockID, now, now)
|
||||
query := s.getQueryBuilder().Insert("blocks").
|
||||
Columns(
|
||||
"id",
|
||||
"modified_by",
|
||||
"update_at",
|
||||
"delete_at",
|
||||
).
|
||||
Values(
|
||||
blockID,
|
||||
modifiedBy,
|
||||
now,
|
||||
now,
|
||||
)
|
||||
|
||||
_, err := query.Exec()
|
||||
if err != nil {
|
||||
|
@ -12,13 +12,16 @@ func TestInsertBlock(t *testing.T) {
|
||||
store, tearDown := SetupTests(t)
|
||||
defer tearDown()
|
||||
|
||||
userID := "user-id"
|
||||
|
||||
blocks, err := store.GetAllBlocks()
|
||||
require.NoError(t, err)
|
||||
initialCount := len(blocks)
|
||||
|
||||
block := model.Block{
|
||||
ID: "id-test",
|
||||
RootID: "id-test",
|
||||
ID: "id-test",
|
||||
RootID: "id-test",
|
||||
ModifiedBy: userID,
|
||||
}
|
||||
|
||||
err = store.InsertBlock(block)
|
||||
@ -30,7 +33,7 @@ func TestInsertBlock(t *testing.T) {
|
||||
|
||||
// Wait for not colliding the ID+insert_at key
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
err = store.DeleteBlock(block.ID)
|
||||
err = store.DeleteBlock(block.ID, userID)
|
||||
require.NoError(t, err)
|
||||
|
||||
blocks, err = store.GetAllBlocks()
|
||||
@ -42,39 +45,47 @@ func TestGetSubTree2(t *testing.T) {
|
||||
store, tearDown := SetupTests(t)
|
||||
defer tearDown()
|
||||
|
||||
userID := "user-id"
|
||||
|
||||
blocks, err := store.GetAllBlocks()
|
||||
require.NoError(t, err)
|
||||
initialCount := len(blocks)
|
||||
|
||||
blocksToInsert := []model.Block{
|
||||
model.Block{
|
||||
ID: "parent",
|
||||
RootID: "parent",
|
||||
ID: "parent",
|
||||
RootID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
ID: "child1",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ID: "child1",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
ID: "child2",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ID: "child2",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
ID: "grandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "child1",
|
||||
ID: "grandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "child1",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
ID: "grandchild2",
|
||||
RootID: "parent",
|
||||
ParentID: "child2",
|
||||
ID: "grandchild2",
|
||||
RootID: "parent",
|
||||
ParentID: "child2",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
ID: "greatgrandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "grandchild1",
|
||||
ID: "greatgrandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "grandchild1",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
}
|
||||
|
||||
@ -93,7 +104,7 @@ func TestGetSubTree2(t *testing.T) {
|
||||
|
||||
// Wait for not colliding the ID+insert_at key
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
DeleteBlocks(t, store, blocksToInsert)
|
||||
DeleteBlocks(t, store, blocksToInsert, userID)
|
||||
|
||||
blocks, err = store.GetAllBlocks()
|
||||
require.NoError(t, err)
|
||||
@ -104,39 +115,47 @@ func TestGetSubTree3(t *testing.T) {
|
||||
store, tearDown := SetupTests(t)
|
||||
defer tearDown()
|
||||
|
||||
userID := "user-id"
|
||||
|
||||
blocks, err := store.GetAllBlocks()
|
||||
require.NoError(t, err)
|
||||
initialCount := len(blocks)
|
||||
|
||||
blocksToInsert := []model.Block{
|
||||
model.Block{
|
||||
ID: "parent",
|
||||
RootID: "parent",
|
||||
ID: "parent",
|
||||
RootID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
ID: "child1",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ID: "child1",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
ID: "child2",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ID: "child2",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
ID: "grandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "child1",
|
||||
ID: "grandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "child1",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
ID: "grandchild2",
|
||||
RootID: "parent",
|
||||
ParentID: "child2",
|
||||
ID: "grandchild2",
|
||||
RootID: "parent",
|
||||
ParentID: "child2",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
ID: "greatgrandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "grandchild1",
|
||||
ID: "greatgrandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "grandchild1",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
}
|
||||
|
||||
@ -157,7 +176,7 @@ func TestGetSubTree3(t *testing.T) {
|
||||
|
||||
// Wait for not colliding the ID+insert_at key
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
DeleteBlocks(t, store, blocksToInsert)
|
||||
DeleteBlocks(t, store, blocksToInsert, userID)
|
||||
|
||||
blocks, err = store.GetAllBlocks()
|
||||
require.NoError(t, err)
|
||||
|
@ -37,9 +37,9 @@ func InsertBlocks(t *testing.T, s *SQLStore, blocks []model.Block) {
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteBlocks(t *testing.T, s *SQLStore, blocks []model.Block) {
|
||||
func DeleteBlocks(t *testing.T, s *SQLStore, blocks []model.Block, modifiedBy string) {
|
||||
for _, block := range blocks {
|
||||
err := s.DeleteBlock(block.ID)
|
||||
err := s.DeleteBlock(block.ID, modifiedBy)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ type Store interface {
|
||||
GetAllBlocks() ([]model.Block, error)
|
||||
GetParentID(blockID string) (string, error)
|
||||
InsertBlock(block model.Block) error
|
||||
DeleteBlock(blockID string) error
|
||||
DeleteBlock(blockID string, modifiedBy string) error
|
||||
Shutdown() error
|
||||
GetSystemSettings() (map[string]string, error)
|
||||
SetSystemSetting(key string, value string) error
|
||||
|
Loading…
Reference in New Issue
Block a user