@@ -19,7 +19,6 @@ import (
19
19
"fmt"
20
20
"reflect"
21
21
"sort"
22
- "strings"
23
22
"time"
24
23
25
24
"github.com/rokwire/logging-library-go/v2/errors"
@@ -89,37 +88,22 @@ type Privacy struct {
89
88
}
90
89
91
90
// GetFieldVisibility determines the privacy setting for the account data at path
92
- func (p * Privacy ) GetFieldVisibility (path string , visibilityMap map [string ]interface {}) (string , error ) {
93
- if len (visibilityMap ) == 0 {
94
- if len (p .FieldVisibility ) == 0 {
95
- return VisibilityPrivate , nil
96
- }
97
- visibilityMap = p .FieldVisibility
98
- }
99
-
100
- splitPath := strings .Split (path , "." )
101
- var err error
102
- visibilityEntry , ok := visibilityMap [splitPath [0 ]]
103
- if ! ok {
91
+ func (p * Privacy ) GetFieldVisibility (path string ) (string , error ) {
92
+ visibilityEntry := utils .GetMapEntryFromPath (p .FieldVisibility , path )
93
+ if visibilityEntry == nil {
104
94
return VisibilityPrivate , nil
105
95
}
96
+
106
97
visibility , ok := visibilityEntry .(string )
107
98
if ! ok {
108
- insideMap , ok := visibilityEntry .(map [string ]interface {})
109
- if ! ok {
110
- return "" , errors .ErrorData (logutils .StatusInvalid , "privacy field visibility" , nil )
111
- }
112
- visibility , err = p .GetFieldVisibility (strings .Join (splitPath [1 :], "." ), insideMap )
113
- if err != nil {
114
- return "" , errors .WrapErrorAction (logutils .ActionGet , "account field visibility" , & logutils.FieldArgs {"path" : path }, err )
115
- }
99
+ return "" , errors .ErrorData (logutils .StatusInvalid , "privacy field visibility" , & logutils.FieldArgs {"path" : path })
116
100
}
117
101
return visibility , nil
118
102
}
119
103
120
104
// IsFieldVisible determines whether the account data at path should be visible to the requesting user
121
105
func (p * Privacy ) IsFieldVisible (path string , isConnection bool ) (bool , error ) {
122
- visibility , err := p .GetFieldVisibility (path , nil )
106
+ visibility , err := p .GetFieldVisibility (path )
123
107
if err != nil {
124
108
return false , errors .WrapErrorAction (logutils .ActionGet , "account field visibility" , & logutils.FieldArgs {"path" : path }, err )
125
109
}
@@ -781,7 +765,7 @@ func (p Profile) Merge(src Profile) Profile {
781
765
}
782
766
783
767
// ProfileFromMap parses a map and converts it into a Profile struct
784
- func ProfileFromMap (profileMap map [string ]interface {}) Profile {
768
+ func ProfileFromMap (profileMap map [string ]interface {}, profileFields map [ string ] string ) Profile {
785
769
profile := Profile {UnstructuredProperties : make (map [string ]interface {})}
786
770
for key , val := range profileMap {
787
771
if key == "first_name" {
@@ -828,6 +812,12 @@ func ProfileFromMap(profileMap map[string]interface{}) Profile {
828
812
profile .UnstructuredProperties [key ] = val
829
813
}
830
814
}
815
+
816
+ for path , profileKey := range profileFields {
817
+ if value := utils .GetMapEntryFromPath (profileMap , path ); value != nil {
818
+ profile .UnstructuredProperties [profileKey ] = value
819
+ }
820
+ }
831
821
return profile
832
822
}
833
823
0 commit comments