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

Add description to public links + internal public links #3305

Merged
merged 16 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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
3 changes: 3 additions & 0 deletions changelog/unreleased/publiclink-description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Add description to public link

https://github.com/cs3org/reva/pull/3305
8 changes: 5 additions & 3 deletions cmd/reva/public-share-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ func publicShareCreateCommand() *command {
cmd.Description = func() string { return "create a public share" }
cmd.Usage = func() string { return "Usage: public-share-create [-flags] <path>" }
rol := cmd.String("rol", "viewer", "the permission for the share (viewer or editor)")
description := cmd.String("description", "", "the description for the share")

cmd.ResetFlags = func() {
*rol = "viewer"
*rol, *description = "viewer", ""
}

cmd.Action = func(w ...io.Writer) error {
Expand Down Expand Up @@ -78,6 +79,7 @@ func publicShareCreateCommand() *command {
shareRequest := &link.CreatePublicShareRequest{
ResourceInfo: res.Info,
Grant: grant,
Description: *description,
}

shareRes, err := client.CreatePublicShare(ctx, shareRequest)
Expand All @@ -91,11 +93,11 @@ func publicShareCreateCommand() *command {

t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Token", "Expiration", "Created", "Updated"})
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Token", "Expiration", "Created", "Updated", "Description"})

s := shareRes.Share
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), s.Token, s.Expiration.String(), time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), s.Token, s.Expiration.String(), time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0), s.Description},
})
t.Render()

Expand Down
4 changes: 2 additions & 2 deletions cmd/reva/public-share-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func publicShareListCommand() *command {
if len(w) == 0 {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Token", "Expiration", "Created", "Updated"})
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Token", "Expiration", "Created", "Updated", "Description"})

for _, s := range shareRes.Share {
t.AppendRows([]table.Row{
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), s.Token, s.Expiration.String(), time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0)},
{s.Id.OpaqueId, s.Owner.Idp, s.Owner.OpaqueId, s.ResourceId.String(), s.Permissions.String(), s.Token, s.Expiration.String(), time.Unix(int64(s.Ctime.Seconds), 0), time.Unix(int64(s.Mtime.Seconds), 0), s.Description},
})
}
t.Render()
Expand Down
37 changes: 29 additions & 8 deletions cmd/reva/public-share-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ func publicShareUpdateCommand() *command {
cmd.Description = func() string { return "update a public share" }
cmd.Usage = func() string { return "Usage: public-share-update [-flags] <share_id>" }
rol := cmd.String("rol", "viewer", "the permission for the share (viewer or editor)")
description := cmd.String("description", "", "the description for the share")

cmd.ResetFlags = func() {
*rol = "viewer"
*rol, *description = "viewer", ""
}
cmd.Action = func(w ...io.Writer) error {
if cmd.NArg() < 1 {
Expand All @@ -59,7 +60,9 @@ func publicShareUpdateCommand() *command {
return err
}

shareRequest := &link.UpdatePublicShareRequest{
var updates []*link.UpdatePublicShareRequest

updates = append(updates, &link.UpdatePublicShareRequest{
Ref: &link.PublicShareReference{
Spec: &link.PublicShareReference_Id{
Id: &link.PublicShareId{
Expand All @@ -75,15 +78,33 @@ func publicShareUpdateCommand() *command {
},
},
},
}
})

shareRes, err := shareClient.UpdatePublicShare(ctx, shareRequest)
if err != nil {
return err
if *description != "" {
updates = append(updates, &link.UpdatePublicShareRequest{
Ref: &link.PublicShareReference{
Spec: &link.PublicShareReference_Id{
Id: &link.PublicShareId{
OpaqueId: id,
},
},
},
Update: &link.UpdatePublicShareRequest_Update{
Type: link.UpdatePublicShareRequest_Update_TYPE_DESCRIPTION,
Description: *description,
},
})
}

if shareRes.Status.Code != rpc.Code_CODE_OK {
return formatError(shareRes.Status)
for _, u := range updates {
shareRes, err := shareClient.UpdatePublicShare(ctx, u)
if err != nil {
return err
}

if shareRes.Status.Code != rpc.Code_CODE_OK {
return formatError(shareRes.Status)
}
}

fmt.Println("OK")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/cheggaaa/pb v1.0.29
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
github.com/cs3org/go-cs3apis v0.0.0-20220929083235-bb0b1a236d6c
github.com/cs3org/go-cs3apis v0.0.0-20220930140901-5777bc1ccfaa
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8
github.com/dgraph-io/ristretto v0.1.0
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20220330081745-2ad58f5932b9 h1:SuPu5Mc2mpz+J059XML+cMd0i5FZR4t/kROS3SaIsnU=
github.com/cs3org/go-cs3apis v0.0.0-20220330081745-2ad58f5932b9/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20220719130120-361e9f987d64 h1:cFnankJOCWndnOns4sKRG7yzH61ammK2Am6rEGWCK40=
github.com/cs3org/go-cs3apis v0.0.0-20220719130120-361e9f987d64/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20220929083235-bb0b1a236d6c h1:b+YTmOGlf43mnF8MzO0fsy8/Ho8JLu44Iq5Y0fKLJMM=
github.com/cs3org/go-cs3apis v0.0.0-20220929083235-bb0b1a236d6c/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20220930140901-5777bc1ccfaa h1:MDbQLEHxlgEB9Xca1NKMqKR4c1r5S94SoP5hEkWLPC8=
github.com/cs3org/go-cs3apis v0.0.0-20220930140901-5777bc1ccfaa/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (s *service) CreatePublicShare(ctx context.Context, req *link.CreatePublicS
log.Error().Msg("error getting user from context")
}

share, err := s.sm.CreatePublicShare(ctx, u, req.ResourceInfo, req.Grant)
share, err := s.sm.CreatePublicShare(ctx, u, req.ResourceInfo, req.Grant, req.Description)
if err != nil {
log.Debug().Err(err).Str("createShare", "shares").Msg("error connecting to storage provider")
}
Expand Down
3 changes: 3 additions & 0 deletions internal/http/services/owncloud/ocs/conversions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ type ShareData struct {
// PasswordProtected represents a public share is password protected
// PasswordProtected bool `json:"password_protected,omitempty" xml:"password_protected,omitempty"`
Quicklink bool `json:"quicklink,omitempty" xml:"quicklink,omitempty"`
// Description of the public share
Description string `json:"description" xml:"description"`
}

// ShareeData holds share recipient search results
Expand Down Expand Up @@ -217,6 +219,7 @@ func PublicShare2ShareData(share *link.PublicShare, r *http.Request, publicURL s
UIDOwner: LocalUserIDToString(share.Creator),
UIDFileOwner: LocalUserIDToString(share.Owner),
Quicklink: share.Quicklink,
Description: share.Description,
}
if share.Id != nil {
sd.ID = share.Id.OpaqueId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request,
},
Password: r.FormValue("password"),
},
Description: r.FormValue("description"),
}

expireTimeString, ok := r.Form["expireDate"]
Expand Down Expand Up @@ -359,6 +360,17 @@ func (h *Handler) updatePublicShare(w http.ResponseWriter, r *http.Request, shar
})
}

// Description
description, ok := r.Form["description"]
if ok {
updatesFound = true
logger.Info().Str("shares", "update").Msg("description updated")
updates = append(updates, &link.UpdatePublicShareRequest_Update{
Type: link.UpdatePublicShareRequest_Update_TYPE_DESCRIPTION,
Description: description[0],
})
}

publicShare := before.Share

// Updates are atomical. See: https://github.com/cs3org/cs3apis/pull/67#issuecomment-617651428 so in order to get the latest updated version
Expand Down
Loading