Add the recovery feature.
This commit is contained in:
parent
a92e172d26
commit
8a0c66ceff
@ -75,6 +75,8 @@ func (this *MatterController) RegisterRoutes() map[string]func(writer http.Respo
|
||||
routeMap["/api/matter/crawl"] = this.Wrap(this.Crawl, USER_ROLE_USER)
|
||||
routeMap["/api/matter/soft/delete"] = this.Wrap(this.SoftDelete, USER_ROLE_USER)
|
||||
routeMap["/api/matter/soft/delete/batch"] = this.Wrap(this.SoftDeleteBatch, USER_ROLE_USER)
|
||||
routeMap["/api/matter/recovery"] = this.Wrap(this.Recovery, USER_ROLE_USER)
|
||||
routeMap["/api/matter/recovery/batch"] = this.Wrap(this.RecoveryBatch, USER_ROLE_USER)
|
||||
routeMap["/api/matter/delete"] = this.Wrap(this.Delete, USER_ROLE_USER)
|
||||
routeMap["/api/matter/delete/batch"] = this.Wrap(this.DeleteBatch, USER_ROLE_USER)
|
||||
routeMap["/api/matter/rename"] = this.Wrap(this.Rename, USER_ROLE_USER)
|
||||
@ -333,6 +335,57 @@ func (this *MatterController) SoftDeleteBatch(writer http.ResponseWriter, reques
|
||||
return this.Success("OK")
|
||||
}
|
||||
|
||||
//recovery delete.
|
||||
func (this *MatterController) Recovery(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
uuid := request.FormValue("uuid")
|
||||
if uuid == "" {
|
||||
panic(result.BadRequest("uuid cannot be null"))
|
||||
}
|
||||
|
||||
matter := this.matterDao.CheckByUuid(uuid)
|
||||
|
||||
user := this.checkUser(request)
|
||||
if matter.UserUuid != user.Uuid {
|
||||
panic(result.UNAUTHORIZED)
|
||||
}
|
||||
|
||||
this.matterService.AtomicRecovery(request, matter, user)
|
||||
|
||||
return this.Success("OK")
|
||||
}
|
||||
|
||||
//recovery batch.
|
||||
func (this *MatterController) RecoveryBatch(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
uuids := request.FormValue("uuids")
|
||||
if uuids == "" {
|
||||
panic(result.BadRequest("uuids cannot be null"))
|
||||
}
|
||||
|
||||
uuidArray := strings.Split(uuids, ",")
|
||||
|
||||
for _, uuid := range uuidArray {
|
||||
|
||||
matter := this.matterDao.FindByUuid(uuid)
|
||||
|
||||
if matter == nil {
|
||||
this.logger.Warn("%s not exist anymore", uuid)
|
||||
continue
|
||||
}
|
||||
|
||||
user := this.checkUser(request)
|
||||
if matter.UserUuid != user.Uuid {
|
||||
panic(result.UNAUTHORIZED)
|
||||
}
|
||||
|
||||
this.matterService.AtomicRecovery(request, matter, user)
|
||||
|
||||
}
|
||||
|
||||
return this.Success("OK")
|
||||
}
|
||||
|
||||
//complete delete.
|
||||
func (this *MatterController) Delete(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
|
@ -450,7 +450,7 @@ func (this *MatterDao) Delete(matter *Matter) {
|
||||
}
|
||||
}
|
||||
|
||||
//soft delete a file from db and disk.
|
||||
//soft delete a file
|
||||
func (this *MatterDao) SoftDelete(matter *Matter) {
|
||||
|
||||
// recursive if dir
|
||||
@ -481,6 +481,30 @@ func (this *MatterDao) SoftDelete(matter *Matter) {
|
||||
}
|
||||
}
|
||||
|
||||
//recovery a file
|
||||
func (this *MatterDao) Recovery(matter *Matter) {
|
||||
|
||||
// recursive if dir
|
||||
if matter.Dir {
|
||||
matters := this.FindByPuuidAndUserUuid(matter.Uuid, matter.UserUuid, nil)
|
||||
|
||||
for _, f := range matters {
|
||||
this.SoftDelete(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) {
|
||||
|
||||
db := core.CONTEXT.GetDB().Where("user_uuid = ?", userUuid).Delete(Matter{})
|
||||
|
@ -271,6 +271,21 @@ func (this *MatterService) SoftDelete(request *http.Request, matter *Matter, use
|
||||
//no need to recompute size.
|
||||
}
|
||||
|
||||
//recovery delete files.
|
||||
func (this *MatterService) Recovery(request *http.Request, matter *Matter, user *User) {
|
||||
|
||||
if matter == nil {
|
||||
panic(result.BadRequest("matter cannot be nil"))
|
||||
}
|
||||
|
||||
if !matter.Deleted {
|
||||
panic(result.BadRequest("matter has not been deleted"))
|
||||
}
|
||||
|
||||
this.matterDao.Recovery(matter)
|
||||
//no need to recompute size.
|
||||
}
|
||||
|
||||
//atomic delete files
|
||||
func (this *MatterService) AtomicDelete(request *http.Request, matter *Matter, user *User) {
|
||||
|
||||
@ -303,6 +318,24 @@ func (this *MatterService) AtomicSoftDelete(request *http.Request, matter *Matte
|
||||
this.SoftDelete(request, matter, user)
|
||||
}
|
||||
|
||||
//atomic recovery delete files
|
||||
func (this *MatterService) AtomicRecovery(request *http.Request, matter *Matter, user *User) {
|
||||
|
||||
if matter == nil {
|
||||
panic(result.BadRequest("matter cannot be nil"))
|
||||
}
|
||||
|
||||
if !matter.Deleted {
|
||||
panic(result.BadRequest("matter has not been deleted"))
|
||||
}
|
||||
|
||||
//lock
|
||||
this.userService.MatterLock(matter.UserUuid)
|
||||
defer this.userService.MatterUnlock(matter.UserUuid)
|
||||
|
||||
this.Recovery(request, matter, user)
|
||||
}
|
||||
|
||||
//upload files.
|
||||
func (this *MatterService) Upload(request *http.Request, file io.Reader, user *User, dirMatter *Matter, filename string, privacy bool) *Matter {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user