File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change 58
58
WHERE
59
59
user_id = $7 AND login_type = $8 RETURNING * ;
60
60
61
-
62
61
-- name: OIDCClaimFields :many
63
62
-- OIDCClaimFields returns a list of distinct keys in the the merged_claims fields.
64
63
-- This query is used to generate the list of available sync fields for idp sync settings.
78
77
ELSE true
79
78
END
80
79
;
80
+
81
+ -- name: OIDCClaimFieldValues :many
82
+ SELECT
83
+ -- DISTINCT to remove duplicates
84
+ DISTINCT jsonb_array_elements_text(CASE
85
+ -- When the type is an array, filter out any non-string elements.
86
+ -- This is to keep the return type consistent.
87
+ WHEN jsonb_typeof(claims- > ' merged_claims' - > ' groups' ) = ' array' THEN
88
+ (
89
+ SELECT
90
+ jsonb_agg(element)
91
+ FROM
92
+ jsonb_array_elements(claims- > ' merged_claims' - > @claim_field) AS element
93
+ WHERE
94
+ -- Filtering out non-string elements
95
+ jsonb_typeof(element) = ' string'
96
+ )
97
+ -- Some IDPs return a single string instead of an array of strings.
98
+ WHEN jsonb_typeof(claims- > ' merged_claims' - > ' groups' ) = ' string' THEN
99
+ jsonb_build_array(claims- > ' merged_claims' - > @claim_field)
100
+ END)::text
101
+ FROM
102
+ user_links
103
+ WHERE
104
+ -- IDP sync only supports string and array (of string) types
105
+ jsonb_typeof(claims- > ' merged_claims' - > @claim_field) = ANY(ARRAY[' string' , ' array' ])
106
+ AND login_type = ' oidc'
107
+ AND CASE WHEN @organization_id :: uuid != ' 00000000-0000-0000-0000-000000000000' ::uuid THEN
108
+ user_links .user_id = ANY(SELECT organization_members .user_id FROM organization_members WHERE organization_id = @organization_id)
109
+ ELSE true
110
+ END
111
+ ;
You can’t perform that action at this time.
0 commit comments