(r *http.Request, id string, operations []scim.PatchOperation)
| 175 | } |
| 176 | |
| 177 | func (h *testResourceHandler) Patch(r *http.Request, id string, operations []scim.PatchOperation) (scim.Resource, error) { |
| 178 | if err := checkBodyNotEmpty(r); err != nil { |
| 179 | return scim.Resource{}, err |
| 180 | } |
| 181 | |
| 182 | if _, ok := h.data[id]; !ok { |
| 183 | return scim.Resource{}, errors.ScimErrorResourceNotFound(id) |
| 184 | } |
| 185 | |
| 186 | var changed bool // Whether or not changes where made |
| 187 | for _, op := range operations { |
| 188 | // Target is the root node. |
| 189 | if op.Path == nil { |
| 190 | for k, v := range op.Value.(map[string]interface{}) { |
| 191 | if v == nil { |
| 192 | continue |
| 193 | } |
| 194 | |
| 195 | path, _ := filter.ParseAttrPath([]byte(k)) |
| 196 | if subAttrName := path.SubAttributeName(); subAttrName != "" { |
| 197 | if old, ok := h.data[id].attributes[path.AttributeName]; ok { |
| 198 | m := old.(map[string]interface{}) |
| 199 | if sub, ok := m[subAttrName]; ok { |
| 200 | if sub == v { |
| 201 | continue |
| 202 | } |
| 203 | } |
| 204 | changed = true |
| 205 | m[subAttrName] = v |
| 206 | h.data[id].attributes[path.AttributeName] = m |
| 207 | continue |
| 208 | } |
| 209 | changed = true |
| 210 | h.data[id].attributes[path.AttributeName] = map[string]interface{}{ |
| 211 | subAttrName: v, |
| 212 | } |
| 213 | continue |
| 214 | } |
| 215 | old, ok := h.data[id].attributes[k] |
| 216 | if !ok { |
| 217 | changed = true |
| 218 | h.data[id].attributes[k] = v |
| 219 | continue |
| 220 | } |
| 221 | switch v := v.(type) { |
| 222 | case []interface{}: |
| 223 | changed = true |
| 224 | h.data[id].attributes[k] = append(old.([]interface{}), v...) |
| 225 | case map[string]interface{}: |
| 226 | m := old.(map[string]interface{}) |
| 227 | var changed_ bool |
| 228 | for attr, value := range v { |
| 229 | if value == nil { |
| 230 | continue |
| 231 | } |
| 232 | |
| 233 | if v, ok := m[attr]; ok { |
| 234 | if v == nil || v == value { |
nothing calls this directly
no test coverage detected