mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-30 08:50:49 -06:00
Merge pull request #9144 from 2403905/issue-9067
Added the watermark text for the Secure View mode
This commit is contained in:
5
changelog/unreleased/enhancement-add-watermark-text.md
Normal file
5
changelog/unreleased/enhancement-add-watermark-text.md
Normal file
@@ -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
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/hex"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
appproviderv1beta1 "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
|
||||
@@ -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"
|
||||
@@ -521,6 +523,29 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (FileInfo, error) {
|
||||
SupportsLocks: true,
|
||||
}
|
||||
|
||||
// user logic from reva wopi driver #TODO: refactor
|
||||
var isPublicShare bool = false
|
||||
if wopiContext.User != nil {
|
||||
// UserId must use only alphanumeric chars (https://learn.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/rest/files/checkfileinfo/checkfileinfo-response#requirements-for-user-identity-properties)
|
||||
if wopiContext.User.GetId().GetType() == userv1beta1.UserType_USER_TYPE_LIGHTWEIGHT {
|
||||
fileInfo.UserId = hex.EncodeToString([]byte(statRes.GetInfo().GetOwner().GetOpaqueId() + "@" + statRes.GetInfo().GetOwner().GetIdp()))
|
||||
} else {
|
||||
fileInfo.UserId = hex.EncodeToString([]byte(wopiContext.User.GetId().GetOpaqueId() + "@" + wopiContext.User.GetId().GetIdp()))
|
||||
}
|
||||
|
||||
isPublicShare = utils.ExistsInOpaque(wopiContext.User.GetOpaque(), "public-share-role")
|
||||
if !isPublicShare {
|
||||
fileInfo.UserFriendlyName = wopiContext.User.GetDisplayName()
|
||||
fileInfo.UserId = hex.EncodeToString([]byte(wopiContext.User.GetId().GetOpaqueId() + "@" + wopiContext.User.GetId().GetIdp()))
|
||||
}
|
||||
}
|
||||
if wopiContext.User == nil || isPublicShare {
|
||||
randomID, _ := uuid.NewUUID()
|
||||
fileInfo.UserId = hex.EncodeToString([]byte("guest-" + randomID.String()))
|
||||
fileInfo.UserFriendlyName = "Guest " + randomID.String()
|
||||
fileInfo.IsAnonymousUser = true
|
||||
}
|
||||
|
||||
switch wopiContext.ViewMode {
|
||||
case appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE:
|
||||
fileInfo.SupportsUpdate = true
|
||||
@@ -533,35 +558,19 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (FileInfo, error) {
|
||||
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 {
|
||||
// UserId must use only alphanumeric chars (https://learn.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/rest/files/checkfileinfo/checkfileinfo-response#requirements-for-user-identity-properties)
|
||||
if wopiContext.User.GetId().GetType() == userv1beta1.UserType_USER_TYPE_LIGHTWEIGHT {
|
||||
fileInfo.UserId = hex.EncodeToString([]byte(statRes.GetInfo().GetOwner().GetOpaqueId() + "@" + statRes.GetInfo().GetOwner().GetIdp()))
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
if !isPublicShare {
|
||||
fileInfo.UserFriendlyName = wopiContext.User.GetUsername()
|
||||
fileInfo.UserId = hex.EncodeToString([]byte(wopiContext.User.GetId().GetOpaqueId() + "@" + wopiContext.User.GetId().GetIdp()))
|
||||
// the fileInfo.WatermarkText supported by Collabora only
|
||||
fileInfo.WatermarkText = f.watermarkText(wopiContext.User)
|
||||
}
|
||||
}
|
||||
if wopiContext.User == nil || isPublicShare {
|
||||
randomID, _ := uuid.NewUUID()
|
||||
fileInfo.UserId = hex.EncodeToString([]byte("guest-" + randomID.String()))
|
||||
fileInfo.UserFriendlyName = "Guest " + randomID.String()
|
||||
fileInfo.IsAnonymousUser = true
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
@@ -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: "shaft@example.com",
|
||||
// Opaque is here for reference, not used by default but might be needed for some tests
|
||||
//Opaque: &typesv1beta1.Opaque{
|
||||
// Map: map[string]*typesv1beta1.OpaqueEntry{
|
||||
@@ -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 shaft@example.com",
|
||||
}
|
||||
|
||||
newFileInfo, err := fc.CheckFileInfo(ctx)
|
||||
|
||||
Expect(err).To(Succeed())
|
||||
Expect(newFileInfo).To(Equal(expectedFileInfo))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user