Fix the soft delete bug.
This commit is contained in:
@ -285,7 +285,7 @@ func (this *MatterController) Crawl(writer http.ResponseWriter, request *http.Re
|
|||||||
return this.Success(matter)
|
return this.Success(matter)
|
||||||
}
|
}
|
||||||
|
|
||||||
//soft delete. todo: 删除了文件,但是父目录没有删的情形没处理。
|
//soft delete.
|
||||||
func (this *MatterController) SoftDelete(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
func (this *MatterController) SoftDelete(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||||
|
|
||||||
uuid := request.FormValue("uuid")
|
uuid := request.FormValue("uuid")
|
||||||
@ -311,9 +311,11 @@ func (this *MatterController) SoftDeleteBatch(writer http.ResponseWriter, reques
|
|||||||
if uuids == "" {
|
if uuids == "" {
|
||||||
panic(result.BadRequest("uuids cannot be null"))
|
panic(result.BadRequest("uuids cannot be null"))
|
||||||
}
|
}
|
||||||
|
user := this.checkUser(request)
|
||||||
|
|
||||||
uuidArray := strings.Split(uuids, ",")
|
uuidArray := strings.Split(uuids, ",")
|
||||||
|
|
||||||
|
matters := make([]*Matter, 0)
|
||||||
for _, uuid := range uuidArray {
|
for _, uuid := range uuidArray {
|
||||||
|
|
||||||
matter := this.matterDao.FindByUuid(uuid)
|
matter := this.matterDao.FindByUuid(uuid)
|
||||||
@ -323,13 +325,15 @@ func (this *MatterController) SoftDeleteBatch(writer http.ResponseWriter, reques
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
user := this.checkUser(request)
|
|
||||||
if matter.UserUuid != user.Uuid {
|
if matter.UserUuid != user.Uuid {
|
||||||
panic(result.UNAUTHORIZED)
|
panic(result.UNAUTHORIZED)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.matterService.AtomicSoftDelete(request, matter, user)
|
matters = append(matters, matter)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, matter := range matters {
|
||||||
|
this.matterService.AtomicSoftDelete(request, matter, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.Success("OK")
|
return this.Success("OK")
|
||||||
@ -414,7 +418,8 @@ func (this *MatterController) DeleteBatch(writer http.ResponseWriter, request *h
|
|||||||
}
|
}
|
||||||
|
|
||||||
uuidArray := strings.Split(uuids, ",")
|
uuidArray := strings.Split(uuids, ",")
|
||||||
|
user := this.checkUser(request)
|
||||||
|
matters := make([]*Matter, 0)
|
||||||
for _, uuid := range uuidArray {
|
for _, uuid := range uuidArray {
|
||||||
|
|
||||||
matter := this.matterDao.FindByUuid(uuid)
|
matter := this.matterDao.FindByUuid(uuid)
|
||||||
@ -424,13 +429,15 @@ func (this *MatterController) DeleteBatch(writer http.ResponseWriter, request *h
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
user := this.checkUser(request)
|
|
||||||
if matter.UserUuid != user.Uuid {
|
if matter.UserUuid != user.Uuid {
|
||||||
panic(result.UNAUTHORIZED)
|
panic(result.UNAUTHORIZED)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.matterService.AtomicDelete(request, matter, user)
|
}
|
||||||
|
|
||||||
|
for _, matter := range matters {
|
||||||
|
|
||||||
|
this.matterService.AtomicDelete(request, matter, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.Success("OK")
|
return this.Success("OK")
|
||||||
|
@ -450,59 +450,22 @@ func (this *MatterDao) Delete(matter *Matter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//soft delete a file
|
//soft delete a file or dir
|
||||||
func (this *MatterDao) SoftDelete(matter *Matter) {
|
func (this *MatterDao) SoftDelete(matter *Matter) {
|
||||||
|
|
||||||
// recursive if dir
|
//soft delete from db.
|
||||||
if matter.Dir {
|
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": true, "delete_time": time.Now()})
|
||||||
matters := this.FindByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
for _, f := range matters {
|
|
||||||
this.SoftDelete(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
//soft delete from db.
|
|
||||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": true, "delete_time": time.Now()})
|
|
||||||
this.PanicError(db.Error)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
//soft delete from db.
|
|
||||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": true, "delete_time": time.Now()})
|
|
||||||
this.PanicError(db.Error)
|
|
||||||
|
|
||||||
//no need to delete its image cache.
|
|
||||||
|
|
||||||
//delete all the share.
|
|
||||||
this.bridgeDao.DeleteByMatterUuid(matter.Uuid)
|
|
||||||
|
|
||||||
//no need to delete from disk.
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//recovery a file
|
//recovery a file
|
||||||
func (this *MatterDao) Recovery(matter *Matter) {
|
func (this *MatterDao) Recovery(matter *Matter) {
|
||||||
|
|
||||||
// recursive if dir
|
//recovery from db.
|
||||||
if matter.Dir {
|
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": false, "delete_time": time.Now()})
|
||||||
matters := this.FindByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
for _, f := range matters {
|
|
||||||
this.Recovery(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
//recovery from db.
|
|
||||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": false, "delete_time": time.Now()})
|
|
||||||
this.PanicError(db.Error)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
//recovery from db.
|
|
||||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": false, "delete_time": time.Now()})
|
|
||||||
this.PanicError(db.Error)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MatterDao) DeleteByUserUuid(userUuid string) {
|
func (this *MatterDao) DeleteByUserUuid(userUuid string) {
|
||||||
|
Reference in New Issue
Block a user