Skip to content

Commit

Permalink
Make additional info attribute configureable
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Mar 26, 2021
1 parent fb410ea commit 8aa4bec
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
21 changes: 13 additions & 8 deletions internal/http/services/owncloud/ocs/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import (

// Config holds the config options that need to be passed down to all ocs handlers
type Config struct {
Prefix string `mapstructure:"prefix"`
Config data.ConfigData `mapstructure:"config"`
Capabilities data.CapabilitiesData `mapstructure:"capabilities"`
GatewaySvc string `mapstructure:"gatewaysvc"`
DefaultUploadProtocol string `mapstructure:"default_upload_protocol"`
UserAgentChunkingMap map[string]string `mapstructure:"user_agent_chunking_map"`
SharePrefix string `mapstructure:"share_prefix"`
HomeNamespace string `mapstructure:"home_namespace"`
Prefix string `mapstructure:"prefix"`
Config data.ConfigData `mapstructure:"config"`
Capabilities data.CapabilitiesData `mapstructure:"capabilities"`
GatewaySvc string `mapstructure:"gatewaysvc"`
DefaultUploadProtocol string `mapstructure:"default_upload_protocol"`
UserAgentChunkingMap map[string]string `mapstructure:"user_agent_chunking_map"`
SharePrefix string `mapstructure:"share_prefix"`
HomeNamespace string `mapstructure:"home_namespace"`
AdditionalInfoAttribute string `mapstructure:"additional_info_attribute"`
}

// Init sets sane defaults
Expand All @@ -53,5 +54,9 @@ func (c *Config) Init() {
c.HomeNamespace = "/home"
}

if c.AdditionalInfoAttribute == "" {
c.AdditionalInfoAttribute = "mail"
}

c.GatewaySvc = sharedconf.GetGatewaySVC(c.GatewaySvc)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ import (

// Handler implements the ownCloud sharing API
type Handler struct {
gatewayAddr string
gatewayAddr string
additionalInfoAttribute string
}

// Init initializes this and any contained handlers
func (h *Handler) Init(c *config.Config) error {
h.gatewayAddr = c.GatewaySvc
h.additionalInfoAttribute = c.AdditionalInfoAttribute
return nil
}

Expand Down Expand Up @@ -116,7 +118,7 @@ func (h *Handler) userAsMatch(u *userpb.User) *conversions.MatchData {
ShareType: int(conversions.ShareTypeUser),
// api compatibility with oc10: always use the username
ShareWith: u.Username,
ShareWithAdditionalInfo: u.Mail,
ShareWithAdditionalInfo: h.getAdditionalInfoAttribute(u),
},
}
}
Expand All @@ -125,10 +127,16 @@ func (h *Handler) groupAsMatch(g *grouppb.Group) *conversions.MatchData {
return &conversions.MatchData{
Label: g.DisplayName,
Value: &conversions.MatchValueData{
ShareType: int(conversions.ShareTypeGroup),
// api compatibility with oc10
ShareType: int(conversions.ShareTypeGroup),
ShareWith: g.GroupName,
ShareWithAdditionalInfo: g.Mail,
},
}
}

func (h *Handler) getAdditionalInfoAttribute(u *userpb.User) string {
if h.additionalInfoAttribute == "username" {
return u.Username
}
return u.Mail
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ import (

// Handler implements the shares part of the ownCloud sharing API
type Handler struct {
gatewayAddr string
publicURL string
sharePrefix string
homeNamespace string
userIdentifierCache *ttlcache.Cache
gatewayAddr string
publicURL string
sharePrefix string
homeNamespace string
additionalInfoAttribute string
userIdentifierCache *ttlcache.Cache
}

// we only cache the minimal set of data instead of the full user metadata
Expand All @@ -72,6 +73,7 @@ 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.userIdentifierCache = ttlcache.NewCache()
_ = h.userIdentifierCache.SetTTL(60 * time.Second)
Expand Down Expand Up @@ -945,7 +947,7 @@ func (h *Handler) mapUserIds(ctx context.Context, c gateway.GatewayAPIClient, s
s.DisplaynameOwner = owner.DisplayName
}
if s.AdditionalInfoFileOwner == "" {
s.AdditionalInfoFileOwner = owner.Mail
s.AdditionalInfoFileOwner = h.getAdditionalInfoAttribute(owner)
}
}

Expand All @@ -956,7 +958,7 @@ func (h *Handler) mapUserIds(ctx context.Context, c gateway.GatewayAPIClient, s
s.DisplaynameFileOwner = fileOwner.DisplayName
}
if s.AdditionalInfoOwner == "" {
s.AdditionalInfoOwner = fileOwner.Mail
s.AdditionalInfoOwner = h.getAdditionalInfoAttribute(fileOwner)
}
}

Expand All @@ -967,7 +969,14 @@ func (h *Handler) mapUserIds(ctx context.Context, c gateway.GatewayAPIClient, s
s.ShareWithDisplayname = shareWith.DisplayName
}
if s.ShareWithAdditionalInfo == "" {
s.ShareWithAdditionalInfo = shareWith.Mail
s.ShareWithAdditionalInfo = h.getAdditionalInfoAttribute(shareWith)
}
}
}

func (h *Handler) getAdditionalInfoAttribute(u *userIdentifiers) string {
if h.additionalInfoAttribute == "username" {
return u.UserName
}
return u.Mail
}

0 comments on commit 8aa4bec

Please sign in to comment.