Skip to content

Commit

Permalink
Merge pull request #4194 from dragonchaser/ocis-3743-show-hide-share-…
Browse files Browse the repository at this point in the history
…status

show hide share status
  • Loading branch information
dragonchaser authored Sep 25, 2023
2 parents 57fe1d0 + 10a931c commit cbebc4a
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 21 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/add-hide-flag-to-shares.md.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Add hide flag to shares

We have added the ability to hide shares through the
ocs/v2.php/apps/files_sharing/api/v1/shares/pending/ endpoint
by appending a POST-Variable called hide which can be true or false.

https://github.com/cs3org/reva/pull/4194/files
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,5 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/cs3org/go-cs3apis => github.com/2403905/go-cs3apis v0.0.0-20230517122726-727045414fd1
// the replacement build is based on https://github.com/dragonchaser/cs3apis/tree/master
replace github.com/cs3org/go-cs3apis => github.com/dragonchaser/go-cs3apis v0.0.0-20230918130959-ae732d4b8147
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,6 @@ cloud.google.com/go/workflows v1.9.0/go.mod h1:ZGkj1aFIOd9c8Gerkjjq7OW7I5+l6cSvT
contrib.go.opencensus.io/exporter/prometheus v0.4.2 h1:sqfsYl5GIY/L570iT+l93ehxaWJs2/OwXtiWwew3oAg=
contrib.go.opencensus.io/exporter/prometheus v0.4.2/go.mod h1:dvEHbiKmgvbr5pjaF9fpw1KeYcjrnC1J8B+JKjsZyRQ=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/2403905/go-cs3apis v0.0.0-20230517122726-727045414fd1 h1:dOIG9lXUo5CAZbjlegvZpeTqfAlH+zn+0uXbtlZjCPY=
github.com/2403905/go-cs3apis v0.0.0-20230517122726-727045414fd1/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k=
github.com/Azure/azure-storage-blob-go v0.14.0/go.mod h1:SMqIBi+SuiQH32bvyjngEewEeXoPfKMgWlBDaYf6fck=
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
Expand Down Expand Up @@ -531,6 +529,8 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUn
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dragonchaser/go-cs3apis v0.0.0-20230918130959-ae732d4b8147 h1:DIEKyIGBNDDzdwnHlbX2BFABHol6c9EEHuCDdVKgWsA=
github.com/dragonchaser/go-cs3apis v0.0.0-20230918130959-ae732d4b8147/go.mod h1:TKUgPjk4kNU0KLd9ZxoFE74Wv6PiXckF4RB3749FztA=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
Expand Down Expand Up @@ -1729,7 +1729,6 @@ google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
Expand Down
2 changes: 2 additions & 0 deletions internal/http/services/owncloud/ocs/conversions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ type ShareData struct {
Quicklink bool `json:"quicklink,omitempty" xml:"quicklink,omitempty"`
// PasswordProtected represents a public share is password protected
// PasswordProtected bool `json:"password_protected,omitempty" xml:"password_protected,omitempty"`
Hide bool `json:"hide" xml:"hide"`
}

// ShareeData holds share recipient search results
Expand Down Expand Up @@ -229,6 +230,7 @@ func CS3Share2ShareData(ctx context.Context, share *collaboration.Share) (*Share
// Displaynames are added later
UIDOwner: LocalUserIDToString(share.GetCreator()),
UIDFileOwner: LocalUserIDToString(share.GetOwner()),
Hide: share.Hide,
}

if share.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,20 @@ func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, sh
return nil
}

hideFlag, _ := strconv.ParseBool(r.URL.Query().Get("hide"))

// we need to add a path to the share
shareRequest := &collaboration.UpdateReceivedShareRequest{
Share: &collaboration.ReceivedShare{
Share: &collaboration.Share{Id: &collaboration.ShareId{OpaqueId: shareID}},
Share: &collaboration.Share{
Id: &collaboration.ShareId{OpaqueId: shareID},
Hide: hideFlag,
},
MountPoint: &provider.Reference{
Path: mountPoint,
},
},
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state"}},
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state", "hide"}},
}
if rejectShare {
shareRequest.Share.State = collaboration.ShareState_SHARE_STATE_REJECTED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func (h *Handler) updateShare(w http.ResponseWriter, r *http.Request, share *col

share.Permissions = &collaboration.SharePermissions{Permissions: role.CS3ResourcePermissions()}

var fieldMaskPaths = []string{"permissions"}
var fieldMaskPaths = []string{"permissions", "hide"}

expireDate := r.PostFormValue("expireDate")
var expirationTs *types.Timestamp
Expand Down Expand Up @@ -863,6 +863,8 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) {
// which pending state to list
stateFilter := getStateFilter(r.FormValue("state"))

showHidden, _ := strconv.ParseBool(r.URL.Query().Get("show_hidden"))

ctx := r.Context()
p := r.URL.Query().Get("path")
shareRef := r.URL.Query().Get("share_ref")
Expand Down Expand Up @@ -950,6 +952,9 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) {

// TODO(refs) filter out "invalid" shares
for _, rs := range lrsRes.GetShares() {
if rs.Share.Hide && !showHidden {
continue
}
if stateFilter != ocsStateUnknown && rs.GetState() != stateFilter {
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.Filte

h.addFileInfo(ctx, data, info)
h.mapUserIds(ctx, client, data)

// Filter out a share if ShareWith is not found because the user or group already deleted
if data.ShareWith == "" {
continue
Expand Down
30 changes: 17 additions & 13 deletions pkg/appctx/ctxmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,24 @@ func GetKeyValuesFromCtx(ctx context.Context) map[interface{}]interface{} {
}

func getKeyValue(ctx interface{}, m map[interface{}]interface{}) {
ctxVals := reflect.ValueOf(ctx).Elem()
ctxType := reflect.TypeOf(ctx).Elem()
// This is a dirty hack to run with go 1.21.x
reflectCtxValues := reflect.ValueOf(ctx)
if reflectCtxValues.Kind() != reflect.Struct {
ctxVals := reflectCtxValues.Elem()
ctxType := reflect.TypeOf(ctx).Elem()

if ctxType.Kind() == reflect.Struct {
for i := 0; i < ctxVals.NumField(); i++ {
currField, currIf := extractField(ctxVals, ctxType, i)
switch currField {
case "Context":
getKeyValue(currIf, m)
case "key":
nextField, nextIf := extractField(ctxVals, ctxType, i+1)
if nextField == "val" {
m[currIf] = nextIf
i++
if ctxType.Kind() == reflect.Struct {
for i := 0; i < ctxVals.NumField(); i++ {
currField, currIf := extractField(ctxVals, ctxType, i)
switch currField {
case "Context":
getKeyValue(currIf, m)
case "key":
nextField, nextIf := extractField(ctxVals, ctxType, i+1)
if nextField == "val" {
m[currIf] = nextIf
i++
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/share/manager/cs3/cs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ func (m *Manager) UpdateReceivedShare(ctx context.Context, rshare *collaboration
rs.State = rshare.State
case "mount_point":
rs.MountPoint = rshare.MountPoint
case "hide":
continue
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/share/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ func (m *mgr) UpdateShare(ctx context.Context, ref *collaboration.ShareReference
m.model.Shares[idx].Permissions = updated.Permissions
case "expiration":
m.model.Shares[idx].Expiration = updated.Expiration
case "hide":
continue
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/share/manager/jsoncs3/jsoncs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati

if share.IsGrantedToUser(s, user) {
if share.MatchesFiltersWithState(s, state.State, filters) {
s.Hide = state.Hide
rs := &collaboration.ReceivedShare{
Share: s,
State: state.State,
Expand Down Expand Up @@ -933,6 +934,7 @@ func (m *Manager) convert(ctx context.Context, userID string, s *collaboration.S
if err == nil && state != nil {
rs.State = state.State
rs.MountPoint = state.MountPoint
rs.Share.Hide = state.Hide
}
return rs
}
Expand Down Expand Up @@ -997,6 +999,8 @@ func (m *Manager) UpdateReceivedShare(ctx context.Context, receivedShare *collab
rs.State = receivedShare.State
case "mount_point":
rs.MountPoint = receivedShare.MountPoint
case "hide":
rs.Share.Hide = receivedShare.Share.Hide
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
Expand Down
103 changes: 103 additions & 0 deletions pkg/share/manager/jsoncs3/jsoncs3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,36 @@ var _ = Describe("Jsoncs3", func() {
})
Expect(err).ToNot(HaveOccurred())
Expect(rs.MountPoint.Path).To(Equal("newMP"))
Expect(rs.Share.Hide).To(Equal(false))
})

It("hides the share", func() {
rs, err := m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{
Spec: &collaboration.ShareReference_Id{
Id: share.Id,
},
})
Expect(err).ToNot(HaveOccurred())
Expect(rs.MountPoint).To(BeNil())

rs.MountPoint = &providerv1beta1.Reference{
Path: "newMP",
}
rs.Share.Hide = true

rs, err = m.UpdateReceivedShare(granteeCtx, rs, &fieldmaskpb.FieldMask{Paths: []string{"hide", "mount_point"}}, nil)
Expect(err).ToNot(HaveOccurred())
Expect(rs.MountPoint.Path).To(Equal("newMP"))
Expect(rs.Share.Hide).To(Equal(true))

rs, err = m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{
Spec: &collaboration.ShareReference_Id{
Id: share.Id,
},
})
Expect(err).ToNot(HaveOccurred())
Expect(rs.MountPoint.Path).To(Equal("newMP"))
Expect(rs.Share.Hide).To(Equal(true))
})

It("handles invalid field masks", func() {
Expand Down Expand Up @@ -1030,6 +1060,79 @@ var _ = Describe("Jsoncs3", func() {
Expect(err).ToNot(HaveOccurred())
Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED))
})

It("hides share and persists the change", func() {
rs, err := m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{
Spec: &collaboration.ShareReference_Id{
Id: gshare.Id,
},
})
Expect(err).ToNot(HaveOccurred())
Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_PENDING))

rs.State = collaboration.ShareState_SHARE_STATE_ACCEPTED
rs.Share.Hide = true
rs, err = m.UpdateReceivedShare(granteeCtx, rs, &fieldmaskpb.FieldMask{Paths: []string{"state", "hide"}}, nil)
Expect(err).ToNot(HaveOccurred())
Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED))
Expect(rs.Share.Hide).To(Equal(true))

m, err := jsoncs3.New(storage, nil, 0, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

rs, err = m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{
Spec: &collaboration.ShareReference_Id{
Id: gshare.Id,
},
})
Expect(rs.Share.Hide).To(Equal(true))
Expect(err).ToNot(HaveOccurred())
Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED))
})

It("hides and unhides the share and persists the change", func() {
rs, err := m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{
Spec: &collaboration.ShareReference_Id{
Id: gshare.Id,
},
})
Expect(err).ToNot(HaveOccurred())
Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_PENDING))

rs.State = collaboration.ShareState_SHARE_STATE_ACCEPTED
rs.Share.Hide = true
rs, err = m.UpdateReceivedShare(granteeCtx, rs, &fieldmaskpb.FieldMask{Paths: []string{"state", "hide"}}, nil)
Expect(err).ToNot(HaveOccurred())
Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED))
Expect(rs.Share.Hide).To(Equal(true))

m, err := jsoncs3.New(storage, nil, 0, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

rs, err = m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{
Spec: &collaboration.ShareReference_Id{
Id: gshare.Id,
},
})
Expect(rs.Share.Hide).To(Equal(true))
Expect(err).ToNot(HaveOccurred())
Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED))

rs.Share.Hide = false
rs, err = m.UpdateReceivedShare(granteeCtx, rs, &fieldmaskpb.FieldMask{Paths: []string{"state", "hide"}}, nil)
Expect(err).ToNot(HaveOccurred())
Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED))
Expect(rs.Share.Hide).To(Equal(false))

rs, err = m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{
Spec: &collaboration.ShareReference_Id{
Id: gshare.Id,
},
})
Expect(rs.Share.Hide).To(Equal(false))
Expect(err).ToNot(HaveOccurred())
Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED))
})
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Space struct {
type State struct {
State collaboration.ShareState
MountPoint *provider.Reference
Hide bool
}

// New returns a new Cache instance
Expand Down Expand Up @@ -117,6 +118,7 @@ func (c *Cache) Add(ctx context.Context, userID, spaceID string, rs *collaborati
receivedSpace.States[rs.Share.Id.GetOpaqueId()] = &State{
State: rs.State,
MountPoint: rs.MountPoint,
Hide: rs.Share.Hide,
}

return c.persist(ctx, userID)
Expand Down
4 changes: 4 additions & 0 deletions pkg/share/manager/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ func (m *manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer
m.shares[i].Permissions = updated.Permissions
case "expiration":
m.shares[i].Expiration = updated.Expiration
case "hide":
m.shares[i].Hide = updated.Hide
default:
return nil, errtypes.NotSupported("updating " + path + " is not supported")
}
Expand Down Expand Up @@ -359,6 +361,8 @@ func (m *manager) UpdateReceivedShare(ctx context.Context, receivedShare *collab
rs.State = receivedShare.State
case "mount_point":
rs.MountPoint = receivedShare.MountPoint
case "hide":
continue
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/share/manager/owncloudsql/owncloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ func (m *mgr) UpdateReceivedShare(ctx context.Context, receivedShare *collaborat
fields = append(fields, "file_target=?")
rs.MountPoint = receivedShare.MountPoint
params = append(params, rs.MountPoint.Path)
case "hide":
continue
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
Expand Down

0 comments on commit cbebc4a

Please sign in to comment.