Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable open in app for given paths #4304

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/disable-open-in-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Disable open in app for given paths

https://github.com/cs3org/reva/pull/4304
1 change: 1 addition & 0 deletions internal/http/services/owncloud/ocdav/ocdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type Config struct {
FavoriteStorageDriver string `mapstructure:"favorite_storage_driver"`
FavoriteStorageDrivers map[string]map[string]interface{} `mapstructure:"favorite_storage_drivers"`
PublicLinkDownload *ConfigPublicLinkDownload `mapstructure:"publiclink_download"`
DisabledOpenInAppPaths []string `mapstructure:"disabled_open_in_app_paths"`
Notifications map[string]interface{} `docs:"Settingsg for the Notification Helper" mapstructure:"notifications"`
}

Expand Down
22 changes: 22 additions & 0 deletions internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,27 @@ func supportLegacyOCMAccess(ctx context.Context, md *provider.ResourceInfo) {
}
}

func appendSlash(path string) string {
if path == "" {
return "/"
}
if path[len(path)-1] == '/' {
return path
}
return path + "/"
}

func (s *svc) isOpenable(path string) bool {
path = appendSlash(path)
path = filepath.Join("/", path)
for _, prefix := range s.c.DisabledOpenInAppPaths {
if strings.HasPrefix(path, appendSlash(prefix)) {
return false
}
}
return true
}

// mdToPropResponse converts the CS3 metadata into a webdav PropResponse
// ns is the CS3 namespace that needs to be removed from the CS3 path before
// prefixing it with the baseURI.
Expand Down Expand Up @@ -567,6 +588,7 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
isShared,
false,
isPublic,
s.isOpenable(md.Path),
)
sublog.Debug().Interface("role", role).Str("dav-permissions", wdp).Msg("converted PermissionSet")
}
Expand Down
1 change: 1 addition & 0 deletions internal/http/services/owncloud/ocdav/tus.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func (s *svc) handleTusPost(ctx context.Context, w http.ResponseWriter, r *http.
isShared,
false,
isPublic,
s.isOpenable(info.Path),
)

w.Header().Set(HeaderContentType, info.MimeType)
Expand Down
9 changes: 7 additions & 2 deletions internal/http/services/owncloud/ocs/conversions/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ func (r *Role) OCSPermissions() Permissions {
// S = Shared
// R = Shareable
// M = Mounted
// Z = Deniable (NEW).
func (r *Role) WebDAVPermissions(isDir, isShared, isMountpoint, isPublic bool) string {
// Z = Deniable
// O = Openable.
func (r *Role) WebDAVPermissions(isDir, isShared, isMountpoint, isPublic, isOpenable bool) string {
var b strings.Builder
if !isPublic && isShared {
fmt.Fprintf(&b, "S")
Expand Down Expand Up @@ -125,6 +126,10 @@ func (r *Role) WebDAVPermissions(isDir, isShared, isMountpoint, isPublic bool) s
fmt.Fprintf(&b, "Z")
}

if isOpenable && !isDir {
fmt.Fprintf(&b, "O")
}

return b.String()
}

Expand Down