Skip to content

Commit

Permalink
handle expiration for space memberships
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Jan 25, 2023
1 parent 2d125a5 commit 4fb71f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"fmt"
"net/http"
"time"

groupv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
Expand Down Expand Up @@ -100,13 +101,32 @@ func (h *Handler) addSpaceMember(w http.ResponseWriter, r *http.Request, info *p
// The viewer role doesn't have the ListGrants permission so we set it here.
permissions.ListGrants = true

expireDate := r.PostFormValue("expireDate")
var expirationTs *types.Timestamp
if expireDate != "" {
expiration, err := time.Parse(_iso8601, expireDate)
if err != nil {
// Web sends different formats when adding and when editing a space membership...
// We need to fix this in a separate PR.
expiration, err = time.Parse(time.RFC3339, expireDate)
if err != nil {
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, "could not parse expireDate", err)
return
}
}
expirationTs = &types.Timestamp{
Seconds: uint64(expiration.UnixNano() / int64(time.Second)),
Nanos: uint32(expiration.UnixNano() % int64(time.Second)),
}
}
createShareRes, err := client.CreateShare(ctx, &collaborationv1beta1.CreateShareRequest{
ResourceInfo: info,
Grant: &collaborationv1beta1.ShareGrant{
Permissions: &collaborationv1beta1.SharePermissions{
Permissions: permissions,
},
Grantee: &grantee,
Grantee: &grantee,
Expiration: expirationTs,
},
})
if err != nil || createShareRes.Status.Code != rpc.Code_CODE_OK {
Expand Down
13 changes: 13 additions & 0 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node,
}

grantMap := make(map[string]*provider.ResourcePermissions, len(grants))
grantExpiration := make(map[string]*types.Timestamp)
groupMap := make(map[string]struct{})
for _, g := range grants {
var id string
Expand All @@ -723,13 +724,21 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node,
}

grantMap[id] = g.Permissions
if g.Expiration != nil {
grantExpiration[id] = g.Expiration
}
}

grantMapJSON, err := json.Marshal(grantMap)
if err != nil {
return nil, err
}

grantExpirationMapJSON, err := json.Marshal(grantExpiration)
if err != nil {
return nil, err
}

groupMapJSON, err := json.Marshal(groupMap)
if err != nil {
return nil, err
Expand All @@ -752,6 +761,10 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node,
Decoder: "json",
Value: grantMapJSON,
},
"grants_expirations": {
Decoder: "json",
Value: grantExpirationMapJSON,
},
"groups": {
Decoder: "json",
Value: groupMapJSON,
Expand Down

0 comments on commit 4fb71f3

Please sign in to comment.