mirror of
https://github.com/eyebluecn/tank.git
synced 2024-04-21 12:32:16 +00:00
fix: fix the bugs for space file upload.
This commit is contained in:
@@ -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)))
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user