|
@@ -24,6 +24,7 @@ import (
|
|
|
"net/url"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
+ "sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -951,9 +952,9 @@ func (s *Manager) HandleEditShare(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
func (s *Manager) HandleDeleteShare(w http.ResponseWriter, r *http.Request) {
|
|
|
//Get the vpath from paramters
|
|
|
- vpath, err := mv(r, "path", true)
|
|
|
+ uuid, err := mv(r, "uuid", true)
|
|
|
if err != nil {
|
|
|
- sendErrorResponse(w, "Invalid path given")
|
|
|
+ sendErrorResponse(w, "Invalid uuid given")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -965,7 +966,7 @@ func (s *Manager) HandleDeleteShare(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
//Delete the share setting
|
|
|
- err = s.DeleteShare(userinfo, vpath)
|
|
|
+ err = s.DeleteShareByUUID(userinfo, uuid)
|
|
|
|
|
|
if err != nil {
|
|
|
sendErrorResponse(w, err.Error())
|
|
@@ -995,7 +996,7 @@ func (s *Manager) HandleListAllShares(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
}
|
|
|
} else {
|
|
|
- //List fsh onlya
|
|
|
+ //List fsh only
|
|
|
targetFsh, err := userinfo.GetFileSystemHandlerFromVirtualPath(fshId)
|
|
|
if err != nil {
|
|
|
common.SendErrorResponse(w, err.Error())
|
|
@@ -1009,10 +1010,70 @@ func (s *Manager) HandleListAllShares(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- js, _ := json.Marshal(results)
|
|
|
+ //Reduce the data
|
|
|
+ type Share struct {
|
|
|
+ UUID string
|
|
|
+ FileVirtualPath string
|
|
|
+ Owner string
|
|
|
+ Permission string
|
|
|
+ IsFolder bool
|
|
|
+ IsOwnerOfShare bool
|
|
|
+ CanAccess bool
|
|
|
+ CanOpenInFileManager bool
|
|
|
+ CanDelete bool
|
|
|
+ }
|
|
|
+
|
|
|
+ reducedResult := []*Share{}
|
|
|
+ for _, result := range results {
|
|
|
+ permissionText := result.Permission
|
|
|
+ if result.Permission == "groups" || result.Permission == "users" {
|
|
|
+ permissionText = permissionText + " (" + strings.Join(result.Accessibles, ", ") + ")"
|
|
|
+ }
|
|
|
+ thisShareInfo := Share{
|
|
|
+ UUID: result.UUID,
|
|
|
+ FileVirtualPath: result.FileVirtualPath,
|
|
|
+ Owner: result.Owner,
|
|
|
+ Permission: permissionText,
|
|
|
+ IsFolder: result.IsFolder,
|
|
|
+ IsOwnerOfShare: userinfo.Username == result.Owner,
|
|
|
+ CanAccess: result.IsAccessibleBy(userinfo.Username, userinfo.GetUserPermissionGroupNames()),
|
|
|
+ CanOpenInFileManager: s.UserCanOpenShareInFileManager(result, userinfo),
|
|
|
+ CanDelete: s.CanModifyShareEntry(userinfo, result.FileVirtualPath),
|
|
|
+ }
|
|
|
+
|
|
|
+ reducedResult = append(reducedResult, &thisShareInfo)
|
|
|
+ }
|
|
|
+
|
|
|
+ js, _ := json.Marshal(reducedResult)
|
|
|
common.SendJSONResponse(w, string(js))
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+ Check if the user can open the share in File Manager
|
|
|
+
|
|
|
+ There are two conditions where the user can open the file in file manager
|
|
|
+ 1. If the user is the owner of the file
|
|
|
+ 2. If the user is NOT the owner of the file but the target fsh is public accessible and in user's fsh list
|
|
|
+*/
|
|
|
+func (s *Manager) UserCanOpenShareInFileManager(share *shareEntry.ShareOption, userinfo *user.User) bool {
|
|
|
+ if share.Owner == userinfo.Username {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ fsh, err := userinfo.GetFileSystemHandlerFromVirtualPath(share.FileVirtualPath)
|
|
|
+ if err != nil {
|
|
|
+ //User do not have permission to access this fsh
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ rpath, _ := fsh.FileSystemAbstraction.VirtualPathToRealPath(share.FileVirtualPath, userinfo.Username)
|
|
|
+ if fsh.Hierarchy == "public" && fsh.FileSystemAbstraction.FileExists(rpath) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
//Craete a new file or folder share
|
|
|
func (s *Manager) CreateNewShare(userinfo *user.User, srcFsh *filesystem.FileSystemHandler, vpath string) (*shareEntry.ShareOption, error) {
|
|
|
//Translate the vpath to realpath
|
|
@@ -1085,6 +1146,10 @@ func (s *Manager) ListAllShareByFshId(fshId string, userinfo *user.User) []*shar
|
|
|
return true
|
|
|
})
|
|
|
|
|
|
+ sort.Slice(results, func(i, j int) bool {
|
|
|
+ return results[i].UUID < results[j].UUID
|
|
|
+ })
|
|
|
+
|
|
|
return results
|
|
|
}
|
|
|
|
|
@@ -1153,10 +1218,20 @@ func (s *Manager) CanModifyShareEntry(userinfo *user.User, vpath string) bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+ //Public fsh where the user and owner both can access
|
|
|
+ fsh, err := userinfo.GetFileSystemHandlerFromVirtualPath(vpath)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ rpath, _ := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, userinfo.Username)
|
|
|
+ if fsh.Hierarchy == "public" && fsh.FileSystemAbstraction.FileExists(rpath) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
-func (s *Manager) DeleteShare(userinfo *user.User, vpath string) error {
|
|
|
+func (s *Manager) DeleteShareByVpath(userinfo *user.User, vpath string) error {
|
|
|
ps := getPathHashFromUsernameAndVpath(userinfo, vpath)
|
|
|
|
|
|
if !s.CanModifyShareEntry(userinfo, vpath) {
|
|
@@ -1165,6 +1240,19 @@ func (s *Manager) DeleteShare(userinfo *user.User, vpath string) error {
|
|
|
return s.options.ShareEntryTable.DeleteShareByPathHash(ps)
|
|
|
}
|
|
|
|
|
|
+func (s *Manager) DeleteShareByUUID(userinfo *user.User, uuid string) error {
|
|
|
+ so := s.GetShareObjectFromUUID(uuid)
|
|
|
+ if so == nil {
|
|
|
+ return errors.New("Invalid share uuid")
|
|
|
+ }
|
|
|
+
|
|
|
+ if !s.CanModifyShareEntry(userinfo, so.FileVirtualPath) {
|
|
|
+ return errors.New("Permission denied")
|
|
|
+ }
|
|
|
+
|
|
|
+ return s.options.ShareEntryTable.DeleteShareByUUID(uuid)
|
|
|
+}
|
|
|
+
|
|
|
func (s *Manager) GetShareUUIDFromUserAndVpath(userinfo *user.User, vpath string) string {
|
|
|
ps := getPathHashFromUsernameAndVpath(userinfo, vpath)
|
|
|
return s.options.ShareEntryTable.GetShareUUIDFromPathHash(ps)
|