mirror of
https://github.com/eyebluecn/tank.git
synced 2024-04-21 12:32:16 +00:00
fix: add the space info into user's struct.
This commit is contained in:
@@ -78,7 +78,6 @@ func (this *MatterController) RegisterRoutes() map[string]func(writer http.Respo
|
||||
routeMap := make(map[string]func(writer http.ResponseWriter, request *http.Request))
|
||||
routeMap["/api/matter/detail"] = this.Wrap(this.Detail, USER_ROLE_USER)
|
||||
routeMap["/api/matter/page"] = this.Wrap(this.Page, USER_ROLE_USER)
|
||||
routeMap["/api/matter/share/page"] = this.Wrap(this.SharePage, USER_ROLE_USER)
|
||||
|
||||
routeMap["/api/matter/create/directory"] = this.Wrap(this.CreateDirectory, USER_ROLE_USER)
|
||||
routeMap["/api/matter/upload"] = this.Wrap(this.Upload, USER_ROLE_USER)
|
||||
@@ -186,88 +185,6 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
|
||||
return this.Success(pager)
|
||||
}
|
||||
|
||||
// 分享的列表接口走这个接口了。 FIXME: 这个接口还没有测试。
|
||||
func (this *MatterController) SharePage(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
page := util.ExtractRequestOptionalInt(request, "page", 0)
|
||||
pageSize := util.ExtractRequestOptionalInt(request, "pageSize", 200)
|
||||
orderCreateTime := util.ExtractRequestOptionalString(request, "orderCreateTime", "")
|
||||
orderUpdateTime := util.ExtractRequestOptionalString(request, "orderUpdateTime", "")
|
||||
orderDeleteTime := util.ExtractRequestOptionalString(request, "orderDeleteTime", "")
|
||||
orderSort := util.ExtractRequestOptionalString(request, "orderSort", "")
|
||||
orderTimes := util.ExtractRequestOptionalString(request, "orderTimes", "")
|
||||
puuid := util.ExtractRequestOptionalString(request, "puuid", "")
|
||||
name := util.ExtractRequestOptionalString(request, "name", "")
|
||||
dir := util.ExtractRequestOptionalString(request, "dir", "")
|
||||
deleted := util.ExtractRequestOptionalString(request, "deleted", "")
|
||||
orderDir := util.ExtractRequestOptionalString(request, "orderDir", "")
|
||||
orderSize := util.ExtractRequestOptionalString(request, "orderSize", "")
|
||||
orderName := util.ExtractRequestOptionalString(request, "orderName", "")
|
||||
extensionsStr := util.ExtractRequestOptionalString(request, "extensions", "")
|
||||
//auth by shareUuid.
|
||||
shareUuid := util.ExtractRequestString(request, "shareUuid")
|
||||
shareCode := util.ExtractRequestString(request, "shareCode")
|
||||
shareRootUuid := util.ExtractRequestString(request, "shareRootUuid")
|
||||
|
||||
if puuid == "" {
|
||||
panic(result.BadRequest("puuid cannot be null"))
|
||||
}
|
||||
|
||||
dirMatter := this.matterDao.CheckByUuid(puuid)
|
||||
if !dirMatter.Dir {
|
||||
panic(result.BadRequest("puuid is not a directory"))
|
||||
}
|
||||
|
||||
user := this.findUser(request)
|
||||
|
||||
this.shareService.ValidateMatter(request, shareUuid, shareCode, user, shareRootUuid, dirMatter)
|
||||
puuid = dirMatter.Uuid
|
||||
|
||||
var extensions []string
|
||||
if extensionsStr != "" {
|
||||
extensions = strings.Split(extensionsStr, ",")
|
||||
}
|
||||
|
||||
sortArray := []builder.OrderPair{
|
||||
{
|
||||
Key: "dir",
|
||||
Value: orderDir,
|
||||
},
|
||||
{
|
||||
Key: "create_time",
|
||||
Value: orderCreateTime,
|
||||
},
|
||||
{
|
||||
Key: "update_time",
|
||||
Value: orderUpdateTime,
|
||||
},
|
||||
{
|
||||
Key: "delete_time",
|
||||
Value: orderDeleteTime,
|
||||
},
|
||||
{
|
||||
Key: "sort",
|
||||
Value: orderSort,
|
||||
},
|
||||
{
|
||||
Key: "size",
|
||||
Value: orderSize,
|
||||
},
|
||||
{
|
||||
Key: "name",
|
||||
Value: orderName,
|
||||
},
|
||||
{
|
||||
Key: "times",
|
||||
Value: orderTimes,
|
||||
},
|
||||
}
|
||||
|
||||
pager := this.matterDao.Page(page, pageSize, puuid, "", dirMatter.SpaceUuid, name, dir, deleted, extensions, sortArray)
|
||||
|
||||
return this.Success(pager)
|
||||
}
|
||||
|
||||
func (this *MatterController) CreateDirectory(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
puuid := util.ExtractRequestString(request, "puuid")
|
||||
|
||||
@@ -63,6 +63,8 @@ func (this *ShareController) RegisterRoutes() map[string]func(writer http.Respon
|
||||
routeMap["/api/share/browse"] = this.Wrap(this.Browse, USER_ROLE_GUEST)
|
||||
routeMap["/api/share/zip"] = this.Wrap(this.Zip, USER_ROLE_GUEST)
|
||||
|
||||
routeMap["/api/share/matter/page"] = this.Wrap(this.SharePage, USER_ROLE_USER)
|
||||
|
||||
return routeMap
|
||||
}
|
||||
|
||||
@@ -266,6 +268,7 @@ func (this *ShareController) CheckShare(writer http.ResponseWriter, request *htt
|
||||
return this.shareService.CheckShare(request, shareUuid, code, user)
|
||||
}
|
||||
|
||||
// get the basic info of this share.
|
||||
func (this *ShareController) Browse(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
shareUuid := request.FormValue("shareUuid")
|
||||
@@ -375,3 +378,85 @@ func (this *ShareController) Zip(writer http.ResponseWriter, request *http.Reque
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 分享下的文件列表
|
||||
func (this *ShareController) SharePage(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
page := util.ExtractRequestOptionalInt(request, "page", 0)
|
||||
pageSize := util.ExtractRequestOptionalInt(request, "pageSize", 200)
|
||||
orderCreateTime := util.ExtractRequestOptionalString(request, "orderCreateTime", "")
|
||||
orderUpdateTime := util.ExtractRequestOptionalString(request, "orderUpdateTime", "")
|
||||
orderDeleteTime := util.ExtractRequestOptionalString(request, "orderDeleteTime", "")
|
||||
orderSort := util.ExtractRequestOptionalString(request, "orderSort", "")
|
||||
orderTimes := util.ExtractRequestOptionalString(request, "orderTimes", "")
|
||||
puuid := util.ExtractRequestOptionalString(request, "puuid", "")
|
||||
name := util.ExtractRequestOptionalString(request, "name", "")
|
||||
dir := util.ExtractRequestOptionalString(request, "dir", "")
|
||||
deleted := util.ExtractRequestOptionalString(request, "deleted", "")
|
||||
orderDir := util.ExtractRequestOptionalString(request, "orderDir", "")
|
||||
orderSize := util.ExtractRequestOptionalString(request, "orderSize", "")
|
||||
orderName := util.ExtractRequestOptionalString(request, "orderName", "")
|
||||
extensionsStr := util.ExtractRequestOptionalString(request, "extensions", "")
|
||||
//auth by shareUuid.
|
||||
shareUuid := util.ExtractRequestString(request, "shareUuid")
|
||||
shareCode := util.ExtractRequestString(request, "shareCode")
|
||||
shareRootUuid := util.ExtractRequestString(request, "shareRootUuid")
|
||||
|
||||
if puuid == "" {
|
||||
panic(result.BadRequest("puuid cannot be null"))
|
||||
}
|
||||
|
||||
dirMatter := this.matterDao.CheckByUuid(puuid)
|
||||
if !dirMatter.Dir {
|
||||
panic(result.BadRequest("puuid is not a directory"))
|
||||
}
|
||||
|
||||
user := this.findUser(request)
|
||||
|
||||
this.shareService.ValidateMatter(request, shareUuid, shareCode, user, shareRootUuid, dirMatter)
|
||||
puuid = dirMatter.Uuid
|
||||
|
||||
var extensions []string
|
||||
if extensionsStr != "" {
|
||||
extensions = strings.Split(extensionsStr, ",")
|
||||
}
|
||||
|
||||
sortArray := []builder.OrderPair{
|
||||
{
|
||||
Key: "dir",
|
||||
Value: orderDir,
|
||||
},
|
||||
{
|
||||
Key: "create_time",
|
||||
Value: orderCreateTime,
|
||||
},
|
||||
{
|
||||
Key: "update_time",
|
||||
Value: orderUpdateTime,
|
||||
},
|
||||
{
|
||||
Key: "delete_time",
|
||||
Value: orderDeleteTime,
|
||||
},
|
||||
{
|
||||
Key: "sort",
|
||||
Value: orderSort,
|
||||
},
|
||||
{
|
||||
Key: "size",
|
||||
Value: orderSize,
|
||||
},
|
||||
{
|
||||
Key: "name",
|
||||
Value: orderName,
|
||||
},
|
||||
{
|
||||
Key: "times",
|
||||
Value: orderTimes,
|
||||
},
|
||||
}
|
||||
|
||||
pager := this.matterDao.Page(page, pageSize, puuid, "", dirMatter.SpaceUuid, name, dir, deleted, extensions, sortArray)
|
||||
|
||||
return this.Success(pager)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
//@Service
|
||||
// @Service
|
||||
type ShareService struct {
|
||||
BaseBean
|
||||
shareDao *ShareDao
|
||||
@@ -74,7 +74,7 @@ func (this *ShareService) CheckShare(request *http.Request, shareUuid string, co
|
||||
return share
|
||||
}
|
||||
|
||||
//check whether a user can access a matter. shareRootUuid is matter's parent(or parent's parent and so on)
|
||||
// check whether a user can access a matter. shareRootUuid is matter's parent(or parent's parent and so on)
|
||||
func (this *ShareService) ValidateMatter(request *http.Request, shareUuid string, code string, user *User, shareRootUuid string, matter *Matter) {
|
||||
|
||||
if matter == nil {
|
||||
@@ -116,7 +116,7 @@ func (this *ShareService) ValidateMatter(request *http.Request, shareUuid string
|
||||
|
||||
}
|
||||
|
||||
//delete user's shares and corresponding bridges.
|
||||
// delete user's shares and corresponding bridges.
|
||||
func (this *ShareService) DeleteSharesByUser(request *http.Request, currentUser *User) {
|
||||
|
||||
//delete share and bridges.
|
||||
@@ -140,3 +140,8 @@ func (this *ShareService) DeleteSharesByUser(request *http.Request, currentUser
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// edit space's info.
|
||||
func (this *ShareService) Edit(spaceUuid string, sizeLimit int64, totalSizeLimit int64) {
|
||||
|
||||
}
|
||||
|
||||
@@ -86,17 +86,14 @@ func (this *SpaceController) Create(writer http.ResponseWriter, request *http.Re
|
||||
}
|
||||
|
||||
func (this *SpaceController) Edit(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
//space's name
|
||||
|
||||
//space's uuid
|
||||
uuid := util.ExtractRequestString(request, "uuid")
|
||||
sizeLimit := util.ExtractRequestInt64(request, "sizeLimit")
|
||||
totalSizeLimit := util.ExtractRequestInt64(request, "totalSizeLimit")
|
||||
|
||||
space := this.spaceDao.CheckByUuid(uuid)
|
||||
|
||||
space.SizeLimit = sizeLimit
|
||||
space.TotalSizeLimit = totalSizeLimit
|
||||
|
||||
space = this.spaceDao.Save(space)
|
||||
user := this.checkUser(request)
|
||||
space := this.spaceService.Edit(request, user, uuid, sizeLimit, totalSizeLimit)
|
||||
|
||||
return this.Success(space)
|
||||
}
|
||||
|
||||
@@ -134,3 +134,22 @@ func (this *SpaceService) CheckReadableByUuid(request *http.Request, user *User,
|
||||
|
||||
return space
|
||||
}
|
||||
|
||||
// edit space's info
|
||||
func (this *SpaceService) Edit(request *http.Request, user *User, spaceUuid string, sizeLimit int64, totalSizeLimit int64) *Space {
|
||||
space := this.CheckWritableByUuid(request, user, spaceUuid)
|
||||
|
||||
if sizeLimit < 0 && sizeLimit != -1 {
|
||||
panic("sizeLimit cannot be negative expect -1.")
|
||||
}
|
||||
|
||||
if totalSizeLimit < 0 && totalSizeLimit != -1 {
|
||||
panic("totalSizeLimit cannot be negative expect -1.")
|
||||
}
|
||||
|
||||
space.SizeLimit = sizeLimit
|
||||
space.TotalSizeLimit = totalSizeLimit
|
||||
space = this.spaceDao.Save(space)
|
||||
|
||||
return space
|
||||
}
|
||||
|
||||
@@ -225,6 +225,9 @@ func (this *UserController) Edit(writer http.ResponseWriter, request *http.Reque
|
||||
avatarUrl := request.FormValue("avatarUrl")
|
||||
role := request.FormValue("role")
|
||||
|
||||
sizeLimit := util.ExtractRequestInt64(request, "sizeLimit")
|
||||
totalSizeLimit := util.ExtractRequestInt64(request, "totalSizeLimit")
|
||||
|
||||
user := this.checkUser(request)
|
||||
currentUser := this.userDao.CheckByUuid(uuid)
|
||||
|
||||
@@ -241,11 +244,17 @@ func (this *UserController) Edit(writer http.ResponseWriter, request *http.Reque
|
||||
panic(result.UNAUTHORIZED)
|
||||
}
|
||||
|
||||
//edit user's info
|
||||
currentUser = this.userDao.Save(currentUser)
|
||||
|
||||
//edit user's private space info.
|
||||
space := this.spaceService.Edit(request, user, currentUser.SpaceUuid, sizeLimit, totalSizeLimit)
|
||||
|
||||
//remove cache user.
|
||||
this.userService.RemoveCacheUserByUuid(currentUser.Uuid)
|
||||
|
||||
currentUser.Space = space
|
||||
|
||||
return this.Success(currentUser)
|
||||
}
|
||||
|
||||
@@ -255,6 +264,10 @@ func (this *UserController) Detail(writer http.ResponseWriter, request *http.Req
|
||||
|
||||
user := this.userDao.CheckByUuid(uuid)
|
||||
|
||||
//append the space info.
|
||||
space := this.spaceDao.FindByUuid(user.SpaceUuid)
|
||||
user.Space = space
|
||||
|
||||
return this.Success(user)
|
||||
|
||||
}
|
||||
@@ -339,6 +352,12 @@ func (this *UserController) Page(writer http.ResponseWriter, request *http.Reque
|
||||
|
||||
pager := this.userDao.Page(page, pageSize, username, status, sortArray)
|
||||
|
||||
//append the space info. FIXME: user better way to get Space.
|
||||
for _, u := range pager.Data.([]*User) {
|
||||
space := this.spaceDao.FindByUuid(u.SpaceUuid)
|
||||
u.Space = space
|
||||
}
|
||||
|
||||
return this.Success(pager)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user