Skip to content

Commit

Permalink
Do not display denial shares on Shared-with-me
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Sep 15, 2021
1 parent d04e363 commit 6ab5f79
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
11 changes: 11 additions & 0 deletions internal/grpc/services/usershareprovider/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ func (s *service) UpdateShare(ctx context.Context, req *collaboration.UpdateShar
}

func (s *service) ListReceivedShares(ctx context.Context, req *collaboration.ListReceivedSharesRequest) (*collaboration.ListReceivedSharesResponse, error) {
// For the UI add a filter to not display the denial shares
foundExclude := false
for _, f := range req.Filters {
if f.Type == collaboration.Filter_TYPE_EXCLUDE_DENIALS {
foundExclude = true
break
}
}
if !foundExclude {
req.Filters = append(req.Filters, &collaboration.Filter{Type: collaboration.Filter_TYPE_EXCLUDE_DENIALS})
}
shares, err := s.sm.ListReceivedShares(ctx, req.Filters) // TODO(labkode): check what to update
if err != nil {
return &collaboration.ListReceivedSharesResponse{
Expand Down
38 changes: 25 additions & 13 deletions pkg/cbox/share/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,20 @@ func (m *mgr) UpdateShare(ctx context.Context, ref *collaboration.ShareReference

func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.Share, error) {
uid := conversions.FormatUserID(ctxpkg.ContextMustGetUser(ctx).Id)
query := "select coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, coalesce(share_with, '') as share_with, coalesce(fileid_prefix, '') as fileid_prefix, coalesce(item_source, '') as item_source, id, stime, permissions, share_type FROM oc_share WHERE (orphan = 0 or orphan IS NULL) AND (uid_owner=? or uid_initiator=?) AND (share_type=? OR share_type=?)"
var filterQuery string
query := `SELECT coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, coalesce(share_with, '') as share_with,
coalesce(fileid_prefix, '') as fileid_prefix, coalesce(item_source, '') as item_source, id, stime, permissions, share_type
FROM oc_share
WHERE (orphan = 0 or orphan IS NULL) AND (uid_owner=? or uid_initiator=?) AND (share_type=? OR share_type=?)`
params := []interface{}{uid, uid, 0, 1}
for i, f := range filters {
for _, f := range filters {
if f.Type == collaboration.Filter_TYPE_RESOURCE_ID {
filterQuery += "(fileid_prefix=? AND item_source=?)"
if i != len(filters)-1 {
filterQuery += " AND "
}
query += " AND (fileid_prefix=? AND item_source=?)"
params = append(params, f.GetResourceId().StorageId, f.GetResourceId().OpaqueId)
} else if f.Type == collaboration.Filter_TYPE_EXCLUDE_DENIALS {
// TODO this may change once the mapping of permission to share types is completed (cf. pkg/cbox/utils/conversions.go)
query += " AND (permissions > 0)"
}
}
if filterQuery != "" {
query = fmt.Sprintf("%s AND (%s)", query, filterQuery)
}

rows, err := m.db.Query(query, params...)
if err != nil {
Expand Down Expand Up @@ -323,11 +322,24 @@ func (m *mgr) ListReceivedShares(ctx context.Context, filters []*collaboration.F
params = append(params, v)
}

query := "select coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, coalesce(share_with, '') as share_with, coalesce(fileid_prefix, '') as fileid_prefix, coalesce(item_source, '') as item_source, ts.id, stime, permissions, share_type, accepted, coalesce(tr.rejected_by, '') as rejected_by FROM oc_share ts LEFT JOIN oc_share_acl tr ON (ts.id = tr.id AND tr.rejected_by = ?) WHERE (orphan = 0 or orphan IS NULL) AND (uid_owner != ? AND uid_initiator != ?) "
query := `SELECT coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, coalesce(share_with, '') as share_with,
coalesce(fileid_prefix, '') as fileid_prefix, coalesce(item_source, '') as item_source, ts.id, stime,
permissions, share_type, accepted, coalesce(tr.rejected_by, '') as rejected_by
FROM oc_share ts LEFT JOIN oc_share_acl tr ON (ts.id = tr.id AND tr.rejected_by = ?)
WHERE (orphan = 0 or orphan IS NULL) AND (uid_owner != ? AND uid_initiator != ?)`
if len(user.Groups) > 0 {
query += "AND (share_with=? OR share_with in (?" + strings.Repeat(",?", len(user.Groups)-1) + "))"
query += " AND (share_with=? OR share_with in (?" + strings.Repeat(",?", len(user.Groups)-1) + "))"
} else {
query += "AND (share_with=?)"
query += " AND (share_with=?)"
}

for _, f := range filters {
if f.Type == collaboration.Filter_TYPE_RESOURCE_ID {
query += " AND (fileid_prefix=? AND item_source=?)"
params = append(params, f.GetResourceId().StorageId, f.GetResourceId().OpaqueId)
} else if f.Type == collaboration.Filter_TYPE_EXCLUDE_DENIALS {
query += " AND (permissions > 0)"
}
}

rows, err := m.db.Query(query, params...)
Expand Down
2 changes: 2 additions & 0 deletions pkg/cbox/utils/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func SharePermToInt(p *provider.ResourcePermissions) int {
} else if p.ListContainer {
perm = 1
}
// TODO map denials and resharing; currently, denials are mapped to 0
return perm
}

Expand Down Expand Up @@ -143,6 +144,7 @@ func IntTosharePerm(p int) *provider.ResourcePermissions {
PurgeRecycle: true,
}
default:
// TODO we may have other options, for now this is a denial
return &provider.ResourcePermissions{}
}
}
Expand Down

0 comments on commit 6ab5f79

Please sign in to comment.