Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter shares based on type in OCS #1683

Merged
merged 3 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/share-type-filter-ocs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Filter created shares based on type in OCS

https://github.com/cs3org/reva/pull/1683
Original file line number Diff line number Diff line change
Expand Up @@ -749,28 +749,40 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) {

func (h *Handler) listSharesWithOthers(w http.ResponseWriter, r *http.Request) {
shares := make([]*conversions.ShareData, 0)

filters := []*collaboration.ListSharesRequest_Filter{}
linkFilters := []*link.ListPublicSharesRequest_Filter{}
var err error
var e error

// shared with others
p := r.URL.Query().Get("path")
if p != "" {
// prefix the path with the owners home, because ocs share requests are relative to the home dir
filters, linkFilters, err = h.addFilters(w, r, h.homeNamespace)
if err != nil {
filters, linkFilters, e = h.addFilters(w, r, h.homeNamespace)
if e != nil {
// result has been written as part of addFilters
return
}
}

userShares, status, err := h.listUserShares(r, filters)
h.logProblems(status, err, "could not listUserShares")

publicShares, status, err := h.listPublicShares(r, linkFilters)
h.logProblems(status, err, "could not listPublicShares")

shares = append(shares, append(userShares, publicShares...)...)
shareTypes := strings.Split(r.URL.Query().Get("share_types"), ",")
for _, s := range shareTypes {
shareType, err := strconv.Atoi(strings.TrimSpace(s))
if err != nil && s != "" {
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, "invalid share type", err)
return
}
if s == "" || shareType == int(conversions.ShareTypeUser) || shareType == int(conversions.ShareTypeGroup) {
userShares, status, err := h.listUserShares(r, filters)
h.logProblems(status, err, "could not listUserShares")
shares = append(shares, userShares...)
}
if s == "" || shareType == int(conversions.ShareTypePublicLink) {
publicShares, status, err := h.listPublicShares(r, linkFilters)
h.logProblems(status, err, "could not listPublicShares")
shares = append(shares, publicShares...)
}
}

response.WriteOCSSuccess(w, r, shares)
}
Expand Down
37 changes: 32 additions & 5 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1388,21 +1388,48 @@ func (fs *eosfs) permissionSet(ctx context.Context, eosFileInfo *eosclient.FileI
}
}

uid, gid, err := fs.getUserUIDAndGID(ctx, u)
uid, _, err := fs.getUserUIDAndGID(ctx, u)
if err != nil {
return &provider.ResourcePermissions{
// no permissions
}
}

var perm string
var perm provider.ResourcePermissions
for _, e := range eosFileInfo.SysACL.Entries {
if e.Qualifier == uid || e.Qualifier == gid {
perm = e.Permissions
var userInGroup bool
for _, g := range u.Groups {
if e.Qualifier == g {
userInGroup = true
}
}
if e.Qualifier == uid || userInGroup {
mergePermissions(&perm, grants.GetGrantPermissionSet(e.Permissions, eosFileInfo.IsDir))
}
}

return grants.GetGrantPermissionSet(perm, eosFileInfo.IsDir)
return &perm
}

func mergePermissions(l *provider.ResourcePermissions, r *provider.ResourcePermissions) {
l.AddGrant = l.AddGrant || r.AddGrant
l.CreateContainer = l.CreateContainer || r.CreateContainer
l.Delete = l.Delete || r.Delete
l.GetPath = l.GetPath || r.GetPath
l.GetQuota = l.GetQuota || r.GetQuota
l.InitiateFileDownload = l.InitiateFileDownload || r.InitiateFileDownload
l.InitiateFileUpload = l.InitiateFileUpload || r.InitiateFileUpload
l.ListContainer = l.ListContainer || r.ListContainer
l.ListFileVersions = l.ListFileVersions || r.ListFileVersions
l.ListGrants = l.ListGrants || r.ListGrants
l.ListRecycle = l.ListRecycle || r.ListRecycle
l.Move = l.Move || r.Move
l.PurgeRecycle = l.PurgeRecycle || r.PurgeRecycle
l.RemoveGrant = l.RemoveGrant || r.RemoveGrant
l.RestoreFileVersion = l.RestoreFileVersion || r.RestoreFileVersion
l.RestoreRecycleItem = l.RestoreRecycleItem || r.RestoreRecycleItem
l.Stat = l.Stat || r.Stat
l.UpdateGrant = l.UpdateGrant || r.UpdateGrant
}

func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo, virtualView bool) (*provider.ResourceInfo, error) {
Expand Down