|
|
|
@ -1,6 +1,7 @@ |
|
|
|
package rest |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/base64" |
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
@ -63,6 +64,8 @@ func (this *ShareController) RegisterRoutes() map[string]func(writer http.Respon |
|
|
|
routeMap["/api/share/page"] = this.Wrap(this.Page, USER_ROLE_USER) |
|
|
|
routeMap["/api/share/browse"] = this.Wrap(this.Browse, USER_ROLE_GUEST) |
|
|
|
routeMap["/api/share/zip"] = this.Wrap(this.Zip, USER_ROLE_GUEST) |
|
|
|
//by han
|
|
|
|
routeMap["/api/share/permits"] = this.Wrap(this.Permits, USER_ROLE_USER) |
|
|
|
|
|
|
|
return routeMap |
|
|
|
} |
|
|
|
@ -72,6 +75,7 @@ func (this *ShareController) Create(writer http.ResponseWriter, request *http.Re |
|
|
|
matterUuids := request.FormValue("matterUuids") |
|
|
|
expireInfinityStr := request.FormValue("expireInfinity") |
|
|
|
expireTimeStr := request.FormValue("expireTime") |
|
|
|
permitListStr := request.FormValue("permitList") |
|
|
|
|
|
|
|
if matterUuids == "" { |
|
|
|
panic(result.BadRequest("matterUuids cannot be null")) |
|
|
|
@ -150,6 +154,15 @@ func (this *ShareController) Create(writer http.ResponseWriter, request *http.Re |
|
|
|
ExpireInfinity: expireInfinity, |
|
|
|
ExpireTime: expireTime, |
|
|
|
} |
|
|
|
|
|
|
|
if permitListStr != "" { |
|
|
|
length := request.FormValue("len") |
|
|
|
permited, err := checkFormatOfPermitList(permitListStr, length) |
|
|
|
if err != nil { |
|
|
|
panic(result.BadRequest("illegal data")) |
|
|
|
} |
|
|
|
share.PermitList = permited |
|
|
|
} |
|
|
|
this.shareDao.Create(share) |
|
|
|
|
|
|
|
for _, matter := range matters { |
|
|
|
@ -163,6 +176,55 @@ func (this *ShareController) Create(writer http.ResponseWriter, request *http.Re |
|
|
|
return this.Success(share) |
|
|
|
} |
|
|
|
|
|
|
|
// by han
|
|
|
|
// Permits 包含2个功能,一是获取权限列表,二是对权限做修改
|
|
|
|
func (this *ShareController) Permits(writer http.ResponseWriter, request *http.Request) *result.WebResult { |
|
|
|
|
|
|
|
uuid := request.FormValue("uuid") |
|
|
|
update := request.FormValue("update") |
|
|
|
permitList := request.FormValue("permitList") |
|
|
|
//uid := request.FormValue("uid") //当前用户
|
|
|
|
|
|
|
|
if uuid == "" { |
|
|
|
panic(result.BadRequest("uuid cannot be null")) |
|
|
|
} |
|
|
|
|
|
|
|
share := this.shareDao.FindByUuid(uuid) |
|
|
|
if share == nil { |
|
|
|
return this.Success(nil) |
|
|
|
} |
|
|
|
|
|
|
|
//通过users参数进行逻辑分支处理
|
|
|
|
if update == "true" && permitList != "" { |
|
|
|
length := request.FormValue("len") |
|
|
|
|
|
|
|
permited, err := checkFormatOfPermitList(permitList, length) |
|
|
|
if err != nil { |
|
|
|
panic(result.BadRequest("illegal data")) |
|
|
|
} |
|
|
|
share.PermitList = permited |
|
|
|
this.shareDao.Save(share) |
|
|
|
return this.Success(nil) |
|
|
|
} |
|
|
|
|
|
|
|
return this.Success(strings.Split(share.PermitList, "|")) |
|
|
|
} |
|
|
|
|
|
|
|
func checkFormatOfPermitList(permitList, length string) (string, error) { |
|
|
|
data, err := base64.StdEncoding.DecodeString(permitList) |
|
|
|
if err != nil { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
|
|
|
|
//简单校验一下数据 格式和长度
|
|
|
|
strs := strings.Split(string(data), "|") |
|
|
|
if strconv.Itoa(len(strs)) != length { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
|
|
|
|
return string(data), nil |
|
|
|
} |
|
|
|
|
|
|
|
func (this *ShareController) Delete(writer http.ResponseWriter, request *http.Request) *result.WebResult { |
|
|
|
|
|
|
|
uuid := request.FormValue("uuid") |
|
|
|
|