feat: explicit provider for WOPI apps to handle fileinfo

This commit is contained in:
Juan Pablo Villafáñez
2024-05-24 14:14:01 +02:00
parent 981d94295f
commit 116bd2c414
5 changed files with 551 additions and 227 deletions

View File

@@ -17,6 +17,7 @@ import (
"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/connector/fileinfo"
"github.com/owncloud/ocis/v2/services/collaboration/pkg/middleware"
"github.com/rs/zerolog"
)
@@ -50,7 +51,7 @@ type FileConnectorService interface {
// The current lockID will be returned if a conflict happens
UnLock(ctx context.Context, lockID string) (string, error)
// CheckFileInfo will return the file information of the target file
CheckFileInfo(ctx context.Context) (FileInfo, error)
CheckFileInfo(ctx context.Context) (fileinfo.FileInfo, error)
}
// FileConnector implements the "File" endpoint.
@@ -475,10 +476,10 @@ func (f *FileConnector) UnLock(ctx context.Context, lockID string) (string, erro
//
// If the operation is successful, a "FileInfo" instance will be returned,
// otherwise the "FileInfo" will be empty and an error will be returned.
func (f *FileConnector) CheckFileInfo(ctx context.Context) (FileInfo, error) {
func (f *FileConnector) CheckFileInfo(ctx context.Context) (fileinfo.FileInfo, error) {
wopiContext, err := middleware.WopiContextFromCtx(ctx)
if err != nil {
return FileInfo{}, err
return nil, err
}
logger := zerolog.Ctx(ctx)
@@ -488,7 +489,7 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (FileInfo, error) {
})
if err != nil {
logger.Error().Err(err).Msg("CheckFileInfo: stat failed")
return FileInfo{}, err
return nil, err
}
if statRes.GetStatus().GetCode() != rpcv1beta1.Code_CODE_OK {
@@ -496,76 +497,87 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (FileInfo, error) {
Str("StatusCode", statRes.GetStatus().GetCode().String()).
Str("StatusMsg", statRes.GetStatus().GetMessage()).
Msg("CheckFileInfo: stat failed with unexpected status")
return FileInfo{}, NewConnectorError(500, statRes.GetStatus().GetCode().String()+" "+statRes.GetStatus().GetMessage())
return nil, NewConnectorError(500, statRes.GetStatus().GetCode().String()+" "+statRes.GetStatus().GetMessage())
}
fileInfo := FileInfo{
// OwnerId 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)
OwnerId: hex.EncodeToString([]byte(statRes.GetInfo().GetOwner().GetOpaqueId() + "@" + statRes.GetInfo().GetOwner().GetIdp())),
Size: int64(statRes.GetInfo().GetSize()),
Version: strconv.FormatUint(statRes.GetInfo().GetMtime().GetSeconds(), 10) + "." + strconv.FormatUint(uint64(statRes.GetInfo().GetMtime().GetNanos()), 10),
BaseFileName: path.Base(statRes.GetInfo().GetPath()),
BreadcrumbDocName: path.Base(statRes.GetInfo().GetPath()),
var info fileinfo.FileInfo
switch strings.ToLower(f.cfg.WopiApp.Provider) {
case "collabora":
info = &fileinfo.Collabora{}
case "onlyoffice":
info = &fileinfo.OnlyOffice{}
default:
info = &fileinfo.Microsoft{}
}
hexEncodedOwnerId := hex.EncodeToString([]byte(statRes.GetInfo().GetOwner().GetOpaqueId() + "@" + statRes.GetInfo().GetOwner().GetIdp()))
version := strconv.FormatUint(statRes.GetInfo().GetMtime().GetSeconds(), 10) + "." + strconv.FormatUint(uint64(statRes.GetInfo().GetMtime().GetNanos()), 10)
// 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)
// assign userId, userFriendlyName and isAnonymousUser
// assume we don't have a wopiContext.User
randomID, _ := uuid.NewUUID()
userId := hex.EncodeToString([]byte("guest-" + randomID.String()))
userFriendlyName := "Guest " + randomID.String()
isAnonymousUser := true
isPublicShare := false
if wopiContext.User != nil {
// if we have a wopiContext.User
isPublicShare = utils.ExistsInOpaque(wopiContext.User.GetOpaque(), "public-share-role")
if !isPublicShare {
hexEncodedWopiUserId := hex.EncodeToString([]byte(wopiContext.User.GetId().GetOpaqueId() + "@" + wopiContext.User.GetId().GetIdp()))
isAnonymousUser = false
userFriendlyName = wopiContext.User.GetDisplayName()
userId = hexEncodedWopiUserId
}
}
// fileinfo map
infoMap := map[string]interface{}{
"OwnerId": hexEncodedOwnerId,
"Size": int64(statRes.GetInfo().GetSize()),
"Version": version,
"BaseFileName": path.Base(statRes.GetInfo().GetPath()),
"BreadcrumbDocName": path.Base(statRes.GetInfo().GetPath()),
// to get the folder we actually need to do a GetPath() request
//BreadcrumbFolderName: path.Dir(statRes.Info.Path),
UserCanNotWriteRelative: true,
"HostViewUrl": wopiContext.ViewAppUrl,
"HostEditUrl": wopiContext.EditAppUrl,
HostViewUrl: wopiContext.ViewAppUrl,
HostEditUrl: wopiContext.EditAppUrl,
"EnableOwnerTermination": true, // only for collabora
"SupportsExtendedLockLength": true,
"SupportsGetLock": true,
"SupportsLocks": true,
"SupportsUpdate": true,
//EnableOwnerTermination: true, // enable only for collabora? wopivalidator is complaining
EnableOwnerTermination: false,
SupportsExtendedLockLength: true,
SupportsGetLock: true,
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
"UserCanNotWriteRelative": true,
"IsAnonymousUser": isAnonymousUser,
"UserFriendlyName": userFriendlyName,
"UserId": userId,
}
switch wopiContext.ViewMode {
case appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE:
fileInfo.SupportsUpdate = true
fileInfo.UserCanWrite = true
infoMap["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
infoMap["DisableExport"] = true
infoMap["DisableCopy"] = true
infoMap["DisablePrint"] = true
if !isPublicShare {
// the fileInfo.WatermarkText supported by Collabora only
fileInfo.WatermarkText = f.watermarkText(wopiContext.User)
infoMap["WatermarkText"] = f.watermarkText(wopiContext.User) // only for collabora
}
}
info.SetProperties(infoMap)
logger.Debug().Msg("CheckFileInfo: success")
return fileInfo, nil
return info, nil
}
func (f *FileConnector) watermarkText(user *userv1beta1.User) string {

View File

@@ -0,0 +1,108 @@
package fileinfo
// Collabora fileInfo properties
//
// Collabora WOPI check file info specification:
// https://sdk.collaboraonline.com/docs/advanced_integration.html
type Collabora struct {
//
// Response properties
//
// Copied from MS WOPI
BaseFileName string `json:"BaseFileName,omitempty"`
// Copied from MS WOPI
DisablePrint bool `json:"DisablePrint"`
// Copied from MS WOPI
OwnerId string `json:"OwnerId,omitempty"`
// A string for the domain the host page sends/receives PostMessages from, we only listen to messages from this domain.
PostMessageOrigin string `json:"PostMessageOrigin,omitempty"`
// copied from MS WOPI
Size int64 `json:"Size"`
// The ID of file (like the wopi/files/ID) can be a non-existing file. In that case, the file will be created from a template when the template (eg. an OTT file) is specified as TemplateSource in the CheckFileInfo response. The TemplateSource is supposed to be an URL like https://somewhere/accessible/file.ott that is accessible by the Online. For the actual saving of the content, normal PutFile mechanism will be used.
TemplateSource string `json:"TemplateSource,omitempty"`
// copied from MS WOPI
UserCanWrite bool `json:"UserCanWrite"`
// copied from MS WOPI
UserCanNotWriteRelative bool `json:"UserCanNotWriteRelative"`
// copied from MS WOPI
UserId string `json:"UserId,omitempty"`
// copied from MS WOPI
UserFriendlyName string `json:"UserFriendlyName,omitempty"`
//
// Extended response properties
//
// If set to true, this will enable the insertion of images chosen from the WOPI storage. A UI_InsertGraphic postMessage will be send to the WOPI host to request the UI to select the file.
EnableInsertRemoteImage bool `json:"EnableInsertRemoteImage,omitempty"`
// If set to true, this will disable the insertion of image chosen from the local device. If EnableInsertRemoteImage is not set to true, then inserting images files is not possible.
DisableInsertLocalImage bool `json:"DisableInsertLocalImage,omitempty"`
// If set to true, hides the print option from the file menu bar in the UI.
HidePrintOption bool `json:"HidePrintOption,omitempty"`
// If set to true, hides the save button from the toolbar and file menubar in the UI.
HideSaveOption bool `json:"HideSaveOption,omitempty"`
// Hides Download as option in the file menubar.
HideExportOption bool `json:"HideExportOption,omitempty"`
// Disables export functionality in backend. If set to true, HideExportOption is assumed to be true
DisableExport bool `json:"DisableExport,omitempty"`
// Disables copying from the document in libreoffice online backend. Pasting into the document would still be possible. However, it is still possible to do an “internal” cut/copy/paste.
DisableCopy bool `json:"DisableCopy,omitempty"`
// Disables displaying of the explanation text on the overlay when the document becomes inactive or killed. With this, the JS integration must provide the user with appropriate message when it gets Session_Closed or User_Idle postMessages.
DisableInactiveMessages bool `json:"DisableInactiveMessages,omitempty"`
// Indicate that the integration wants to handle the downloading of pdf for printing or svg for slideshows or exported document, because it cannot rely on browsers support for downloading.
DownloadAsPostMessage bool `json:"DownloadAsPostMessage,omitempty"`
// Similar to download as, doctype extensions can be provided for save-as. In this case the new file is loaded in the integration instead of downloaded.
SaveAsPostmessage bool `json:"SaveAsPostmessage,omitempty"`
// If set to true, it allows the document owner (the one with OwnerId =UserId) to send a closedocument message (see protocol.txt)
EnableOwnerTermination bool `json:"EnableOwnerTermination,omitempty"`
// JSON object that contains additional info about the user, namely the avatar image.
//UserExtraInfo -> requires definition, currently not used
// JSON object that contains additional info about the user, but unlike the UserExtraInfo it is not shared among the views in collaborative editing sessions.
//UserPrivateInfo -> requires definition, currently not used
// If set to a non-empty string, is used for rendering a watermark-like text on each tile of the document.
WatermarkText string `json:"WatermarkText,omitempty"`
}
func (cinfo *Collabora) SetProperties(props map[string]interface{}) {
setters := map[string]func(value interface{}){
"BaseFileName": assignStringTo(&cinfo.BaseFileName),
"DisablePrint": assignBoolTo(&cinfo.DisablePrint),
"OwnerId": assignStringTo(&cinfo.OwnerId),
"PostMessageOrigin": assignStringTo(&cinfo.PostMessageOrigin),
"Size": assignInt64To(&cinfo.Size),
"TemplateSource": assignStringTo(&cinfo.TemplateSource),
"UserCanWrite": assignBoolTo(&cinfo.UserCanWrite),
"UserCanNotWriteRelative": assignBoolTo(&cinfo.UserCanNotWriteRelative),
"UserId": assignStringTo(&cinfo.UserId),
"UserFriendlyName": assignStringTo(&cinfo.UserFriendlyName),
"EnableInsertRemoteImage": assignBoolTo(&cinfo.EnableInsertRemoteImage),
"DisableInsertLocalImage": assignBoolTo(&cinfo.DisableInsertLocalImage),
"HidePrintOption": assignBoolTo(&cinfo.HidePrintOption),
"HideSaveOption": assignBoolTo(&cinfo.HideSaveOption),
"HideExportOption": assignBoolTo(&cinfo.HideExportOption),
"DisableExport": assignBoolTo(&cinfo.DisableExport),
"DisableCopy": assignBoolTo(&cinfo.DisableCopy),
"DisableInactiveMessages": assignBoolTo(&cinfo.DisableInactiveMessages),
"DownloadAsPostMessage": assignBoolTo(&cinfo.DownloadAsPostMessage),
"SaveAsPostmessage": assignBoolTo(&cinfo.SaveAsPostmessage),
"EnableOwnerTermination": assignBoolTo(&cinfo.EnableOwnerTermination),
//UserExtraInfo -> requires definition, currently not used
//UserPrivateInfo -> requires definition, currently not used
"WatermarkText": assignStringTo(&cinfo.WatermarkText),
}
for key, value := range props {
setterFn := setters[key]
if setterFn != nil {
setterFn(value)
}
}
}
func (cinfo *Collabora) GetTarget() string {
return "Collabora"
}

View File

@@ -0,0 +1,103 @@
package fileinfo
// FileInfo contains the properties of the file.
// Some properties refer to capabilities in the WOPI client, and capabilities
// that the WOPI server has.
//
// Specific implementations must allow json-encoding of their relevant
// properties because the object will be marshalled directly
type FileInfo interface {
// SetProperties will set the properties of this FileInfo.
// Keys should match any valid property that the FileInfo implementation
// has. If a key doesn't match any property, it must be ignored.
// The values must have its matching type for the target property,
// otherwise panics might happen.
//
// This method should help to reduce the friction of using different
// implementations with different properties. You can use the same map
// for all the implementations knowing that the relevant properties for
// each implementation will be set.
SetProperties(props map[string]interface{})
// GetTarget will return the target implementation (OnlyOffice, Collabora...).
// This will help to identify the implementation we're using in an easy way.
// Note that the returned value must be unique among all the implementations
GetTarget() string
}
// assignStringTo will return a function whose parameter will be assigned
// to the provided key. The function will panic if the assignment isn't
// possible.
//
// fn := AssignStringTo(&target)
// fn(value)
//
// Is roughly equivalent to
//
// target = value
//
// The reason for this method is to help the `SetProperties` method in order
// to provide a setter function for each property.
// Expected code for the `SetProperties` should be similar to
//
// setters := map[string]func(value interface{}) {
// "Owner": AssignStringTo(&info.Owner),
// "DisplayName": AssignStringTo(&info.DisplayName),
// .....
// }
// for key, value := range props {
// fn := setters[key]
// fn(value)
// }
//
// Further `assign*To` functions will be provided to be able to assign
// different data types
func assignStringTo(targetKey *string) func(value interface{}) {
return func(value interface{}) {
*targetKey = value.(string)
}
}
// assignStringListTo will return a function whose parameter will be assigned
// to the provided key. The function will panic if the assignment isn't
// possible.
//
// See assignStringTo for more information
func assignStringListTo(targetKey *[]string) func(value interface{}) {
return func(value interface{}) {
*targetKey = value.([]string)
}
}
// assignInt64To will return a function whose parameter will be assigned
// to the provided key. The function will panic if the assignment isn't
// possible.
//
// See assignStringTo for more information
func assignInt64To(targetKey *int64) func(value interface{}) {
return func(value interface{}) {
*targetKey = value.(int64)
}
}
// assignIntTo will return a function whose parameter will be assigned
// to the provided key. The function will panic if the assignment isn't
// possible.
//
// See assignStringTo for more information
func assignIntTo(targetKey *int) func(value interface{}) {
return func(value interface{}) {
*targetKey = value.(int)
}
}
// assignBoolTo will return a function whose parameter will be assigned
// to the provided key. The function will panic if the assignment isn't
// possible.
//
// See assignStringTo for more information
func assignBoolTo(targetKey *bool) func(value interface{}) {
return func(value interface{}) {
*targetKey = value.(bool)
}
}

View File

@@ -1,17 +1,10 @@
package connector
package fileinfo
// FileInfo contains the properties of the file.
// Some properties refer to capabilities in the WOPI client, and capabilities
// that the WOPI server has.
// Microsoft fileInfo properties
//
// For now, the FileInfo contains data for Microsoft, Collabora and OnlyOffice.
// Not all the properties are supported by every system.
type FileInfo struct {
// ------------
// Microsoft WOPI check file info specification:
// https://docs.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/rest/files/checkfileinfo
// ------------
// Microsoft WOPI check file info specification:
// https://docs.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/rest/files/checkfileinfo
type Microsoft struct {
//
// Required response properties
//
@@ -168,166 +161,86 @@ type FileInfo struct {
BreadcrumbFolderName string `json:"BreadcrumbFolderName,omitempty"`
// A URI to a web page that the WOPI client should navigate to when the user clicks on UI that displays BreadcrumbFolderName.
BreadcrumbFolderUrl string `json:"BreadcrumbFolderUrl,omitempty"`
// ------------
// Collabora WOPI check file info specification:
// https://sdk.collaboraonline.com/docs/advanced_integration.html
// ------------
//
// Response properties
//
//BaseFileName -> already in MS WOPI
//DisablePrint -> already in MS WOPI
//OwnerID -> already in MS WOPI
// A string for the domain the host page sends/receives PostMessages from, we only listen to messages from this domain.
PostMessageOrigin string `json:"PostMessageOrigin,omitempty"`
//Size -> already in MS WOPI
// The ID of file (like the wopi/files/ID) can be a non-existing file. In that case, the file will be created from a template when the template (eg. an OTT file) is specified as TemplateSource in the CheckFileInfo response. The TemplateSource is supposed to be an URL like https://somewhere/accessible/file.ott that is accessible by the Online. For the actual saving of the content, normal PutFile mechanism will be used.
TemplateSource string `json:"TemplateSource,omitempty"`
//UserCanWrite -> already in MS WOPI
//UserCanNotWriteRelative -> already in MS WOPI
//UserId -> already in MS WOPI
//UserFriendlyName -> already in MS WOPI
//
// Extended response properties
//
// If set to true, this will enable the insertion of images chosen from the WOPI storage. A UI_InsertGraphic postMessage will be send to the WOPI host to request the UI to select the file.
EnableInsertRemoteImage bool `json:"EnableInsertRemoteImage,omitempty"`
// If set to true, this will disable the insertion of image chosen from the local device. If EnableInsertRemoteImage is not set to true, then inserting images files is not possible.
DisableInsertLocalImage bool `json:"DisableInsertLocalImage,omitempty"`
// If set to true, hides the print option from the file menu bar in the UI.
HidePrintOption bool `json:"HidePrintOption,omitempty"`
// If set to true, hides the save button from the toolbar and file menubar in the UI.
HideSaveOption bool `json:"HideSaveOption,omitempty"`
// Hides Download as option in the file menubar.
HideExportOption bool `json:"HideExportOption,omitempty"`
// Disables export functionality in backend. If set to true, HideExportOption is assumed to be true
DisableExport bool `json:"DisableExport,omitempty"`
// Disables copying from the document in libreoffice online backend. Pasting into the document would still be possible. However, it is still possible to do an “internal” cut/copy/paste.
DisableCopy bool `json:"DisableCopy,omitempty"`
// Disables displaying of the explanation text on the overlay when the document becomes inactive or killed. With this, the JS integration must provide the user with appropriate message when it gets Session_Closed or User_Idle postMessages.
DisableInactiveMessages bool `json:"DisableInactiveMessages,omitempty"`
// Indicate that the integration wants to handle the downloading of pdf for printing or svg for slideshows or exported document, because it cannot rely on browsers support for downloading.
DownloadAsPostMessage bool `json:"DownloadAsPostMessage,omitempty"`
// Similar to download as, doctype extensions can be provided for save-as. In this case the new file is loaded in the integration instead of downloaded.
SaveAsPostmessage bool `json:"SaveAsPostmessage,omitempty"`
// If set to true, it allows the document owner (the one with OwnerId =UserId) to send a closedocument message (see protocol.txt)
EnableOwnerTermination bool `json:"EnableOwnerTermination,omitempty"`
// JSON object that contains additional info about the user, namely the avatar image.
//UserExtraInfo -> requires definition, currently not used
// JSON object that contains additional info about the user, but unlike the UserExtraInfo it is not shared among the views in collaborative editing sessions.
//UserPrivateInfo -> requires definition, currently not used
// If set to a non-empty string, is used for rendering a watermark-like text on each tile of the document.
WatermarkText string `json:"WatermarkText,omitempty"`
// ------------
// OnlyOffice WOPI check file info specification:
// https://api.onlyoffice.com/editors/wopi/restapi/checkfileinfo
// ------------
//
// Required response properties
//
//BaseFileName -> already in MS WOPI
//Version -> already in MS WOPI
//
// Breadcrumb properties
//
//BreadcrumbBrandName -> already in MS WOPI
//BreadcrumbBrandUrl -> already in MS WOPI
//BreadcrumbDocName -> already in MS WOPI
//BreadcrumbFolderName -> already in MS WOPI
//BreadcrumbFolderUrl -> already in MS WOPI
//
// PostMessage properties
//
// Specifies if the WOPI client should notify the WOPI server in case the user closes the rendering or editing client currently using this file. The host expects to receive the UI_Close PostMessage when the Close UI in the online office is activated.
ClosePostMessage bool `json:"ClosePostMessage,omitempty"`
// Specifies if the WOPI client should notify the WOPI server in case the user tries to edit a file. The host expects to receive the UI_Edit PostMessage when the Edit UI in the online office is activated.
EditModePostMessage bool `json:"EditModePostMessage,omitempty"`
// Specifies if the WOPI client should notify the WOPI server in case the user tries to edit a file. The host expects to receive the Edit_Notification PostMessage.
EditNotificationPostMessage bool `json:"EditNotificationPostMessage,omitempty"`
// Specifies if the WOPI client should notify the WOPI server in case the user tries to share a file. The host expects to receive the UI_Sharing PostMessage when the Share UI in the online office is activated.
FileSharingPostMessage bool `json:"FileSharingPostMessage,omitempty"`
// Specifies if the WOPI client will notify the WOPI server in case the user tries to navigate to the previous file version. The host expects to receive the UI_FileVersions PostMessage when the Previous Versions UI in the online office is activated.
FileVersionPostMessage bool `json:"FileVersionPostMessage,omitempty"`
// A domain that the WOPI client must use as the targetOrigin parameter when sending messages as described in [W3C-HTML5WEBMSG].
//PostMessageOrigin -> already in collabora WOPI
//
// File URL properties
//
//CloseUrl -> already in MS WOPI
//FileSharingUrl -> already in MS WOPI
//FileVersionUrl -> already in MS WOPI
//HostEditUrl -> already in MS WOPI
//
// Miscellaneous properties
//
// Specifies if the WOPI client must disable the Copy and Paste functionality within the application. By default, all Copy and Paste functionality is enabled, i.e. the setting has no effect. Possible property values:
// BlockAll - the Copy and Paste functionality is completely disabled within the application;
// CurrentDocumentOnly - the Copy and Paste functionality is enabled but content can only be copied and pasted within the file currently open in the application.
//CopyPasteRestrictions -> already in MS WOPI
//DisablePrint -> already in MS WOPI
//FileExtension -> already in MS WOPI
//FileNameMaxLength -> already in MS WOPI
//LastModifiedTime -> already in MS WOPI
//
// User metadata properties
//
//IsAnonymousUser -> already in MS WOPI
//UserFriendlyName -> already in MS WOPI
//UserId -> already in MS WOPI
//
// User permissions properties
//
//ReadOnly -> already in MS WOPI
//UserCanNotWriteRelative -> already in MS WOPI
//UserCanRename -> already in MS WOPI
// Specifies if the user has permissions to review a file.
UserCanReview bool `json:"UserCanReview,omitempty"`
//UserCanWrite -> already in MS WOPI
//
// Host capabilities properties
//
//SupportsLocks -> already in MS WOPI
//SupportsRename -> already in MS WOPI
// Specifies if the WOPI server supports the review permission.
SupportsReviewing bool `json:"SupportsReviewing,omitempty"`
//SupportsUpdate -> already in MS WOPI
//
// Other properties
//
//EnableInsertRemoteImage -> already in collabora WOPI
//HidePrintOption -> already in collabora WOPI
}
func (minfo *Microsoft) SetProperties(props map[string]interface{}) {
setters := map[string]func(value interface{}){
"BaseFileName": assignStringTo(&minfo.BaseFileName),
"OwnerId": assignStringTo(&minfo.OwnerId),
"Size": assignInt64To(&minfo.Size),
"UserId": assignStringTo(&minfo.UserId),
"Version": assignStringTo(&minfo.Version),
"SupportedShareUrlTypes": assignStringListTo(&minfo.SupportedShareUrlTypes),
"SupportsCobalt": assignBoolTo(&minfo.SupportsCobalt),
"SupportsContainers": assignBoolTo(&minfo.SupportsContainers),
"SupportsDeleteFile": assignBoolTo(&minfo.SupportsDeleteFile),
"SupportsEcosystem": assignBoolTo(&minfo.SupportsEcosystem),
"SupportsExtendedLockLength": assignBoolTo(&minfo.SupportsExtendedLockLength),
"SupportsFolders": assignBoolTo(&minfo.SupportsFolders),
//SupportsGetFileWopiSrc bool `json:"SupportsGetFileWopiSrc"` // wopivalidator is complaining and the property isn't used for now -> commented
"SupportsGetLock": assignBoolTo(&minfo.SupportsGetLock),
"SupportsLocks": assignBoolTo(&minfo.SupportsLocks),
"SupportsRename": assignBoolTo(&minfo.SupportsRename),
"SupportsUpdate": assignBoolTo(&minfo.SupportsUpdate),
"SupportsUserInfo": assignBoolTo(&minfo.SupportsUserInfo),
"IsAnonymousUser": assignBoolTo(&minfo.IsAnonymousUser),
"IsEduUser": assignBoolTo(&minfo.IsEduUser),
"LicenseCheckForEditIsEnabled": assignBoolTo(&minfo.LicenseCheckForEditIsEnabled),
"UserFriendlyName": assignStringTo(&minfo.UserFriendlyName),
"UserInfo": assignStringTo(&minfo.UserInfo),
"ReadOnly": assignBoolTo(&minfo.ReadOnly),
"RestrictedWebViewOnly": assignBoolTo(&minfo.RestrictedWebViewOnly),
"UserCanAttend": assignBoolTo(&minfo.UserCanAttend),
"UserCanNotWriteRelative": assignBoolTo(&minfo.UserCanNotWriteRelative),
"UserCanPresent": assignBoolTo(&minfo.UserCanPresent),
"UserCanRename": assignBoolTo(&minfo.UserCanRename),
"UserCanWrite": assignBoolTo(&minfo.UserCanWrite),
"CloseUrl": assignStringTo(&minfo.CloseUrl),
"DownloadUrl": assignStringTo(&minfo.DownloadUrl),
"FileEmbedCommandUrl": assignStringTo(&minfo.FileEmbedCommandUrl),
"FileSharingUrl": assignStringTo(&minfo.FileSharingUrl),
"FileUrl": assignStringTo(&minfo.FileUrl),
"FileVersionUrl": assignStringTo(&minfo.FileVersionUrl),
"HostEditUrl": assignStringTo(&minfo.HostEditUrl),
"HostEmbeddedViewUrl": assignStringTo(&minfo.HostEmbeddedViewUrl),
"HostViewUrl": assignStringTo(&minfo.HostViewUrl),
"SignoutUrl": assignStringTo(&minfo.SignoutUrl),
"AllowAdditionalMicrosoftServices": assignBoolTo(&minfo.AllowAdditionalMicrosoftServices),
"AllowErrorReportPrompt": assignBoolTo(&minfo.AllowErrorReportPrompt),
"AllowExternalMarketplace": assignBoolTo(&minfo.AllowExternalMarketplace),
"ClientThrottlingProtection": assignStringTo(&minfo.ClientThrottlingProtection),
"CloseButtonClosesWindow": assignBoolTo(&minfo.CloseButtonClosesWindow),
"CopyPasteRestrictions": assignStringTo(&minfo.CopyPasteRestrictions),
"DisablePrint": assignBoolTo(&minfo.DisablePrint),
"DisableTranslation": assignBoolTo(&minfo.DisableTranslation),
"FileExtension": assignStringTo(&minfo.FileExtension),
"FileNameMaxLength": assignIntTo(&minfo.FileNameMaxLength),
"LastModifiedTime": assignStringTo(&minfo.LastModifiedTime),
"RequestedCallThrottling": assignStringTo(&minfo.RequestedCallThrottling),
"SHA256": assignStringTo(&minfo.SHA256),
"SharingStatus": assignStringTo(&minfo.SharingStatus),
"TemporarilyNotWritable": assignBoolTo(&minfo.TemporarilyNotWritable),
"BreadcrumbBrandName": assignStringTo(&minfo.BreadcrumbBrandName),
"BreadcrumbBrandUrl": assignStringTo(&minfo.BreadcrumbBrandUrl),
"BreadcrumbDocName": assignStringTo(&minfo.BreadcrumbDocName),
"BreadcrumbFolderName": assignStringTo(&minfo.BreadcrumbFolderName),
"BreadcrumbFolderUrl": assignStringTo(&minfo.BreadcrumbFolderUrl),
}
for key, value := range props {
setterFn := setters[key]
if setterFn != nil {
setterFn(value)
}
}
}
func (minfo *Microsoft) GetTarget() string {
return "Microsoft"
}

View File

@@ -0,0 +1,188 @@
package fileinfo
// OnlyOffice fileInfo properties
//
// OnlyOffice WOPI check file info specification:
// https://api.onlyoffice.com/editors/wopi/restapi/checkfileinfo
type OnlyOffice struct {
//
// Required response properties
//
// copied from MS WOPI
BaseFileName string `json:"BaseFileName,omitempty"`
// copied from MS WOPI
Version string `json:"Version,omitempty"`
//
// Breadcrumb properties
//
// copied from MS WOPI
BreadcrumbBrandName string `json:"BreadcrumbBrandName,omitempty"`
// copied from MS WOPI
BreadcrumbBrandUrl string `json:"BreadcrumbBrandUrl,omitempty"`
// copied from MS WOPI
BreadcrumbDocName string `json:"BreadcrumbDocName,omitempty"`
// copied from MS WOPI
BreadcrumbFolderName string `json:"BreadcrumbFolderName,omitempty"`
// copied from MS WOPI
BreadcrumbFolderUrl string `json:"BreadcrumbFolderUrl,omitempty"`
//
// PostMessage properties
//
// Specifies if the WOPI client should notify the WOPI server in case the user closes the rendering or editing client currently using this file. The host expects to receive the UI_Close PostMessage when the Close UI in the online office is activated.
ClosePostMessage bool `json:"ClosePostMessage,omitempty"`
// Specifies if the WOPI client should notify the WOPI server in case the user tries to edit a file. The host expects to receive the UI_Edit PostMessage when the Edit UI in the online office is activated.
EditModePostMessage bool `json:"EditModePostMessage,omitempty"`
// Specifies if the WOPI client should notify the WOPI server in case the user tries to edit a file. The host expects to receive the Edit_Notification PostMessage.
EditNotificationPostMessage bool `json:"EditNotificationPostMessage,omitempty"`
// Specifies if the WOPI client should notify the WOPI server in case the user tries to share a file. The host expects to receive the UI_Sharing PostMessage when the Share UI in the online office is activated.
FileSharingPostMessage bool `json:"FileSharingPostMessage,omitempty"`
// Specifies if the WOPI client will notify the WOPI server in case the user tries to navigate to the previous file version. The host expects to receive the UI_FileVersions PostMessage when the Previous Versions UI in the online office is activated.
FileVersionPostMessage bool `json:"FileVersionPostMessage,omitempty"`
// A domain that the WOPI client must use as the targetOrigin parameter when sending messages as described in [W3C-HTML5WEBMSG].
// copied from collabora WOPI
PostMessageOrigin string `json:"PostMessageOrigin,omitempty"`
//
// File URL properties
//
// copied from MS WOPI
CloseUrl string `json:"CloseUrl,omitempty"`
// copied from MS WOPI
FileSharingUrl string `json:"FileSharingUrl,omitempty"`
// copied from MS WOPI
FileVersionUrl string `json:"FileVersionUrl,omitempty"`
// copied from MS WOPI
HostEditUrl string `json:"HostEditUrl,omitempty"`
//
// Miscellaneous properties
//
// Specifies if the WOPI client must disable the Copy and Paste functionality within the application. By default, all Copy and Paste functionality is enabled, i.e. the setting has no effect. Possible property values:
// BlockAll - the Copy and Paste functionality is completely disabled within the application;
// CurrentDocumentOnly - the Copy and Paste functionality is enabled but content can only be copied and pasted within the file currently open in the application.
// copied from MS WOPI
CopyPasteRestrictions string `json:"CopyPasteRestrictions,omitempty"`
// copied from MS WOPI
DisablePrint bool `json:"DisablePrint"`
// copied from MS WOPI
FileExtension string `json:"FileExtension,omitempty"`
// copied from MS WOPI
FileNameMaxLength int `json:"FileNameMaxLength,omitempty"`
// copied from MS WOPI
LastModifiedTime string `json:"LastModifiedTime,omitempty"`
//
// User metadata properties
//
// copied from MS WOPI
IsAnonymousUser bool `json:"IsAnonymousUser,omitempty"`
// copied from MS WOPI
UserFriendlyName string `json:"UserFriendlyName,omitempty"`
// copied from MS WOPI
UserId string `json:"UserId,omitempty"`
//
// User permissions properties
//
// copied from MS WOPI
ReadOnly bool `json:"ReadOnly"`
// copied from MS WOPI
UserCanNotWriteRelative bool `json:"UserCanNotWriteRelative"`
// copied from MS WOPI
UserCanRename bool `json:"UserCanRename"`
// Specifies if the user has permissions to review a file.
UserCanReview bool `json:"UserCanReview,omitempty"`
// copied from MS WOPI
UserCanWrite bool `json:"UserCanWrite"`
//
// Host capabilities properties
//
// copied from MS WOPI
SupportsLocks bool `json:"SupportsLocks"`
// copied from MS WOPI
SupportsRename bool `json:"SupportsRename"`
// Specifies if the WOPI server supports the review permission.
SupportsReviewing bool `json:"SupportsReviewing,omitempty"`
// copied from MS WOPI
SupportsUpdate bool `json:"SupportsUpdate"` // whether "Putfile" and "PutRelativeFile" work
//
// Other properties
//
// copied from collabora WOPI
EnableInsertRemoteImage bool `json:"EnableInsertRemoteImage,omitempty"`
// copied from collabora WOPI
HidePrintOption bool `json:"HidePrintOption,omitempty"`
}
func (oinfo *OnlyOffice) SetProperties(props map[string]interface{}) {
setters := map[string]func(value interface{}){
"BaseFileName": assignStringTo(&oinfo.BaseFileName),
"Version": assignStringTo(&oinfo.Version),
"BreadcrumbBrandName": assignStringTo(&oinfo.BreadcrumbBrandName),
"BreadcrumbBrandUrl": assignStringTo(&oinfo.BreadcrumbBrandUrl),
"BreadcrumbDocName": assignStringTo(&oinfo.BreadcrumbDocName),
"BreadcrumbFolderName": assignStringTo(&oinfo.BreadcrumbFolderName),
"BreadcrumbFolderUrl": assignStringTo(&oinfo.BreadcrumbFolderUrl),
"ClosePostMessage": assignBoolTo(&oinfo.ClosePostMessage),
"EditModePostMessage": assignBoolTo(&oinfo.EditModePostMessage),
"EditNotificationPostMessage": assignBoolTo(&oinfo.EditNotificationPostMessage),
"FileSharingPostMessage": assignBoolTo(&oinfo.FileSharingPostMessage),
"FileVersionPostMessage": assignBoolTo(&oinfo.FileVersionPostMessage),
"PostMessageOrigin": assignStringTo(&oinfo.PostMessageOrigin),
"CloseUrl": assignStringTo(&oinfo.CloseUrl),
"FileSharingUrl": assignStringTo(&oinfo.FileSharingUrl),
"FileVersionUrl": assignStringTo(&oinfo.FileVersionUrl),
"HostEditUrl": assignStringTo(&oinfo.HostEditUrl),
"CopyPasteRestrictions": assignStringTo(&oinfo.CopyPasteRestrictions),
"DisablePrint": assignBoolTo(&oinfo.DisablePrint),
"FileExtension": assignStringTo(&oinfo.FileExtension),
"FileNameMaxLength": assignIntTo(&oinfo.FileNameMaxLength),
"LastModifiedTime": assignStringTo(&oinfo.LastModifiedTime),
"IsAnonymousUser": assignBoolTo(&oinfo.IsAnonymousUser),
"UserFriendlyName": assignStringTo(&oinfo.UserFriendlyName),
"UserId": assignStringTo(&oinfo.UserId),
"ReadOnly": assignBoolTo(&oinfo.ReadOnly),
"UserCanNotWriteRelative": assignBoolTo(&oinfo.UserCanNotWriteRelative),
"UserCanRename": assignBoolTo(&oinfo.UserCanRename),
"UserCanReview": assignBoolTo(&oinfo.UserCanReview),
"UserCanWrite": assignBoolTo(&oinfo.UserCanWrite),
"SupportsLocks": assignBoolTo(&oinfo.SupportsLocks),
"SupportsRename": assignBoolTo(&oinfo.SupportsRename),
"SupportsReviewing": assignBoolTo(&oinfo.SupportsReviewing),
"SupportsUpdate": assignBoolTo(&oinfo.SupportsUpdate),
"EnableInsertRemoteImage": assignBoolTo(&oinfo.EnableInsertRemoteImage),
"HidePrintOption": assignBoolTo(&oinfo.HidePrintOption),
}
for key, value := range props {
setterFn := setters[key]
if setterFn != nil {
setterFn(value)
}
}
}
func (oinfo *OnlyOffice) GetTarget() string {
return "OnlyOffice"
}