From 963b7fdb829df025344434b817e402f0a859f309 Mon Sep 17 00:00:00 2001 From: lishuang Date: Tue, 27 Jun 2023 00:03:49 +0800 Subject: [PATCH] fix: fix the bugs for space file upload. --- code/rest/dav_service.go | 4 ++-- code/rest/matter_dao.go | 37 +++++++++++++++++++++++++++++++++++ code/rest/matter_service.go | 10 +++++----- code/rest/space_controller.go | 5 +++++ code/rest/space_service.go | 2 +- code/support/tank_context.go | 2 +- 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/code/rest/dav_service.go b/code/rest/dav_service.go index 5046e45..25aa780 100644 --- a/code/rest/dav_service.go +++ b/code/rest/dav_service.go @@ -402,13 +402,13 @@ func (this *DavService) HandleMkcol(writer http.ResponseWriter, request *http.Re } //check whether col exists. (RFC2518:8.3.1) - dbMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, TRUE, thisDirName) + dbMatter := this.matterDao.FindBySpaceNameAndPuuidAndDirAndName(space.Name, dirMatter.Uuid, TRUE, thisDirName) if dbMatter != nil { panic(result.CustomWebResult(result.METHOD_NOT_ALLOWED, fmt.Sprintf("%s already exists", dirPath))) } //check whether file exists. (RFC2518:8.3.1) - fileMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, FALSE, thisDirName) + fileMatter := this.matterDao.FindBySpaceNameAndPuuidAndDirAndName(space.Name, dirMatter.Uuid, FALSE, thisDirName) if fileMatter != nil { panic(result.CustomWebResult(result.METHOD_NOT_ALLOWED, fmt.Sprintf("%s file already exists", dirPath))) } diff --git a/code/rest/matter_dao.go b/code/rest/matter_dao.go index c14b7af..90ce61d 100644 --- a/code/rest/matter_dao.go +++ b/code/rest/matter_dao.go @@ -242,6 +242,43 @@ func (this *MatterDao) FindByUserUuidAndPuuidAndDirAndName(userUuid string, puui return matter } +func (this *MatterDao) FindBySpaceNameAndPuuidAndDirAndName(spaceName string, puuid string, dir string, name string) *Matter { + + var matter = &Matter{} + + var wp = &builder.WherePair{} + + if puuid != "" { + wp = wp.And(&builder.WherePair{Query: "puuid = ?", Args: []interface{}{puuid}}) + } + + if spaceName != "" { + wp = wp.And(&builder.WherePair{Query: "space_name = ?", Args: []interface{}{spaceName}}) + } + + if name != "" { + wp = wp.And(&builder.WherePair{Query: "name = ?", Args: []interface{}{name}}) + } + + if dir == TRUE { + wp = wp.And(&builder.WherePair{Query: "dir = ?", Args: []interface{}{true}}) + } else if dir == FALSE { + wp = wp.And(&builder.WherePair{Query: "dir = ?", Args: []interface{}{false}}) + } + + db := core.CONTEXT.GetDB().Where(wp.Query, wp.Args...).First(matter) + + if db.Error != nil { + if db.Error.Error() == result.DB_ERROR_NOT_FOUND { + return nil + } else { + this.PanicError(db.Error) + } + } + + return matter +} + func (this *MatterDao) FindByPuuidAndUserUuid(puuid string, userUuid string, sortArray []builder.OrderPair) []*Matter { return this.FindByPuuidAndUserUuidAndDeleted(puuid, userUuid, "", sortArray) } diff --git a/code/rest/matter_service.go b/code/rest/matter_service.go index 8b650e2..99c06b2 100644 --- a/code/rest/matter_service.go +++ b/code/rest/matter_service.go @@ -613,7 +613,7 @@ func (this *MatterService) createDirectory(request *http.Request, dirMatter *Mat } //if exist. return. - matter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, TRUE, name) + matter := this.matterDao.FindBySpaceNameAndPuuidAndDirAndName(space.Name, dirMatter.Uuid, TRUE, name) if matter != nil { return matter } @@ -637,7 +637,7 @@ func (this *MatterService) createDirectory(request *http.Request, dirMatter *Mat Puuid: dirMatter.Uuid, UserUuid: user.Uuid, SpaceUuid: space.Uuid, - SpaceName: user.Username, + SpaceName: space.Name, Dir: true, Name: name, Path: relativePath, @@ -914,7 +914,7 @@ func (this *MatterService) AtomicRename(request *http.Request, matter *Matter, n } //check whether the name used by another matter. - oldMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, matter.Puuid, "", name) + oldMatter := this.matterDao.FindBySpaceNameAndPuuidAndDirAndName(space.Name, matter.Puuid, "", name) if oldMatter != nil { if overwrite { //delete this one. @@ -1022,7 +1022,7 @@ func (this *MatterService) mirror(request *http.Request, srcPath string, destDir if fileStat.IsDir() { //判断当前文件夹下,文件是否已经存在了。 - srcDirMatter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, destDirMatter.Uuid, TRUE, fileStat.Name()) + srcDirMatter := this.matterDao.FindBySpaceNameAndPuuidAndDirAndName(space.Name, destDirMatter.Uuid, TRUE, fileStat.Name()) if srcDirMatter == nil { srcDirMatter = this.createDirectory(request, destDirMatter, fileStat.Name(), user, space) @@ -1041,7 +1041,7 @@ func (this *MatterService) mirror(request *http.Request, srcPath string, destDir } else { //判断当前文件夹下,文件是否已经存在了。 - matter := this.matterDao.FindByUserUuidAndPuuidAndDirAndName(user.Uuid, destDirMatter.Uuid, FALSE, fileStat.Name()) + matter := this.matterDao.FindBySpaceNameAndPuuidAndDirAndName(space.Name, destDirMatter.Uuid, FALSE, fileStat.Name()) if matter != nil { //如果是覆盖,那么删除之前的文件 if overwrite { diff --git a/code/rest/space_controller.go b/code/rest/space_controller.go index 33ddfaf..a3bbe6f 100644 --- a/code/rest/space_controller.go +++ b/code/rest/space_controller.go @@ -33,6 +33,11 @@ func (this *SpaceController) Init() { this.spaceMemberDao = b } + b = core.CONTEXT.GetBean(this.spaceMemberService) + if b, ok := b.(*SpaceMemberService); ok { + this.spaceMemberService = b + } + b = core.CONTEXT.GetBean(this.matterDao) if b, ok := b.(*MatterDao); ok { this.matterDao = b diff --git a/code/rest/space_service.go b/code/rest/space_service.go index e3ab36a..dd59b46 100644 --- a/code/rest/space_service.go +++ b/code/rest/space_service.go @@ -112,7 +112,7 @@ func (this *SpaceService) CheckWritableByUuid(request *http.Request, user *User, return space } - manage := this.spaceMemberService.canManage(user, spaceUuid) + manage := this.spaceMemberService.canWrite(user, spaceUuid) if !manage { panic(result.BadRequestI18n(request, i18n.PermissionDenied)) } diff --git a/code/support/tank_context.go b/code/support/tank_context.go index f4a95f8..8954a19 100644 --- a/code/support/tank_context.go +++ b/code/support/tank_context.go @@ -81,7 +81,7 @@ func (this *TankContext) OpenDb() { log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer logger.Config{ SlowThreshold: time.Second, // slow SQL 1s - LogLevel: logger.Info, // log level. open when debug. + LogLevel: logger.Warn, // log level. open when debug. IgnoreRecordNotFoundError: true, // ignore ErrRecordNotFound Colorful: false, // colorful print },