Skip to content

Commit

Permalink
disable open in app for given paths
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Oct 31, 2023
1 parent d17f87c commit c156094
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
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
21 changes: 21 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,26 @@ 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)
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 +587,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

0 comments on commit c156094

Please sign in to comment.