Finish the basic share code validate.
This commit is contained in:
@ -3,14 +3,17 @@ package rest
|
||||
import (
|
||||
"github.com/eyebluecn/tank/code/core"
|
||||
"github.com/eyebluecn/tank/code/tool/result"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
//@Service
|
||||
type ShareService struct {
|
||||
BaseBean
|
||||
shareDao *ShareDao
|
||||
userDao *UserDao
|
||||
shareDao *ShareDao
|
||||
matterDao *MatterDao
|
||||
bridgeDao *BridgeDao
|
||||
userDao *UserDao
|
||||
}
|
||||
|
||||
//初始化方法
|
||||
@ -23,6 +26,16 @@ func (this *ShareService) Init() {
|
||||
this.shareDao = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.matterDao)
|
||||
if b, ok := b.(*MatterDao); ok {
|
||||
this.matterDao = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.bridgeDao)
|
||||
if b, ok := b.(*BridgeDao); ok {
|
||||
this.bridgeDao = b
|
||||
}
|
||||
|
||||
b = core.CONTEXT.GetBean(this.userDao)
|
||||
if b, ok := b.(*UserDao); ok {
|
||||
this.userDao = b
|
||||
@ -60,3 +73,41 @@ func (this *ShareService) CheckShare(shareUuid string, code string, user *User)
|
||||
|
||||
return share
|
||||
}
|
||||
|
||||
//根据某个shareUuid和code,某个用户是否有权限获取 shareRootUuid 下面的 matterUuid
|
||||
//如果是根目录下的文件,那么shareRootUuid传root.
|
||||
func (this *ShareService) ValidateMatter(shareUuid string, code string, user *User, shareRootUuid string, matter *Matter) {
|
||||
|
||||
if matter == nil {
|
||||
panic(result.BadRequest("matter cannot be nil"))
|
||||
}
|
||||
|
||||
//如果文件是自己的,那么放行
|
||||
if user != nil && matter.UserUuid == user.Uuid {
|
||||
return
|
||||
}
|
||||
|
||||
if shareRootUuid == "" {
|
||||
panic(result.BadRequest("matterUuid cannot be null"))
|
||||
}
|
||||
|
||||
share := this.CheckShare(shareUuid, code, user)
|
||||
|
||||
//如果shareRootUuid是根,那么matterUuid在bridge中应该有记录
|
||||
if shareRootUuid == MATTER_ROOT {
|
||||
|
||||
this.bridgeDao.CheckByShareUuidAndMatterUuid(share.Uuid, matter.Uuid)
|
||||
|
||||
} else {
|
||||
//验证 shareRootMatter是否在被分享。
|
||||
shareRootMatter := this.matterDao.CheckByUuid(shareRootUuid)
|
||||
this.bridgeDao.CheckByShareUuidAndMatterUuid(share.Uuid, shareRootMatter.Uuid)
|
||||
|
||||
//保证 puuid对应的matter是shareRootMatter的子文件夹。
|
||||
child := strings.HasPrefix(matter.Path, shareRootMatter.Path)
|
||||
if !child {
|
||||
panic(result.BadRequest("%s 不是 %s 的子文件夹!", matter.Uuid, shareRootUuid))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user