From 1642744fd85876b5c9e965d40940fd4f9b9a0664 Mon Sep 17 00:00:00 2001 From: Rajat Bajaj Date: Tue, 25 Mar 2025 16:09:51 +0530 Subject: [PATCH] Updated SetScope implementation in Options for Facebook and Apple Connection --- management/connection.go | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/management/connection.go b/management/connection.go index 153c5973..c4481f61 100644 --- a/management/connection.go +++ b/management/connection.go @@ -771,12 +771,27 @@ type ConnectionOptionsFacebook struct { // Scopes returns the scopes for ConnectionOptionsFacebook. func (c *ConnectionOptionsFacebook) Scopes() []string { - return tag.Scopes(c) + return strings.Fields(c.GetScope()) } // SetScopes sets the scopes for ConnectionOptionsFacebook. func (c *ConnectionOptionsFacebook) SetScopes(enable bool, scopes ...string) { - tag.SetScopes(c, enable, scopes...) + scopeMap := make(map[string]bool) + for _, scope := range c.Scopes() { + scopeMap[scope] = true + } + for _, scope := range scopes { + scopeMap[scope] = enable + } + scopeSlice := make([]string, 0, len(scopeMap)) + for scope, enabled := range scopeMap { + if enabled { + scopeSlice = append(scopeSlice, scope) + } + } + sort.Strings(scopeSlice) + scope := strings.Join(scopeSlice, " ") + c.Scope = &scope } // ConnectionOptionsApple is used to configure an Apple Connection. @@ -799,12 +814,27 @@ type ConnectionOptionsApple struct { // Scopes returns the scopes for ConnectionOptionsApple. func (c *ConnectionOptionsApple) Scopes() []string { - return tag.Scopes(c) + return strings.Fields(c.GetScope()) } // SetScopes sets the scopes for ConnectionOptionsApple. func (c *ConnectionOptionsApple) SetScopes(enable bool, scopes ...string) { - tag.SetScopes(c, enable, scopes...) + scopeMap := make(map[string]bool) + for _, scope := range c.Scopes() { + scopeMap[scope] = true + } + for _, scope := range scopes { + scopeMap[scope] = enable + } + scopeSlice := make([]string, 0, len(scopeMap)) + for scope, enabled := range scopeMap { + if enabled { + scopeSlice = append(scopeSlice, scope) + } + } + sort.Strings(scopeSlice) + scope := strings.Join(scopeSlice, " ") + c.Scope = &scope } // ConnectionOptionsLinkedin is used to configure a Linkedin Connection.