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

Quicklinks #2715

Merged
merged 4 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions changelog/unreleased/quicklinks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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.

Downside: since we can't update cs3api at the moment, we reserve the name `Quicklink` for the quicklink. Trying to create
a link named `Quicklink` without the "quicklink=true" flag will result in a `Bad Request`

https://github.com/cs3org/reva/pull/2715
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import (
"github.com/pkg/errors"
)

// QuicklinkName is the reserved name for a quicklink.
// Creating (or updating) a link with (to) the same name will be blocked by the server
var QuicklinkName = "Quicklink"
kobergj marked this conversation as resolved.
Show resolved Hide resolved

func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request, statInfo *provider.ResourceInfo) (*link.PublicShare, *ocsError) {
ctx := r.Context()
log := appctx.GetLogger(ctx)
Expand All @@ -59,6 +63,54 @@ func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request,
}
}

// check reserved names
linkname := r.FormValue("name")
quick, _ := strconv.ParseBool(r.FormValue("quicklink")) // no need to check the error - defaults to zero value!
if !quick && linkname == QuicklinkName {
return nil, &ocsError{
Code: response.MetaBadRequest.StatusCode,
Message: fmt.Sprintf("not allowed to use `%s` as name", linkname),
}

}

// check if a quicklink should be created
if quick {
_, f, err := h.addFilters(w, r, &provider.Reference{ResourceId: statInfo.Id})
micbar marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Error().Err(err).Msg("could not add filters")
return nil, &ocsError{
Code: response.MetaServerError.StatusCode,
Message: "could not add filters",
Error: err,
}
}

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.DisplayName == QuicklinkName {
return l, nil
}
}

linkname = QuicklinkName
}

newPermissions, err := permissionFromRequest(r, h)
if err != nil {
return nil, &ocsError{
Expand Down Expand Up @@ -120,7 +172,7 @@ 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": linkname,
// "password": r.FormValue("password"),
},
}
Expand Down Expand Up @@ -262,7 +314,15 @@ func (h *Handler) updatePublicShare(w http.ResponseWriter, r *http.Request, shar
newName, ok := r.Form["name"]
if ok {
updatesFound = true
if newName[0] != before.Share.DisplayName {
if n := newName[0]; n != before.Share.DisplayName {
if n == QuicklinkName {
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, fmt.Sprintf("not allowed to rename a link to '%s'", n), nil)
return
}
if before.Share.DisplayName == QuicklinkName {
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, "not allowed to rename a quicklink", nil)
return
}
updates = append(updates, &link.UpdatePublicShareRequest_Update{
Type: link.UpdatePublicShareRequest_Update_TYPE_DISPLAYNAME,
DisplayName: newName[0],
Expand Down