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

Added the watermark text for the Secure View mode #9144

Merged
merged 1 commit into from
May 15, 2024
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/enhancement-add-watermark-text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add watermark text

We've added the watermark text for the Secure View mode.

https://github.com/owncloud/ocis/pull/9144
49 changes: 29 additions & 20 deletions services/collaboration/pkg/connector/fileconnector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"path"
"strconv"
"strings"
"time"

appproviderv1beta1 "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
Expand All @@ -13,6 +14,7 @@ import (
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/google/uuid"
"github.com/owncloud/ocis/v2/services/collaboration/pkg/config"
"github.com/owncloud/ocis/v2/services/collaboration/pkg/middleware"
Expand Down Expand Up @@ -521,20 +523,6 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (FileInfo, error) {
SupportsLocks: true,
}

switch wopiContext.ViewMode {
case appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE:
fileInfo.SupportsUpdate = true
fileInfo.UserCanWrite = true

case appproviderv1beta1.ViewMode_VIEW_MODE_READ_ONLY:
// nothing special to do here for now

case appproviderv1beta1.ViewMode_VIEW_MODE_VIEW_ONLY:
fileInfo.DisableExport = true
fileInfo.DisableCopy = true
fileInfo.DisablePrint = true
}

// user logic from reva wopi driver #TODO: refactor
var isPublicShare bool = false
if wopiContext.User != nil {
Expand All @@ -545,13 +533,9 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (FileInfo, error) {
fileInfo.UserId = hex.EncodeToString([]byte(wopiContext.User.GetId().GetOpaqueId() + "@" + wopiContext.User.GetId().GetIdp()))
}

if wopiContext.User.GetOpaque() != nil {
if _, ok := wopiContext.User.GetOpaque().GetMap()["public-share-role"]; ok {
isPublicShare = true
}
}
isPublicShare = utils.ExistsInOpaque(wopiContext.User.GetOpaque(), "public-share-role")
if !isPublicShare {
fileInfo.UserFriendlyName = wopiContext.User.GetUsername()
fileInfo.UserFriendlyName = wopiContext.User.GetDisplayName()
fileInfo.UserId = hex.EncodeToString([]byte(wopiContext.User.GetId().GetOpaqueId() + "@" + wopiContext.User.GetId().GetIdp()))
}
}
Expand All @@ -562,6 +546,31 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (FileInfo, error) {
fileInfo.IsAnonymousUser = true
}

switch wopiContext.ViewMode {
case appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE:
fileInfo.SupportsUpdate = true
fileInfo.UserCanWrite = true

case appproviderv1beta1.ViewMode_VIEW_MODE_READ_ONLY:
// nothing special to do here for now

case appproviderv1beta1.ViewMode_VIEW_MODE_VIEW_ONLY:
fileInfo.DisableExport = true
fileInfo.DisableCopy = true
fileInfo.DisablePrint = true
if !isPublicShare {
// the fileInfo.WatermarkText supported by Collabora only
fileInfo.WatermarkText = f.watermarkText(wopiContext.User)
}
}

logger.Debug().Msg("CheckFileInfo: success")
return fileInfo, nil
}

func (f *FileConnector) watermarkText(user *userv1beta1.User) string {
if user != nil {
return strings.TrimSpace(user.GetDisplayName() + " " + user.GetMail())
}
return "Watermark"
}
55 changes: 54 additions & 1 deletion services/collaboration/pkg/connector/fileconnector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ var _ = Describe("FileConnector", func() {
OpaqueId: "opaqueId",
Type: userv1beta1.UserType_USER_TYPE_PRIMARY,
},
Username: "Pet Shaft",
Username: "Shaft",
DisplayName: "Pet Shaft",
Mail: "[email protected]",
// Opaque is here for reference, not used by default but might be needed for some tests
//Opaque: &typesv1beta1.Opaque{
// Map: map[string]*typesv1beta1.OpaqueEntry{
Expand Down Expand Up @@ -871,5 +873,56 @@ var _ = Describe("FileConnector", func() {
Expect(err).To(Succeed())
Expect(newFileInfo).To(Equal(expectedFileInfo))
})

It("Stat success authenticated user", func() {
// change view mode to view only
wopiCtx.ViewMode = appproviderv1beta1.ViewMode_VIEW_MODE_VIEW_ONLY

ctx := middleware.WopiContextToCtx(context.Background(), wopiCtx)

gatewayClient.On("Stat", mock.Anything, mock.Anything).Times(1).Return(&providerv1beta1.StatResponse{
Status: status.NewOK(ctx),
Info: &providerv1beta1.ResourceInfo{
Owner: &userv1beta1.UserId{
Idp: "customIdp",
OpaqueId: "aabbcc",
Type: userv1beta1.UserType_USER_TYPE_PRIMARY,
},
Size: uint64(998877),
Mtime: &typesv1beta1.Timestamp{
Seconds: uint64(16273849),
},
Path: "/path/to/test.txt",
// Other properties aren't used for now.
},
}, nil)

expectedFileInfo := connector.FileInfo{
OwnerId: "61616262636340637573746f6d496470", // hex of aabbcc@customIdp
Size: int64(998877),
Version: "16273849.0",
BaseFileName: "test.txt",
BreadcrumbDocName: "test.txt",
UserCanNotWriteRelative: true,
HostViewUrl: "http://test.ex.prv/view",
HostEditUrl: "http://test.ex.prv/edit",
EnableOwnerTermination: false,
SupportsExtendedLockLength: true,
SupportsGetLock: true,
SupportsLocks: true,
DisableExport: true,
DisableCopy: true,
DisablePrint: true,
IsAnonymousUser: false,
UserId: hex.EncodeToString([]byte("opaqueId@inmemory")),
UserFriendlyName: "Pet Shaft",
WatermarkText: "Pet Shaft [email protected]",
}

newFileInfo, err := fc.CheckFileInfo(ctx)

Expect(err).To(Succeed())
Expect(newFileInfo).To(Equal(expectedFileInfo))
})
})
})