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

handle expiration for space memberships #3628

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions changelog/unreleased/space-member-expiration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add expiration date to space memberships

Added an optional expiration date to space memberships to restrict the access in time.

https://github.com/cs3org/reva/pull/3628
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