| 844 | } |
| 845 | |
| 846 | func applyIDPSyncMappingDiff[IDType uuid.UUID | string]( |
| 847 | previous map[string][]IDType, |
| 848 | add, remove []codersdk.IDPSyncMapping[IDType], |
| 849 | ) map[string][]IDType { |
| 850 | next := make(map[string][]IDType) |
| 851 | |
| 852 | // Copy existing mapping |
| 853 | for key, ids := range previous { |
| 854 | next[key] = append(next[key], ids...) |
| 855 | } |
| 856 | |
| 857 | // Add unique entries |
| 858 | for _, mapping := range add { |
| 859 | if !slice.Contains(next[mapping.Given], mapping.Gets) { |
| 860 | next[mapping.Given] = append(next[mapping.Given], mapping.Gets) |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | // Remove entries |
| 865 | for _, mapping := range remove { |
| 866 | next[mapping.Given] = slices.DeleteFunc(next[mapping.Given], func(u IDType) bool { |
| 867 | return u == mapping.Gets |
| 868 | }) |
| 869 | } |
| 870 | |
| 871 | return next |
| 872 | } |