fix: use constants for the properties

This commit is contained in:
Juan Pablo Villafáñez
2024-06-21 12:46:33 +02:00
parent cfc39fac24
commit ab636a611f
5 changed files with 250 additions and 144 deletions
@@ -538,42 +538,42 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (fileinfo.FileInfo, e
// 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()),
fileinfo.KeyOwnerID: hexEncodedOwnerId,
fileinfo.KeySize: int64(statRes.GetInfo().GetSize()),
fileinfo.KeyVersion: version,
fileinfo.KeyBaseFileName: path.Base(statRes.GetInfo().GetPath()),
fileinfo.KeyBreadcrumbDocName: path.Base(statRes.GetInfo().GetPath()),
// to get the folder we actually need to do a GetPath() request
//BreadcrumbFolderName: path.Dir(statRes.Info.Path),
"HostViewURL": wopiContext.ViewAppUrl,
"HostEditURL": wopiContext.EditAppUrl,
fileinfo.KeyHostViewURL: wopiContext.ViewAppUrl,
fileinfo.KeyHostEditURL: wopiContext.EditAppUrl,
"EnableOwnerTermination": true, // only for collabora
"SupportsExtendedLockLength": true,
"SupportsGetLock": true,
"SupportsLocks": true,
"SupportsUpdate": true,
fileinfo.KeyEnableOwnerTermination: true, // only for collabora
fileinfo.KeySupportsExtendedLockLength: true,
fileinfo.KeySupportsGetLock: true,
fileinfo.KeySupportsLocks: true,
fileinfo.KeySupportsUpdate: true,
"UserCanNotWriteRelative": true,
"IsAnonymousUser": isAnonymousUser,
"UserFriendlyName": userFriendlyName,
"UserID": userId,
fileinfo.KeyUserCanNotWriteRelative: true,
fileinfo.KeyIsAnonymousUser: isAnonymousUser,
fileinfo.KeyUserFriendlyName: userFriendlyName,
fileinfo.KeyUserID: userId,
}
switch wopiContext.ViewMode {
case appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE:
infoMap["UserCanWrite"] = true
infoMap[fileinfo.KeyUserCanWrite] = true
case appproviderv1beta1.ViewMode_VIEW_MODE_READ_ONLY:
// nothing special to do here for now
case appproviderv1beta1.ViewMode_VIEW_MODE_VIEW_ONLY:
infoMap["DisableExport"] = true // only for collabora
infoMap["DisableCopy"] = true // only for collabora
infoMap["DisablePrint"] = true
infoMap[fileinfo.KeyDisableExport] = true // only for collabora
infoMap[fileinfo.KeyDisableCopy] = true // only for collabora
infoMap[fileinfo.KeyDisablePrint] = true
if !isPublicShare {
infoMap["WatermarkText"] = f.watermarkText(wopiContext.User) // only for collabora
infoMap[fileinfo.KeyWatermarkText] = f.watermarkText(wopiContext.User) // only for collabora
}
}
@@ -84,65 +84,65 @@ type Collabora struct {
func (cinfo *Collabora) SetProperties(props map[string]interface{}) {
for key, value := range props {
switch key {
case "BaseFileName":
case KeyBaseFileName:
cinfo.BaseFileName = value.(string)
case "DisablePrint":
case KeyDisablePrint:
cinfo.DisablePrint = value.(bool)
case "OwnerID":
case KeyOwnerID:
cinfo.OwnerID = value.(string)
case "PostMessageOrigin":
case KeyPostMessageOrigin:
cinfo.PostMessageOrigin = value.(string)
case "Size":
case KeySize:
cinfo.Size = value.(int64)
case "TemplateSource":
case KeyTemplateSource:
cinfo.TemplateSource = value.(string)
case "UserCanWrite":
case KeyUserCanWrite:
cinfo.UserCanWrite = value.(bool)
case "UserCanNotWriteRelative":
case KeyUserCanNotWriteRelative:
cinfo.UserCanNotWriteRelative = value.(bool)
case "UserID":
case KeyUserID:
cinfo.UserID = value.(string)
case "UserFriendlyName":
case KeyUserFriendlyName:
cinfo.UserFriendlyName = value.(string)
case "EnableInsertRemoteImage":
case KeyEnableInsertRemoteImage:
cinfo.EnableInsertRemoteImage = value.(bool)
case "DisableInsertLocalImage":
case KeyDisableInsertLocalImage:
cinfo.DisableInsertLocalImage = value.(bool)
case "HidePrintOption":
case KeyHidePrintOption:
cinfo.HidePrintOption = value.(bool)
case "HideSaveOption":
case KeyHideSaveOption:
cinfo.HideSaveOption = value.(bool)
case "HideExportOption":
case KeyHideExportOption:
cinfo.HideExportOption = value.(bool)
case "DisableExport":
case KeyDisableExport:
cinfo.DisableExport = value.(bool)
case "DisableCopy":
case KeyDisableCopy:
cinfo.DisableCopy = value.(bool)
case "DisableInactiveMessages":
case KeyDisableInactiveMessages:
cinfo.DisableInactiveMessages = value.(bool)
case "DownloadAsPostMessage":
case KeyDownloadAsPostMessage:
cinfo.DownloadAsPostMessage = value.(bool)
case "SaveAsPostmessage":
case KeySaveAsPostmessage:
cinfo.SaveAsPostmessage = value.(bool)
case "EnableOwnerTermination":
case KeyEnableOwnerTermination:
cinfo.EnableOwnerTermination = value.(bool)
//UserExtraInfo -> requires definition, currently not used
//UserPrivateInfo -> requires definition, currently not used
case "WatermarkText":
case KeyWatermarkText:
cinfo.WatermarkText = value.(string)
case "EnableShare":
case KeyEnableShare:
cinfo.EnableShare = value.(bool)
case "HideUserList":
case KeyHideUserList:
cinfo.HideUserList = value.(string)
case "SupportsLocks":
case KeySupportsLocks:
cinfo.SupportsLocks = value.(bool)
case "SupportsRename":
case KeySupportsRename:
cinfo.SupportsRename = value.(bool)
case "UserCanRename":
case KeyUserCanRename:
cinfo.UserCanRename = value.(bool)
case "BreadcrumbDocName":
case KeyBreadcrumbDocName:
cinfo.BreadcrumbDocName = value.(string)
}
}
@@ -24,3 +24,109 @@ type FileInfo interface {
// Note that the returned value must be unique among all the implementations
GetTarget() string
}
// constants that can be used to refer the fileinfo properties for the
// SetProperties method of the FileInfo interface
const (
KeyBaseFileName = "BaseFileName"
KeyOwnerID = "OwnerId"
KeySize = "Size"
KeyUserID = "UserID"
KeyVersion = "Version"
KeySupportedShareURLTypes = "SupportedShareURLTypes"
KeySupportsCobalt = "SupportsCobalt"
KeySupportsContainers = "SupportsContainers"
KeySupportsDeleteFile = "SupportsDeleteFile"
KeySupportsEcosystem = "SupportsEcosystem"
KeySupportsExtendedLockLength = "SupportsExtendedLockLength"
KeySupportsFolders = "SupportsFolders"
//KeySupportsGetFileWopiSrc = "SupportsGetFileWopiSrc" // wopivalidator is complaining and the property isn't used for now -> commented
KeySupportsGetLock = "SupportsGetLock"
KeySupportsLocks = "SupportsLocks"
KeySupportsRename = "SupportsRename"
KeySupportsUpdate = "SupportsUpdate"
KeySupportsUserInfo = "SupportsUserInfo"
KeyIsAnonymousUser = "IsAnonymousUser"
KeyIsEduUser = "IsEduUser"
KeyLicenseCheckForEditIsEnabled = "LicenseCheckForEditIsEnabled"
KeyUserFriendlyName = "UserFriendlyName"
KeyUserInfo = "UserInfo"
KeyReadOnly = "ReadOnly"
KeyRestrictedWebViewOnly = "RestrictedWebViewOnly"
KeyUserCanAttend = "UserCanAttend"
KeyUserCanNotWriteRelative = "UserCanNotWriteRelative"
KeyUserCanPresent = "UserCanPresent"
KeyUserCanRename = "UserCanRename"
KeyUserCanWrite = "UserCanWrite"
KeyCloseURL = "CloseURL"
KeyDownloadURL = "DownloadURL"
KeyFileEmbedCommandURL = "FileEmbedCommandURL"
KeyFileSharingURL = "FileSharingURL"
KeyFileURL = "FileURL"
KeyFileVersionURL = "FileVersionURL"
KeyHostEditURL = "HostEditURL"
KeyHostEmbeddedViewURL = "HostEmbeddedViewURL"
KeyHostViewURL = "HostViewURL"
KeySignoutURL = "SignoutURL"
KeyAllowAdditionalMicrosoftServices = "AllowAdditionalMicrosoftServices"
KeyAllowErrorReportPrompt = "AllowErrorReportPrompt"
KeyAllowExternalMarketplace = "AllowExternalMarketplace"
KeyClientThrottlingProtection = "ClientThrottlingProtection"
KeyCloseButtonClosesWindow = "CloseButtonClosesWindow"
KeyCopyPasteRestrictions = "CopyPasteRestrictions"
KeyDisablePrint = "DisablePrint"
KeyDisableTranslation = "DisableTranslation"
KeyFileExtension = "FileExtension"
KeyFileNameMaxLength = "FileNameMaxLength"
KeyLastModifiedTime = "LastModifiedTime"
KeyRequestedCallThrottling = "RequestedCallThrottling"
KeySHA256 = "SHA256"
KeySharingStatus = "SharingStatus"
KeyTemporarilyNotWritable = "TemporarilyNotWritable"
//KeyUniqueContentId = "UniqueContentId" // From microsoft docs: Not supported in CSPP -> commented
KeyBreadcrumbBrandName = "BreadcrumbBrandName"
KeyBreadcrumbBrandURL = "BreadcrumbBrandURL"
KeyBreadcrumbDocName = "BreadcrumbDocName"
KeyBreadcrumbFolderName = "BreadcrumbFolderName"
KeyBreadcrumbFolderURL = "BreadcrumbFolderUrl"
// Collabora (non-dupped) properties below
KeyPostMessageOrigin = "PostMessageOrigin"
KeyTemplateSource = "TemplateSource"
KeyEnableInsertRemoteImage = "EnableInsertRemoteImage"
KeyDisableInsertLocalImage = "DisableInsertLocalImage"
KeyHidePrintOption = "HidePrintOption"
KeyHideSaveOption = "HideSaveOption"
KeyHideExportOption = "HideExportOption"
KeyDisableExport = "DisableExport"
KeyDisableCopy = "DisableCopy"
KeyDisableInactiveMessages = "DisableInactiveMessages"
KeyDownloadAsPostMessage = "DownloadAsPostMessage"
KeySaveAsPostmessage = "SaveAsPostmessage"
KeyEnableOwnerTermination = "EnableOwnerTermination"
//KeyUserExtraInfo -> requires definition, currently not used
//KeyUserPrivateInfo -> requires definition, currently not used
KeyWatermarkText = "WatermarkText"
KeyEnableShare = "EnableShare"
KeyHideUserList = "HideUserList"
// OnlyOffice (non-dupped) properties below
KeyClosePostMessage = "ClosePostMessage"
KeyEditModePostMessage = "EditModePostMessage"
KeyEditNotificationPostMessage = "EditNotificationPostMessage"
KeyFileSharingPostMessage = "FileSharingPostMessage"
KeyFileVersionPostMessage = "FileVersionPostMessage"
KeyUserCanReview = "UserCanReview"
KeySupportsReviewing = "SupportsReviewing"
)
@@ -167,130 +167,130 @@ type Microsoft struct {
func (minfo *Microsoft) SetProperties(props map[string]interface{}) {
for key, value := range props {
switch key {
case "BaseFileName":
case KeyBaseFileName:
minfo.BaseFileName = value.(string)
case "OwnerID":
case KeyOwnerID:
minfo.OwnerID = value.(string)
case "Size":
case KeySize:
minfo.Size = value.(int64)
case "UserID":
case KeyUserID:
minfo.UserID = value.(string)
case "Version":
case KeyVersion:
minfo.Version = value.(string)
case "SupportedShareURLTypes":
case KeySupportedShareURLTypes:
minfo.SupportedShareURLTypes = value.([]string)
case "SupportsCobalt":
case KeySupportsCobalt:
minfo.SupportsCobalt = value.(bool)
case "SupportsContainers":
case KeySupportsContainers:
minfo.SupportsContainers = value.(bool)
case "SupportsDeleteFile":
case KeySupportsDeleteFile:
minfo.SupportsDeleteFile = value.(bool)
case "SupportsEcosystem":
case KeySupportsEcosystem:
minfo.SupportsEcosystem = value.(bool)
case "SupportsExtendedLockLength":
case KeySupportsExtendedLockLength:
minfo.SupportsExtendedLockLength = value.(bool)
case "SupportsFolders":
case KeySupportsFolders:
minfo.SupportsFolders = value.(bool)
//SupportsGetFileWopiSrc bool `json:"SupportsGetFileWopiSrc"` // wopivalidator is complaining and the property isn't used for now -> commented
case "SupportsGetLock":
case KeySupportsGetLock:
minfo.SupportsGetLock = value.(bool)
case "SupportsLocks":
case KeySupportsLocks:
minfo.SupportsLocks = value.(bool)
case "SupportsRename":
case KeySupportsRename:
minfo.SupportsRename = value.(bool)
case "SupportsUpdate":
case KeySupportsUpdate:
minfo.SupportsUpdate = value.(bool)
case "SupportsUserInfo":
case KeySupportsUserInfo:
minfo.SupportsUserInfo = value.(bool)
case "IsAnonymousUser":
case KeyIsAnonymousUser:
minfo.IsAnonymousUser = value.(bool)
case "IsEduUser":
case KeyIsEduUser:
minfo.IsEduUser = value.(bool)
case "LicenseCheckForEditIsEnabled":
case KeyLicenseCheckForEditIsEnabled:
minfo.LicenseCheckForEditIsEnabled = value.(bool)
case "UserFriendlyName":
case KeyUserFriendlyName:
minfo.UserFriendlyName = value.(string)
case "UserInfo":
case KeyUserInfo:
minfo.UserInfo = value.(string)
case "ReadOnly":
case KeyReadOnly:
minfo.ReadOnly = value.(bool)
case "RestrictedWebViewOnly":
case KeyRestrictedWebViewOnly:
minfo.RestrictedWebViewOnly = value.(bool)
case "UserCanAttend":
case KeyUserCanAttend:
minfo.UserCanAttend = value.(bool)
case "UserCanNotWriteRelative":
case KeyUserCanNotWriteRelative:
minfo.UserCanNotWriteRelative = value.(bool)
case "UserCanPresent":
case KeyUserCanPresent:
minfo.UserCanPresent = value.(bool)
case "UserCanRename":
case KeyUserCanRename:
minfo.UserCanRename = value.(bool)
case "UserCanWrite":
case KeyUserCanWrite:
minfo.UserCanWrite = value.(bool)
case "CloseURL":
case KeyCloseURL:
minfo.CloseURL = value.(string)
case "DownloadURL":
case KeyDownloadURL:
minfo.DownloadURL = value.(string)
case "FileEmbedCommandURL":
case KeyFileEmbedCommandURL:
minfo.FileEmbedCommandURL = value.(string)
case "FileSharingURL":
case KeyFileSharingURL:
minfo.FileSharingURL = value.(string)
case "FileURL":
case KeyFileURL:
minfo.FileURL = value.(string)
case "FileVersionURL":
case KeyFileVersionURL:
minfo.FileVersionURL = value.(string)
case "HostEditURL":
case KeyHostEditURL:
minfo.HostEditURL = value.(string)
case "HostEmbeddedViewURL":
case KeyHostEmbeddedViewURL:
minfo.HostEmbeddedViewURL = value.(string)
case "HostViewURL":
case KeyHostViewURL:
minfo.HostViewURL = value.(string)
case "SignoutURL":
case KeySignoutURL:
minfo.SignoutURL = value.(string)
case "AllowAdditionalMicrosoftServices":
case KeyAllowAdditionalMicrosoftServices:
minfo.AllowAdditionalMicrosoftServices = value.(bool)
case "AllowErrorReportPrompt":
case KeyAllowErrorReportPrompt:
minfo.AllowErrorReportPrompt = value.(bool)
case "AllowExternalMarketplace":
case KeyAllowExternalMarketplace:
minfo.AllowExternalMarketplace = value.(bool)
case "ClientThrottlingProtection":
case KeyClientThrottlingProtection:
minfo.ClientThrottlingProtection = value.(string)
case "CloseButtonClosesWindow":
case KeyCloseButtonClosesWindow:
minfo.CloseButtonClosesWindow = value.(bool)
case "CopyPasteRestrictions":
case KeyCopyPasteRestrictions:
minfo.CopyPasteRestrictions = value.(string)
case "DisablePrint":
case KeyDisablePrint:
minfo.DisablePrint = value.(bool)
case "DisableTranslation":
case KeyDisableTranslation:
minfo.DisableTranslation = value.(bool)
case "FileExtension":
case KeyFileExtension:
minfo.FileExtension = value.(string)
case "FileNameMaxLength":
case KeyFileNameMaxLength:
minfo.FileNameMaxLength = value.(int)
case "LastModifiedTime":
case KeyLastModifiedTime:
minfo.LastModifiedTime = value.(string)
case "RequestedCallThrottling":
case KeyRequestedCallThrottling:
minfo.RequestedCallThrottling = value.(string)
case "SHA256":
case KeySHA256:
minfo.SHA256 = value.(string)
case "SharingStatus":
case KeySharingStatus:
minfo.SharingStatus = value.(string)
case "TemporarilyNotWritable":
case KeyTemporarilyNotWritable:
minfo.TemporarilyNotWritable = value.(bool)
case "BreadcrumbBrandName":
case KeyBreadcrumbBrandName:
minfo.BreadcrumbBrandName = value.(string)
case "BreadcrumbBrandURL":
case KeyBreadcrumbBrandURL:
minfo.BreadcrumbBrandURL = value.(string)
case "BreadcrumbDocName":
case KeyBreadcrumbDocName:
minfo.BreadcrumbDocName = value.(string)
case "BreadcrumbFolderName":
case KeyBreadcrumbFolderName:
minfo.BreadcrumbFolderName = value.(string)
case "BreadcrumbFolderURL":
case KeyBreadcrumbFolderURL:
minfo.BreadcrumbFolderURL = value.(string)
}
}
@@ -131,85 +131,85 @@ type OnlyOffice struct {
func (oinfo *OnlyOffice) SetProperties(props map[string]interface{}) {
for key, value := range props {
switch key {
case "BaseFileName":
case KeyBaseFileName:
oinfo.BaseFileName = value.(string)
case "Version":
case KeyVersion:
oinfo.Version = value.(string)
case "BreadcrumbBrandName":
case KeyBreadcrumbBrandName:
oinfo.BreadcrumbBrandName = value.(string)
case "BreadcrumbBrandURL":
case KeyBreadcrumbBrandURL:
oinfo.BreadcrumbBrandURL = value.(string)
case "BreadcrumbDocName":
case KeyBreadcrumbDocName:
oinfo.BreadcrumbDocName = value.(string)
case "BreadcrumbFolderName":
case KeyBreadcrumbFolderName:
oinfo.BreadcrumbFolderName = value.(string)
case "BreadcrumbFolderURL":
case KeyBreadcrumbFolderURL:
oinfo.BreadcrumbFolderURL = value.(string)
case "ClosePostMessage":
case KeyClosePostMessage:
oinfo.ClosePostMessage = value.(bool)
case "EditModePostMessage":
case KeyEditModePostMessage:
oinfo.EditModePostMessage = value.(bool)
case "EditNotificationPostMessage":
case KeyEditNotificationPostMessage:
oinfo.EditNotificationPostMessage = value.(bool)
case "FileSharingPostMessage":
case KeyFileSharingPostMessage:
oinfo.FileSharingPostMessage = value.(bool)
case "FileVersionPostMessage":
case KeyFileVersionPostMessage:
oinfo.FileVersionPostMessage = value.(bool)
case "PostMessageOrigin":
case KeyPostMessageOrigin:
oinfo.PostMessageOrigin = value.(string)
case "CloseURL":
case KeyCloseURL:
oinfo.CloseURL = value.(string)
case "FileSharingURL":
case KeyFileSharingURL:
oinfo.FileSharingURL = value.(string)
case "FileVersionURL":
case KeyFileVersionURL:
oinfo.FileVersionURL = value.(string)
case "HostEditURL":
case KeyHostEditURL:
oinfo.HostEditURL = value.(string)
case "CopyPasteRestrictions":
case KeyCopyPasteRestrictions:
oinfo.CopyPasteRestrictions = value.(string)
case "DisablePrint":
case KeyDisablePrint:
oinfo.DisablePrint = value.(bool)
case "FileExtension":
case KeyFileExtension:
oinfo.FileExtension = value.(string)
case "FileNameMaxLength":
case KeyFileNameMaxLength:
oinfo.FileNameMaxLength = value.(int)
case "LastModifiedTime":
case KeyLastModifiedTime:
oinfo.LastModifiedTime = value.(string)
case "IsAnonymousUser":
case KeyIsAnonymousUser:
oinfo.IsAnonymousUser = value.(bool)
case "UserFriendlyName":
case KeyUserFriendlyName:
oinfo.UserFriendlyName = value.(string)
case "UserID":
case KeyUserID:
oinfo.UserID = value.(string)
case "ReadOnly":
case KeyReadOnly:
oinfo.ReadOnly = value.(bool)
case "UserCanNotWriteRelative":
case KeyUserCanNotWriteRelative:
oinfo.UserCanNotWriteRelative = value.(bool)
case "UserCanRename":
case KeyUserCanRename:
oinfo.UserCanRename = value.(bool)
case "UserCanReview":
case KeyUserCanReview:
oinfo.UserCanReview = value.(bool)
case "UserCanWrite":
case KeyUserCanWrite:
oinfo.UserCanWrite = value.(bool)
case "SupportsLocks":
case KeySupportsLocks:
oinfo.SupportsLocks = value.(bool)
case "SupportsRename":
case KeySupportsRename:
oinfo.SupportsRename = value.(bool)
case "SupportsReviewing":
case KeySupportsReviewing:
oinfo.SupportsReviewing = value.(bool)
case "SupportsUpdate":
case KeySupportsUpdate:
oinfo.SupportsUpdate = value.(bool)
case "EnableInsertRemoteImage":
case KeyEnableInsertRemoteImage:
oinfo.EnableInsertRemoteImage = value.(bool)
case "HidePrintOption":
case KeyHidePrintOption:
oinfo.HidePrintOption = value.(bool)
}
}