Skip to content

Commit

Permalink
Quicklinks (#2715)
Browse files Browse the repository at this point in the history
* quicklink functionality

Signed-off-by: jkoberg <jkoberg@owncloud.com>

* changelog

Signed-off-by: jkoberg <jkoberg@owncloud.com>

* avoid extra stat call and const

Signed-off-by: jkoberg <jkoberg@owncloud.com>

* use forked cs3api to get access to quicklink field

Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj authored Apr 7, 2022
1 parent c7a9ff1 commit 3cb849a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 11 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/quicklinks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: introduced quicklinks

We now support Quicklinks. When creating a link with flag "quicklink=true", no new link will be created when a link
already exists.

https://github.com/cs3org/reva/pull/2715
4 changes: 2 additions & 2 deletions cmd/reva/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var preferencesCommand = func() *command {
}
value := cmd.Args()[2]
req := &preferences.SetKeyRequest{
Key: key,
Key: &preferences.PreferenceKey{Key: key},
Val: value,
}

Expand All @@ -70,7 +70,7 @@ var preferencesCommand = func() *command {

case "get":
req := &preferences.GetKeyRequest{
Key: key,
Key: &preferences.PreferenceKey{Key: key},
}

res, err := client.GetKey(ctx, req)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ require (
go 1.16

replace (
github.com/cs3org/go-cs3apis => github.com/kobergj/go-cs3apis v0.0.0-20220406134716-65f04386eb09 // temporary fork
github.com/eventials/go-tus => github.com/andrewmostello/go-tus v0.0.0-20200314041820-904a9904af9a
github.com/oleiade/reflections => github.com/oleiade/reflections v1.0.1
google.golang.org/grpc => google.golang.org/grpc v1.26.0 // temporary downgrade
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19 h1:1jqPH58jCxvbaJ9WLIJ7W2/m622bWS6ChptzljSG6IQ=
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20220328105952-297bef33e13f h1:emnlOWc1s2gx77MViLnZH9yh5TRHKsykRu6rJjx3lkM=
github.com/cs3org/go-cs3apis v0.0.0-20220328105952-297bef33e13f/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down Expand Up @@ -639,6 +635,8 @@ github.com/klauspost/compress v1.14.3/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
github.com/kobergj/go-cs3apis v0.0.0-20220406134716-65f04386eb09 h1:i1caLRatgEscEdtcplmwjxHSVve13rQTuRDxo42FZI8=
github.com/kobergj/go-cs3apis v0.0.0-20220406134716-65f04386eb09/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down
6 changes: 3 additions & 3 deletions internal/grpc/services/preferences/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ func (s *service) SetKey(ctx context.Context, req *preferences.SetKeyRequest) (*
mutex.Lock()
defer mutex.Unlock()
if len(m[name]) == 0 {
m[name] = map[string]string{key: value}
m[name] = map[string]string{key.Key: value}
} else {
usersettings := m[name]
usersettings[key] = value
usersettings[key.Key] = value
}

return &preferences.SetKeyResponse{
Expand All @@ -118,7 +118,7 @@ func (s *service) GetKey(ctx context.Context, req *preferences.GetKeyRequest) (*
mutex.Lock()
defer mutex.Unlock()
if len(m[name]) != 0 {
if value, ok := m[name][key]; ok {
if value, ok := m[name][key.Key]; ok {
return &preferences.GetKeyResponse{
Status: status.NewOK(ctx),
Val: value,
Expand Down
3 changes: 3 additions & 0 deletions internal/http/services/owncloud/ocs/conversions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ type ShareData struct {
URL string `json:"url,omitempty" xml:"url,omitempty"`
// Attributes associated
Attributes string `json:"attributes,omitempty" xml:"attributes,omitempty"`
// Quicklink indicates if the link is the quicklink
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"`
}
Expand Down Expand Up @@ -233,6 +235,7 @@ func PublicShare2ShareData(share *link.PublicShare, r *http.Request, publicURL s
URL: publicURL + path.Join("/", "s/"+share.Token),
UIDOwner: LocalUserIDToString(share.Creator),
UIDFileOwner: LocalUserIDToString(share.Owner),
Quicklink: share.Quicklink,
}
if share.Id != nil {
sd.ID = share.Id.OpaqueId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/conversions"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/response"
"github.com/cs3org/reva/v2/pkg/appctx"
"github.com/cs3org/reva/v2/pkg/publicshare"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
"github.com/pkg/errors"
)
Expand All @@ -59,6 +60,33 @@ func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request,
}
}

// check if a quicklink should be created
quick, _ := strconv.ParseBool(r.FormValue("quicklink")) // no need to check the error - defaults to zero value!
if quick {
f := []*link.ListPublicSharesRequest_Filter{publicshare.ResourceIDFilter(statInfo.Id)}
req := link.ListPublicSharesRequest{Filters: f}
res, err := c.ListPublicShares(ctx, &req)
if err != nil {
return nil, &ocsError{
Code: response.MetaServerError.StatusCode,
Message: "could not list public links",
Error: err,
}
}
if res.Status.Code != rpc.Code_CODE_OK {
return nil, &ocsError{
Code: int(res.Status.GetCode()),
Message: "could not list public links",
}
}

for _, l := range res.GetShare() {
if l.Quicklink {
return l, nil
}
}
}

newPermissions, err := permissionFromRequest(r, h)
if err != nil {
return nil, &ocsError{
Expand Down Expand Up @@ -120,7 +148,8 @@ func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request,
// set displayname and password protected as arbitrary metadata
req.ResourceInfo.ArbitraryMetadata = &provider.ArbitraryMetadata{
Metadata: map[string]string{
"name": r.FormValue("name"),
"name": r.FormValue("name"),
"quicklink": r.FormValue("quicklink"),
// "password": r.FormValue("password"),
},
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/publicshare/manager/cs3/cs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"net/url"
"path"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -173,12 +174,14 @@ func (m *Manager) CreatePublicShare(ctx context.Context, u *user.User, ri *provi
tkn := utils.RandString(15)
now := time.Now().UnixNano()

displayName := tkn
displayName, quicklink := tkn, false
if ri.ArbitraryMetadata != nil {
metadataName, ok := ri.ArbitraryMetadata.Metadata["name"]
if ok {
displayName = metadataName
}

quicklink, _ = strconv.ParseBool(ri.ArbitraryMetadata.Metadata["quicklink"])
}

var passwordProtected bool
Expand Down Expand Up @@ -210,6 +213,7 @@ func (m *Manager) CreatePublicShare(ctx context.Context, u *user.User, ri *provi
PasswordProtected: passwordProtected,
Expiration: g.Expiration,
DisplayName: displayName,
Quicklink: quicklink,
},
HashedPassword: password,
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/publicshare/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strconv"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -159,6 +160,8 @@ func (m *manager) CreatePublicShare(ctx context.Context, u *user.User, rInfo *pr
displayName = tkn
}

quicklink, _ := strconv.ParseBool(rInfo.ArbitraryMetadata.Metadata["quicklink"])

var passwordProtected bool
password := g.Password
if len(password) > 0 {
Expand Down Expand Up @@ -187,6 +190,7 @@ func (m *manager) CreatePublicShare(ctx context.Context, u *user.User, rInfo *pr
PasswordProtected: passwordProtected,
Expiration: g.Expiration,
DisplayName: displayName,
Quicklink: quicklink,
}

ps := &publicShare{
Expand Down

0 comments on commit 3cb849a

Please sign in to comment.