Commit d20a646ae66c62c660b3b41811182d88c810eabf
1 parent
0f134a87
Exists in
master
• add model to parse scim queries
Showing
1 changed file
with
45 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,45 @@ |
1 | +module ScimRails | |
2 | + class ScimQueryParser | |
3 | + attr_accessor :query_elements | |
4 | + | |
5 | + def initialize(query_string) | |
6 | + self.query_elements = query_string.split(" ") | |
7 | + end | |
8 | + | |
9 | + def attribute | |
10 | + attribute = query_elements.dig(0) | |
11 | + raise ScimRails::ExceptionHandler::InvalidQuery if attribute.blank? | |
12 | + attribute = attribute.to_sym | |
13 | + | |
14 | + mapped_attribute = attribute_mapping(attribute) | |
15 | + raise ScimRails::ExceptionHandler::InvalidQuery if mapped_attribute.blank? | |
16 | + mapped_attribute | |
17 | + end | |
18 | + | |
19 | + def operator | |
20 | + sql_comparison_operator(query_elements.dig(1)) | |
21 | + end | |
22 | + | |
23 | + def parameter | |
24 | + parameter = query_elements.dig(2) | |
25 | + return if parameter.blank? | |
26 | + parameter.gsub(/"/, "") | |
27 | + end | |
28 | + | |
29 | + private | |
30 | + | |
31 | + def attribute_mapping(attribute) | |
32 | + ScimRails.config.queryable_user_attributes[attribute] | |
33 | + end | |
34 | + | |
35 | + def sql_comparison_operator(element) | |
36 | + case element | |
37 | + when "eq" | |
38 | + "=" | |
39 | + else | |
40 | + # TODO: implement additional query filters | |
41 | + raise ScimRails::ExceptionHandler::InvalidQuery | |
42 | + end | |
43 | + end | |
44 | + end | |
45 | +end | ... | ... |