Skip to content

Commit

Permalink
Use templates
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Mar 29, 2021
1 parent f38dd24 commit 46473dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package shares

import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
Expand All @@ -28,6 +29,7 @@ import (
"path"
"strconv"
"strings"
"text/template"
"time"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
}

0 comments on commit 46473dc

Please sign in to comment.