Skip to content

Commit 34b2efa

Browse files
committed
Added EMBEDDED view mode
1 parent 6ef0696 commit 34b2efa

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/core/wopi.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def checkFileInfo(fileid, acctok):
6969
fmd['IsAnonymousUser'] = False
7070
fmd['UserFriendlyName'] = acctok['username']
7171
fmd['BreadcrumbFolderName'] = 'ScienceMesh share' if acctok['usertype'] == utils.UserType.OCM else 'Parent folder'
72-
if acctok['viewmode'] != utils.ViewMode.VIEW_ONLY and srv.config.get('general', 'downloadurl', fallback=None):
72+
if acctok['viewmode'] not in (utils.ViewMode.VIEW_ONLY, utils.ViewMode.EMBEDDED) and \
73+
srv.config.get('general', 'downloadurl', fallback=None):
7374
fmd['DownloadUrl'] = fmd['FileUrl'] = '%s?access_token=%s' % \
7475
(srv.config.get('general', 'downloadurl'), flask.request.args['access_token'])
7576
fmd['BreadcrumbBrandName'] = srv.config.get('general', 'brandingname', fallback=None)
@@ -87,12 +88,12 @@ def checkFileInfo(fileid, acctok):
8788
fmd['SupportsUpdate'] = fmd['UserCanWrite'] = fmd['SupportsLocks'] = \
8889
fmd['SupportsDeleteFile'] = acctok['viewmode'] in (utils.ViewMode.READ_WRITE, utils.ViewMode.PREVIEW)
8990
fmd['ReadOnly'] = not fmd['SupportsUpdate']
90-
fmd['RestrictedWebViewOnly'] = acctok['viewmode'] == utils.ViewMode.VIEW_ONLY
91+
fmd['RestrictedWebViewOnly'] = acctok['viewmode'] in (utils.ViewMode.VIEW_ONLY, utils.ViewMode.EMBEDDED)
9192
# SaveAs functionality is disabled for anonymous and federated users, as they have no personal space where to save
9293
# as an alternate location and we cannot assume that saving to the same folder is allowed (e.g. single-file shares).
9394
# Instead, regular (authenticated) users are offered a SaveAs (unless in view-only mode), where the operation
9495
# is executed to the user's home if no access is given to the same folder where the file is.
95-
fmd['UserCanNotWriteRelative'] = acctok['viewmode'] == utils.ViewMode.VIEW_ONLY or \
96+
fmd['UserCanNotWriteRelative'] = acctok['viewmode'] in (utils.ViewMode.VIEW_ONLY, utils.ViewMode.EMBEDDED) or \
9697
acctok['usertype'] != utils.UserType.REGULAR
9798
fmd['SupportsRename'] = fmd['UserCanRename'] = enablerename and \
9899
acctok['viewmode'] in (utils.ViewMode.READ_WRITE, utils.ViewMode.PREVIEW)
@@ -133,7 +134,8 @@ def checkFileInfo(fileid, acctok):
133134
# extensions for Collabora Online
134135
if 'Collabora' in acctok['appname']:
135136
fmd['EnableOwnerTermination'] = True
136-
fmd['DisableExport'] = fmd['DisableCopy'] = fmd['DisablePrint'] = acctok['viewmode'] == utils.ViewMode.VIEW_ONLY
137+
fmd['DisableExport'] = fmd['DisableCopy'] = fmd['DisablePrint'] = acctok['viewmode'] in (utils.ViewMode.VIEW_ONLY,
138+
utils.ViewMode.EMBEDDED)
137139
if srv.config.get('apps', 'codedisableexport', fallback='False').upper() == 'TRUE':
138140
fmd['UserCanNotWriteRelative'] = fmd['DisableExport'] = True
139141

@@ -377,7 +379,7 @@ def putRelative(fileid, reqheaders, acctok):
377379
(acctok['userid'][-20:], acctok['filename'], fileid, suggTarget, relTarget,
378380
overwriteTarget, reqheaders.get('X-WOPI-TimeStamp'), flask.request.args['access_token'][-20:]))
379381

380-
if acctok['viewmode'] == utils.ViewMode.VIEW_ONLY or acctok['usertype'] != utils.UserType.REGULAR:
382+
if acctok['viewmode'] in (utils.ViewMode.VIEW_ONLY, utils.ViewMode.EMBEDDED) or acctok['usertype'] != utils.UserType.REGULAR:
381383
# UNAUTHORIZED may seem better but the WOPI validator tests explicitly expect NOT_IMPLEMENTED
382384
return utils.createJsonResponse({'message': 'Unauthorized to perform PutRelative'}, http.client.NOT_IMPLEMENTED)
383385

src/core/wopiutils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class ViewMode(Enum):
5757
READ_WRITE = "VIEW_MODE_READ_WRITE"
5858
# The file can be downloaded and updated, and the app should be shown in preview mode
5959
PREVIEW = "VIEW_MODE_PREVIEW"
60+
# The file can be viewed in embedded mode, no editing is allowed
61+
EMBEDDED = "VIEW_MODE_EMBEDDED"
6062

6163

6264
class UserType(Enum):

src/wopiserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def iopOpenInApp():
361361
except bridge.FailedOpen as foe:
362362
return foe.msg, foe.statuscode
363363
else:
364-
# the base app URL is the editor in READ_WRITE mode, and the viewer in READ_ONLY or PREVIEW mode
364+
# the base app URL is the editor in READ_WRITE mode, and the viewer in READ_ONLY, PREVIEW or EMBEDDED mode
365365
# as the known WOPI applications all support switching from preview to edit mode
366366
res['app-url'] = appurl if vm == utils.ViewMode.READ_WRITE else appviewurl
367367
res['app-url'] += '%sWOPISrc=%s' % ('&' if '?' in res['app-url'] else '?',

0 commit comments

Comments
 (0)