Skip to content

Commit

Permalink
Feature flag for spaces in extractReference
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegeens committed Jan 20, 2025
1 parent 03d3621 commit 7d5d622
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions internal/http/services/owncloud/ocs/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Config struct {
OCMMountPoint string `mapstructure:"ocm_mount_point"`
ListOCMShares bool `mapstructure:"list_ocm_shares"`
Notifications map[string]interface{} `mapstructure:"notifications"`
EnableSpaces bool `mapstructure:"enable_spaces"`
}

// Init sets sane defaults.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type Handler struct {
listOCMShares bool
notificationHelper *notificationhelper.NotificationHelper
Log *zerolog.Logger
EnableSpaces bool
}

// we only cache the minimal set of data instead of the full user metadata.
Expand Down Expand Up @@ -117,6 +118,7 @@ func (h *Handler) Init(c *config.Config, l *zerolog.Logger) {
h.homeNamespace = c.HomeNamespace
h.ocmMountPoint = c.OCMMountPoint
h.listOCMShares = c.ListOCMShares
h.EnableSpaces = c.EnableSpaces
h.Log = l
h.notificationHelper = notificationhelper.New("ocs", c.Notifications, l)
h.additionalInfoTemplate, _ = template.New("additionalInfo").Parse(c.AdditionalInfoAttribute)
Expand Down Expand Up @@ -152,21 +154,34 @@ func (h *Handler) startCacheWarmup(c cache.Warmup) {

func (h *Handler) extractReference(r *http.Request) (*provider.Reference, error) {
var ref provider.Reference
if spaceID := r.FormValue("space_ref"); spaceID != "" {
_, base, _, ok := spaces.DecodeResourceID(spaceID)
if !ok {
return nil, errors.New("bad space id format")
}
if h.EnableSpaces {
if spaceID := r.FormValue("space_ref"); spaceID != "" {
_, base, _, ok := spaces.DecodeResourceID(spaceID)
if !ok {
return nil, errors.New("bad space id format")
}

ref.Path = base
}
if p := r.FormValue("path"); p != "" {
if ref.Path == "" {
ref.Path = path.Join(h.homeNamespace, p)
} else {
ref.Path = path.Join(ref.Path, p)
ref.Path = base
}
if p := r.FormValue("path"); p != "" {
if ref.Path == "" {
ref.Path = path.Join(h.homeNamespace, p)
} else {
ref.Path = path.Join(ref.Path, p)
}
}
} else {
if p := r.FormValue("path"); p != "" {
ref = provider.Reference{Path: path.Join(h.homeNamespace, p)}
} else if spaceRef := r.FormValue("space_ref"); spaceRef != "" {
var err error
ref, err = utils.ParseStorageSpaceReference(spaceRef)
if err != nil {
return nil, err
}
}
}

return &ref, nil
}

Expand Down

0 comments on commit 7d5d622

Please sign in to comment.