Skip to content

Commit

Permalink
add changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Dec 5, 2023
1 parent 7f85627 commit de1c439
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add validation to the public share provider

We added validation to the public share provider. The idea behind it is that the cs3 clients will become much simpler. The provider can do the validation and return different status codes. The API clients then just need to convert CS3 status codes to http status codes.

https://github.com/cs3org/reva/pull/4372/
https://github.com/owncloud/ocis/issues/6993
55 changes: 36 additions & 19 deletions internal/grpc/services/publicshareprovider/publicshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ package publicshareprovider

import (
"context"
"fmt"
"regexp"
"strconv"
"time"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/v2/pkg/password"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/v2/pkg/sharedconf"
Expand Down Expand Up @@ -260,8 +263,18 @@ func (s *service) CreatePublicShare(ctx context.Context, req *link.CreatePublicS
}

grant := req.GetGrant()
setPassword := grant.GetPassword()

if grant.GetExpiration() != nil {
expirationDateTime := cs3TimestampToTime(grant.GetExpiration()).UTC()
if expirationDateTime.Before(time.Now().UTC()) {
msg := fmt.Sprintf("expiration date is in the past: %s", expirationDateTime.Format(time.RFC3339))
return &link.CreatePublicShareResponse{
Status: status.NewFailedPrecondition(ctx, nil, msg),
}, nil
}
}

setPassword := grant.GetPassword()
if enforcePassword(grant, s.conf) && len(setPassword) == 0 {
return &link.CreatePublicShareResponse{
Status: status.NewFailedPrecondition(ctx, nil, "password protection is enforced"),
Expand Down Expand Up @@ -295,24 +308,6 @@ func (s *service) CreatePublicShare(ctx context.Context, req *link.CreatePublicS
return res, nil
}

func checkQuicklink(info *provider.ResourceInfo) (bool, error) {
if info == nil {
return false, nil
}
if m := info.GetArbitraryMetadata().GetMetadata(); m != nil {
q, ok := m["quicklink"]
if !ok || q == "" {
return false, nil
}
quickLink, err := strconv.ParseBool(q)
if err != nil {
return false, err
}
return quickLink, nil
}
return false, nil
}

func (s *service) RemovePublicShare(ctx context.Context, req *link.RemovePublicShareRequest) (*link.RemovePublicShareResponse, error) {
gatewayClient, err := s.gatewaySelector.Next()
if err != nil {
Expand Down Expand Up @@ -469,3 +464,25 @@ func enforcePassword(grant *link.Grant, conf *config) bool {
}
return false
}

func checkQuicklink(info *provider.ResourceInfo) (bool, error) {
if info == nil {
return false, nil
}
if m := info.GetArbitraryMetadata().GetMetadata(); m != nil {
q, ok := m["quicklink"]
if !ok || q == "" {
return false, nil
}
quickLink, err := strconv.ParseBool(q)
if err != nil {
return false, err
}
return quickLink, nil
}
return false, nil
}

func cs3TimestampToTime(t *typesv1beta1.Timestamp) time.Time {
return time.Unix(int64(t.Seconds), int64(t.Nanos))
}

0 comments on commit de1c439

Please sign in to comment.