Skip to content

Fix the expiration date response for links #11239

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-public-link-expiration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix the expiration date response for links

We fixed the inconsistency in the expiration date response for links

https://github.com/owncloud/ocis/pull/11239
https://github.com/owncloud/ocis/issues/11232
23 changes: 2 additions & 21 deletions services/graph/pkg/service/v0/api_driveitem_permissions_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import (
"net/http"
"net/url"
"strconv"
"time"

rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
libregraph "github.com/owncloud/libre-graph-api-go"
Expand Down Expand Up @@ -62,7 +60,7 @@ func (s DriveItemPermissionsService) CreateLink(ctx context.Context, driveItemID
}
expirationDate, isSet := createLink.GetExpirationDateTimeOk()
if isSet {
expireTime := parseAndFillUpTime(expirationDate)
expireTime := utils.TimeToTS(*expirationDate)
if expireTime == nil {
s.logger.Debug().Interface("createLink", createLink).Send()
return libregraph.Permission{}, errorcode.New(errorcode.InvalidRequest, "invalid expiration date")
Expand Down Expand Up @@ -298,7 +296,7 @@ func (s DriveItemPermissionsService) updatePublicLinkPermission(ctx context.Cont
expirationDate := newPermission.GetExpirationDateTime()
update := &link.UpdatePublicShareRequest_Update{
Type: link.UpdatePublicShareRequest_Update_TYPE_EXPIRATION,
Grant: &link.Grant{Expiration: parseAndFillUpTime(&expirationDate)},
Grant: &link.Grant{Expiration: utils.TimeToTS(expirationDate)},
}
perm, err = s.updatePublicLink(ctx, permissionID, update)
if err != nil {
Expand Down Expand Up @@ -409,20 +407,3 @@ func (s DriveItemPermissionsService) updatePublicLink(ctx context.Context, permi
}
return permission, nil
}

func parseAndFillUpTime(t *time.Time) *types.Timestamp {
if t == nil || t.IsZero() {
return nil
}

// the link needs to be valid for the whole day
tLink := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
tLink = tLink.Add(23*time.Hour + 59*time.Minute + 59*time.Second)

final := tLink.UnixNano()

return &types.Timestamp{
Seconds: uint64(final / 1000000000),
Nanos: uint32(final % 1000000000),
}
}
4 changes: 2 additions & 2 deletions services/graph/pkg/service/v0/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ func (g BaseGraphService) libreGraphPermissionFromCS3PublicShare(createdLink *li

// set expiration date
if createdLink.GetExpiration() != nil {
perm.SetExpirationDateTime(cs3TimestampToTime(createdLink.GetExpiration()).UTC())
perm.SetExpirationDateTime(cs3TimestampToTime(createdLink.GetExpiration()))
}

// set cTime
if createdLink.GetCtime() != nil {
perm.SetCreatedDateTime(cs3TimestampToTime(createdLink.GetCtime()).UTC())
perm.SetCreatedDateTime(cs3TimestampToTime(createdLink.GetCtime()))
}

perm.SetHasPassword(createdLink.GetPasswordProtected())
Expand Down