Skip to content

Commit

Permalink
apps: fixed viewMode resolution by making permissions override user's…
Browse files Browse the repository at this point in the history
… choices (cs3org#3805)
  • Loading branch information
glpatcern authored and gmgigi96 committed Jun 28, 2023
1 parent d5aa80d commit 20be8e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/apps-viewmode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Apps: fixed viewMode resolution

Currently, the viewMode passed on /app/open is taken without validating
the actual user's permissions. This PR fixes this.

https://github.com/cs3org/reva/pull/3805
14 changes: 9 additions & 5 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,19 +449,23 @@ func filterAppsByUserAgent(mimeTypes []*appregistry.MimeTypeInfo, userAgent stri
}

func resolveViewMode(res *provider.ResourceInfo, vm string) gateway.OpenInAppRequest_ViewMode {
var viewMode gateway.OpenInAppRequest_ViewMode
if vm != "" {
return utils.GetViewMode(vm)
viewMode = utils.GetViewMode(vm)
} else {
viewMode = gateway.OpenInAppRequest_VIEW_MODE_READ_WRITE
}

var viewMode gateway.OpenInAppRequest_ViewMode
canEdit := res.PermissionSet.InitiateFileUpload
canView := res.PermissionSet.InitiateFileDownload

switch {
case canEdit && canView:
viewMode = gateway.OpenInAppRequest_VIEW_MODE_READ_WRITE
// ok
case canView:
viewMode = gateway.OpenInAppRequest_VIEW_MODE_READ_ONLY
if viewMode == gateway.OpenInAppRequest_VIEW_MODE_READ_WRITE || viewMode == gateway.OpenInAppRequest_VIEW_MODE_PREVIEW {
// downgrade to the maximum permitted viewmode
viewMode = gateway.OpenInAppRequest_VIEW_MODE_READ_ONLY
}
default:
// no permissions, will return access denied
viewMode = gateway.OpenInAppRequest_VIEW_MODE_INVALID
Expand Down

0 comments on commit 20be8e6

Please sign in to comment.