From 8aa4bec2a3c14cca2c384d48771ed1bb359eea75 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Fri, 26 Mar 2021 14:17:32 +0100 Subject: [PATCH] Make additional info attribute configureable --- .../services/owncloud/ocs/config/config.go | 21 ++++++++++------ .../handlers/apps/sharing/sharees/sharees.go | 16 +++++++++--- .../handlers/apps/sharing/shares/shares.go | 25 +++++++++++++------ 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/internal/http/services/owncloud/ocs/config/config.go b/internal/http/services/owncloud/ocs/config/config.go index 3cb402e2694..521054e7320 100644 --- a/internal/http/services/owncloud/ocs/config/config.go +++ b/internal/http/services/owncloud/ocs/config/config.go @@ -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 @@ -53,5 +54,9 @@ func (c *Config) Init() { c.HomeNamespace = "/home" } + if c.AdditionalInfoAttribute == "" { + c.AdditionalInfoAttribute = "mail" + } + c.GatewaySvc = sharedconf.GetGatewaySVC(c.GatewaySvc) } 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 5bb51e7b08a..d81f1fb918e 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 @@ -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 } @@ -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), }, } } @@ -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 +} 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 028c3e91723..88815672837 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 @@ -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 @@ -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) @@ -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) } } @@ -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) } } @@ -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 +}