Skip to content

Commit f47cc99

Browse files
committed
use forked cs3api to get access to quicklink field
Signed-off-by: jkoberg <[email protected]>
1 parent 7657f63 commit f47cc99

File tree

7 files changed

+23
-36
lines changed

7 files changed

+23
-36
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ require (
9393
go 1.16
9494

9595
replace (
96+
github.com/cs3org/go-cs3apis => github.com/kobergj/go-cs3apis v0.0.0-20220406134716-65f04386eb09 // temporary fork
9697
github.com/eventials/go-tus => github.com/andrewmostello/go-tus v0.0.0-20200314041820-904a9904af9a
9798
github.com/oleiade/reflections => github.com/oleiade/reflections v1.0.1
9899
google.golang.org/grpc => google.golang.org/grpc v1.26.0 // temporary downgrade

go.sum

+2-4
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
207207
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
208208
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
209209
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
210-
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19 h1:1jqPH58jCxvbaJ9WLIJ7W2/m622bWS6ChptzljSG6IQ=
211-
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
212-
github.com/cs3org/go-cs3apis v0.0.0-20220328105952-297bef33e13f h1:emnlOWc1s2gx77MViLnZH9yh5TRHKsykRu6rJjx3lkM=
213-
github.com/cs3org/go-cs3apis v0.0.0-20220328105952-297bef33e13f/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
214210
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
215211
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
216212
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
@@ -639,6 +635,8 @@ github.com/klauspost/compress v1.14.3/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e
639635
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
640636
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
641637
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
638+
github.com/kobergj/go-cs3apis v0.0.0-20220406134716-65f04386eb09 h1:i1caLRatgEscEdtcplmwjxHSVve13rQTuRDxo42FZI8=
639+
github.com/kobergj/go-cs3apis v0.0.0-20220406134716-65f04386eb09/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
642640
github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ=
643641
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
644642
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=

internal/grpc/services/preferences/preferences.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ func (s *service) SetKey(ctx context.Context, req *preferences.SetKeyRequest) (*
9292
mutex.Lock()
9393
defer mutex.Unlock()
9494
if len(m[name]) == 0 {
95-
m[name] = map[string]string{key: value}
95+
m[name] = map[string]string{key.Key: value}
9696
} else {
9797
usersettings := m[name]
98-
usersettings[key] = value
98+
usersettings[key.Key] = value
9999
}
100100

101101
return &preferences.SetKeyResponse{
@@ -118,7 +118,7 @@ func (s *service) GetKey(ctx context.Context, req *preferences.GetKeyRequest) (*
118118
mutex.Lock()
119119
defer mutex.Unlock()
120120
if len(m[name]) != 0 {
121-
if value, ok := m[name][key]; ok {
121+
if value, ok := m[name][key.Key]; ok {
122122
return &preferences.GetKeyResponse{
123123
Status: status.NewOK(ctx),
124124
Val: value,

internal/http/services/owncloud/ocs/conversions/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ type ShareData struct {
142142
URL string `json:"url,omitempty" xml:"url,omitempty"`
143143
// Attributes associated
144144
Attributes string `json:"attributes,omitempty" xml:"attributes,omitempty"`
145+
// Quicklink indicates if the link is the quicklink
146+
Quicklink bool `json:"quicklink,omitempty" xml:"quicklink,omitempty"`
145147
// PasswordProtected represents a public share is password protected
146148
// PasswordProtected bool `json:"password_protected,omitempty" xml:"password_protected,omitempty"`
147149
}
@@ -233,6 +235,7 @@ func PublicShare2ShareData(share *link.PublicShare, r *http.Request, publicURL s
233235
URL: publicURL + path.Join("/", "s/"+share.Token),
234236
UIDOwner: LocalUserIDToString(share.Creator),
235237
UIDFileOwner: LocalUserIDToString(share.Owner),
238+
Quicklink: share.Quicklink,
236239
}
237240
if share.Id != nil {
238241
sd.ID = share.Id.OpaqueId

internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go

+5-28
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ import (
3838
"github.com/pkg/errors"
3939
)
4040

41-
// QuicklinkName is the reserved name for a quicklink.
42-
// Creating (or updating) a link with (to) the same name will be blocked by the server
43-
const QuicklinkName = "Quicklink"
44-
4541
func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request, statInfo *provider.ResourceInfo) (*link.PublicShare, *ocsError) {
4642
ctx := r.Context()
4743
log := appctx.GetLogger(ctx)
@@ -64,18 +60,8 @@ func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request,
6460
}
6561
}
6662

67-
// check reserved names
68-
linkname := r.FormValue("name")
69-
quick, _ := strconv.ParseBool(r.FormValue("quicklink")) // no need to check the error - defaults to zero value!
70-
if !quick && linkname == QuicklinkName {
71-
return nil, &ocsError{
72-
Code: response.MetaBadRequest.StatusCode,
73-
Message: fmt.Sprintf("not allowed to use `%s` as name", linkname),
74-
}
75-
76-
}
77-
7863
// check if a quicklink should be created
64+
quick, _ := strconv.ParseBool(r.FormValue("quicklink")) // no need to check the error - defaults to zero value!
7965
if quick {
8066
f := []*link.ListPublicSharesRequest_Filter{publicshare.ResourceIDFilter(statInfo.Id)}
8167
req := link.ListPublicSharesRequest{Filters: f}
@@ -95,12 +81,10 @@ func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request,
9581
}
9682

9783
for _, l := range res.GetShare() {
98-
if l.DisplayName == QuicklinkName {
84+
if l.Quicklink {
9985
return l, nil
10086
}
10187
}
102-
103-
linkname = QuicklinkName
10488
}
10589

10690
newPermissions, err := permissionFromRequest(r, h)
@@ -164,7 +148,8 @@ func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request,
164148
// set displayname and password protected as arbitrary metadata
165149
req.ResourceInfo.ArbitraryMetadata = &provider.ArbitraryMetadata{
166150
Metadata: map[string]string{
167-
"name": linkname,
151+
"name": r.FormValue("name"),
152+
"quicklink": r.FormValue("quicklink"),
168153
// "password": r.FormValue("password"),
169154
},
170155
}
@@ -306,15 +291,7 @@ func (h *Handler) updatePublicShare(w http.ResponseWriter, r *http.Request, shar
306291
newName, ok := r.Form["name"]
307292
if ok {
308293
updatesFound = true
309-
if n := newName[0]; n != before.Share.DisplayName {
310-
if n == QuicklinkName {
311-
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, fmt.Sprintf("not allowed to rename a link to '%s'", n), nil)
312-
return
313-
}
314-
if before.Share.DisplayName == QuicklinkName {
315-
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, "not allowed to rename a quicklink", nil)
316-
return
317-
}
294+
if newName[0] != before.Share.DisplayName {
318295
updates = append(updates, &link.UpdatePublicShareRequest_Update{
319296
Type: link.UpdatePublicShareRequest_Update_TYPE_DISPLAYNAME,
320297
DisplayName: newName[0],

pkg/publicshare/manager/cs3/cs3.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"net/url"
2626
"path"
27+
"strconv"
2728
"strings"
2829
"sync"
2930
"time"
@@ -173,12 +174,14 @@ func (m *Manager) CreatePublicShare(ctx context.Context, u *user.User, ri *provi
173174
tkn := utils.RandString(15)
174175
now := time.Now().UnixNano()
175176

176-
displayName := tkn
177+
displayName, quicklink := tkn, false
177178
if ri.ArbitraryMetadata != nil {
178179
metadataName, ok := ri.ArbitraryMetadata.Metadata["name"]
179180
if ok {
180181
displayName = metadataName
181182
}
183+
184+
quicklink, _ = strconv.ParseBool(ri.ArbitraryMetadata.Metadata["quicklink"])
182185
}
183186

184187
var passwordProtected bool
@@ -210,6 +213,7 @@ func (m *Manager) CreatePublicShare(ctx context.Context, u *user.User, ri *provi
210213
PasswordProtected: passwordProtected,
211214
Expiration: g.Expiration,
212215
DisplayName: displayName,
216+
Quicklink: quicklink,
213217
},
214218
HashedPassword: password,
215219
}

pkg/publicshare/manager/json/json.go

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"os"
2727
"os/signal"
2828
"path/filepath"
29+
"strconv"
2930
"strings"
3031
"sync"
3132
"syscall"
@@ -159,6 +160,8 @@ func (m *manager) CreatePublicShare(ctx context.Context, u *user.User, rInfo *pr
159160
displayName = tkn
160161
}
161162

163+
quicklink, _ := strconv.ParseBool(rInfo.ArbitraryMetadata.Metadata["quicklink"])
164+
162165
var passwordProtected bool
163166
password := g.Password
164167
if len(password) > 0 {
@@ -187,6 +190,7 @@ func (m *manager) CreatePublicShare(ctx context.Context, u *user.User, rInfo *pr
187190
PasswordProtected: passwordProtected,
188191
Expiration: g.Expiration,
189192
DisplayName: displayName,
193+
Quicklink: quicklink,
190194
}
191195

192196
ps := &publicShare{

0 commit comments

Comments
 (0)