diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go index d81f1fb918e..ea8ad4a95a7 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go @@ -30,6 +30,7 @@ import ( "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/rhttp/router" + "github.com/cs3org/reva/pkg/storage/utils/templates" ) // Handler implements the ownCloud sharing API @@ -135,8 +136,5 @@ func (h *Handler) groupAsMatch(g *grouppb.Group) *conversions.MatchData { } func (h *Handler) getAdditionalInfoAttribute(u *userpb.User) string { - if h.additionalInfoAttribute == "username" { - return u.Username - } - return u.Mail + return templates.WithUser(u, h.additionalInfoAttribute) } diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index 88815672837..7075f192e3b 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -19,6 +19,7 @@ package shares import ( + "bytes" "context" "encoding/base64" "encoding/json" @@ -28,6 +29,7 @@ import ( "path" "strconv" "strings" + "text/template" "time" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" @@ -52,12 +54,12 @@ import ( // Handler implements the shares part of the ownCloud sharing API type Handler struct { - gatewayAddr string - publicURL string - sharePrefix string - homeNamespace string - additionalInfoAttribute string - userIdentifierCache *ttlcache.Cache + gatewayAddr string + publicURL string + sharePrefix string + homeNamespace string + additionalInfoTemplate *template.Template + userIdentifierCache *ttlcache.Cache } // we only cache the minimal set of data instead of the full user metadata @@ -73,7 +75,8 @@ func (h *Handler) Init(c *config.Config) error { h.publicURL = c.Config.Host h.sharePrefix = c.SharePrefix h.homeNamespace = c.HomeNamespace - h.additionalInfoAttribute = c.AdditionalInfoAttribute + + h.additionalInfoTemplate, _ = template.New("additionalInfo").Parse(c.AdditionalInfoAttribute) h.userIdentifierCache = ttlcache.NewCache() _ = h.userIdentifierCache.SetTTL(60 * time.Second) @@ -975,8 +978,9 @@ func (h *Handler) mapUserIds(ctx context.Context, c gateway.GatewayAPIClient, s } func (h *Handler) getAdditionalInfoAttribute(u *userIdentifiers) string { - if h.additionalInfoAttribute == "username" { - return u.UserName + b := bytes.Buffer{} + if err := h.additionalInfoTemplate.Execute(&b, u); err != nil { + return "" } - return u.Mail + return b.String() }