|
|
@@ -54,8 +54,9 @@
|
|
|
|
|
|
-define(TAB, ?MODULE).
|
|
|
-define(AUTHN_QSCHEMA, [
|
|
|
- {<<"like_username">>, binary},
|
|
|
- {<<"user_group">>, binary}
|
|
|
+ {<<"like_user_id">>, binary},
|
|
|
+ {<<"user_group">>, binary},
|
|
|
+ {<<"is_superuser">>, atom}
|
|
|
]).
|
|
|
-define(QUERY_FUN, {?MODULE, query}).
|
|
|
|
|
|
@@ -298,9 +299,9 @@ run_fuzzy_filter(_, []) ->
|
|
|
true;
|
|
|
run_fuzzy_filter(
|
|
|
E = #user_info{user_id = {_, UserID}},
|
|
|
- [{username, like, UsernameSubStr} | Fuzzy]
|
|
|
+ [{user_id, like, UserIDSubStr} | Fuzzy]
|
|
|
) ->
|
|
|
- binary:match(UserID, UsernameSubStr) /= nomatch andalso run_fuzzy_filter(E, Fuzzy).
|
|
|
+ binary:match(UserID, UserIDSubStr) /= nomatch andalso run_fuzzy_filter(E, Fuzzy).
|
|
|
|
|
|
%%------------------------------------------------------------------------------
|
|
|
%% Internal functions
|
|
|
@@ -392,17 +393,12 @@ format_user_info(#user_info{user_id = {_, UserID}, is_superuser = IsSuperuser})
|
|
|
#{user_id => UserID, is_superuser => IsSuperuser}.
|
|
|
|
|
|
ms_from_qstring(QString) ->
|
|
|
- [Ms] = lists:foldl(
|
|
|
- fun
|
|
|
- ({user_group, '=:=', UserGroup}, AccIn) ->
|
|
|
- [group_match_spec(UserGroup) | AccIn];
|
|
|
- (_, AccIn) ->
|
|
|
- AccIn
|
|
|
- end,
|
|
|
- [],
|
|
|
- QString
|
|
|
- ),
|
|
|
- Ms.
|
|
|
+ case lists:keytake(user_group, 1, QString) of
|
|
|
+ {value, {user_group, '=:=', UserGroup}, QString2} ->
|
|
|
+ group_match_spec(UserGroup, QString2);
|
|
|
+ _ ->
|
|
|
+ []
|
|
|
+ end.
|
|
|
|
|
|
group_match_spec(UserGroup) ->
|
|
|
ets:fun2ms(
|
|
|
@@ -410,3 +406,17 @@ group_match_spec(UserGroup) ->
|
|
|
User
|
|
|
end
|
|
|
).
|
|
|
+
|
|
|
+group_match_spec(UserGroup, QString) ->
|
|
|
+ case lists:keyfind(is_superuser, 1, QString) of
|
|
|
+ false ->
|
|
|
+ ets:fun2ms(fun(#user_info{user_id = {Group, _}} = User) when Group =:= UserGroup ->
|
|
|
+ User
|
|
|
+ end);
|
|
|
+ {is_superuser, '=:=', Value} ->
|
|
|
+ ets:fun2ms(fun(#user_info{user_id = {Group, _}, is_superuser = IsSuper} = User) when
|
|
|
+ Group =:= UserGroup, IsSuper =:= Value
|
|
|
+ ->
|
|
|
+ User
|
|
|
+ end)
|
|
|
+ end.
|