impress: restrict presentation in readonly mode

When export is disabled or watermarks are enabled, presentation in readonly mode
is disabled.
This is checked in the frontend by the WOPI property `DisablePresentation`
that is synthesized in the wsd. Also check when calling the presentation
command.
WOPIFileInfo::getWatermarkText() is stubbed on mobile.

Signed-off-by: Hubert Figuière <hub@collabora.com>
Change-Id: I4f7aff9f670f7523dfcf396f6009a272df9d5af8
pull/8986/head
Hubert Figuière 2024-05-01 12:23:10 -04:00 committed by Caolán McNamara
parent 72bbc375be
commit 22e789a420
6 changed files with 35 additions and 1 deletions

View File

@ -1324,7 +1324,6 @@ L.Control.Menubar = L.Control.extend({
!window.ThisIsAMobileApp ? 'exportdirectpdf' : 'downloadas-pdf', !window.ThisIsAMobileApp ? 'exportepub' : 'downloadas-epub', // file menu
'downloadas-ods', 'downloadas-xls', 'downloadas-xlsx', 'downloadas-csv', 'closedocument', // file menu
'fullscreen', 'zoomin', 'zoomout', 'zoomreset', 'showstatusbar', 'togglemenubar', 'showresolved', 'toggledarktheme', // view menu
'fullscreen-presentation', 'presentation-currentslide', 'present-in-window', // slide menu
'about', 'keyboard-shortcuts', 'latestupdates', 'feedback', 'online-help', 'report-an-issue', // help menu
'insertcomment'
]
@ -1341,6 +1340,10 @@ L.Control.Menubar = L.Control.extend({
// Use original template as provided by server
this._menubarCont = map.mainMenuTemplate.cloneNode(true);
$('#main-menu-state').after(this._menubarCont);
if (!this._map['wopi'].DisablePresentation)
this.options.allowedViewModeActions = this.options.allowedViewModeActions.concat(['fullscreen-presentation', 'presentation-currentslide', 'present-in-window']);
this._initializeMenu(this.options.initial);
map.on('doclayerinit', this._onDocLayerInit, this);

View File

@ -36,6 +36,11 @@ L.Map.SlideShow = L.Handler.extend({
},
_onFullScreen: function (e) {
if (this._checkPresentationDisabled()) {
this._notifyPresentationDisabled();
return;
}
if (this._checkAlreadyPresenting()) {
this._notifyAlreadyPresenting();
return;
@ -94,6 +99,11 @@ L.Map.SlideShow = L.Handler.extend({
},
_onPresentWindow: function (e) {
if (this._checkPresentationDisabled()) {
this._notifyPresentationDisabled();
return;
}
if (this._checkAlreadyPresenting()) {
this._notifyAlreadyPresenting();
return;
@ -295,6 +305,16 @@ L.Map.SlideShow = L.Handler.extend({
_('OK'), null, false);
},
_checkPresentationDisabled: function() {
return this._map['wopi'].DisablePresentation;
},
_notifyPresentationDisabled: function() {
this._map.uiManager.showInfoModal('presentation-disabled-modal',
_('Presentation disabled'),
_('Presentation mode has been disabled for this document'), '',
_('OK'), null, false);
},
_onSlideWindowKeyPress: function(e) {
if (e.code === 'Escape') {

View File

@ -32,6 +32,7 @@ L.Map.WOPI = L.Handler.extend({
SupportsRename: false,
UserCanRename: false,
UserCanWrite: false,
DisablePresentation: false,
_appLoadedConditions: {
docloaded: false,
@ -127,6 +128,7 @@ L.Map.WOPI = L.Handler.extend({
this.UserCanRename = !!wopiInfo['UserCanRename'];
this.EnableShare = !!wopiInfo['EnableShare'];
this.UserCanWrite = !!wopiInfo['UserCanWrite'];
this.DisablePresentation = wopiInfo['DisablePresentation'];
if (this.UserCanWrite && !app.isReadOnly()) // There are 2 places that set the file permissions, WOPI and URI. Don't change permission if URI doesn't allow.
app.setPermission('edit');

View File

@ -81,6 +81,7 @@ public:
bool getDisableExport() const { return false; }
bool getDisableCopy() const { return false; }
bool getEnableOwnerTermination() const { return false; }
std::string getWatermarkText() const { return std::string(); }
TriState getDisableChangeTrackingShow() const { return TriState::Unset; }
TriState getDisableChangeTrackingRecord() const { return TriState::Unset; }

View File

@ -1493,6 +1493,12 @@ bool ClientSession::filterMessage(const std::string& message) const
allowed = false;
LOG_WRN("WOPI host has disabled export for this session");
}
else if (id == "slideshow" && _wopiFileInfo &&
(_wopiFileInfo->getDisableExport() || !_wopiFileInfo->getWatermarkText().empty()))
{
allowed = false;
LOG_WRN("WOPI host has disabled slideshow for this session");
}
}
else
{

View File

@ -1230,6 +1230,8 @@ DocumentBroker::updateSessionWithWopiInfo(const std::shared_ptr<ClientSession>&
wopiInfo->set("HideChangeTrackingControls", wopiFileInfo->getHideChangeTrackingControls() ==
WopiStorage::WOPIFileInfo::TriState::True);
wopiInfo->set("IsOwner", session->isDocumentOwner());
bool disablePresentation = !watermarkText.empty() || wopiFileInfo->getDisableExport() || wopiFileInfo->getHideExportOption();
wopiInfo->set("DisablePresentation", disablePresentation);
std::ostringstream ossWopiInfo;
wopiInfo->stringify(ossWopiInfo);