Fix parsing of acl/access rules inside oauth sections of api_permissions

This should fix problem reported in #1568
This commit is contained in:
Paweł Chmielowski 2017-02-27 20:23:24 +01:00
parent ac025ee6f2
commit b2e16ffb12
1 changed files with 6 additions and 7 deletions

View File

@ -363,7 +363,9 @@ parse_who(Name, Atom, ParseOauth) when is_atom(Atom) ->
parse_who(Name, [Atom], ParseOauth); parse_who(Name, [Atom], ParseOauth);
parse_who(Name, Defs, ParseOauth) when is_list(Defs) -> parse_who(Name, Defs, ParseOauth) when is_list(Defs) ->
lists:map( lists:map(
fun([{access, Val}]) -> fun([Val]) ->
parse_who(Name, [Val], ParseOauth);
({access, Val}) ->
try acl:access_rules_validator(Val) of try acl:access_rules_validator(Val) of
Rule -> Rule ->
{access, Rule} {access, Rule}
@ -377,7 +379,7 @@ parse_who(Name, Defs, ParseOauth) when is_list(Defs) ->
report_error(<<"Invalid access rule '~p' used inside 'who' section for api_permission '~s'">>, report_error(<<"Invalid access rule '~p' used inside 'who' section for api_permission '~s'">>,
[Val, Name]) [Val, Name])
end; end;
([{oauth, OauthList}]) when is_list(OauthList) -> ({oauth, OauthList}) when is_list(OauthList) ->
case ParseOauth of case ParseOauth of
oauth -> oauth ->
Nested = parse_who(Name, lists:flatten(OauthList), scope), Nested = parse_who(Name, lists:flatten(OauthList), scope),
@ -413,7 +415,7 @@ parse_who(Name, Defs, ParseOauth) when is_list(Defs) ->
end; end;
(Atom) when is_atom(Atom) -> (Atom) when is_atom(Atom) ->
{acl, {acl, Atom}}; {acl, {acl, Atom}};
([Other]) -> (Other) ->
try acl:normalize_spec(Other) of try acl:normalize_spec(Other) of
Rule2 -> Rule2 ->
{acl, Rule2} {acl, Rule2}
@ -421,10 +423,7 @@ parse_who(Name, Defs, ParseOauth) when is_list(Defs) ->
_:_ -> _:_ ->
report_error(<<"Invalid value '~p' used inside 'who' section for api_permission '~s'">>, report_error(<<"Invalid value '~p' used inside 'who' section for api_permission '~s'">>,
[Other, Name]) [Other, Name])
end; end
(Invalid) ->
report_error(<<"Invalid value '~p' used inside 'who' section for api_permission '~s'">>,
[Invalid, Name])
end, Defs); end, Defs);
parse_who(Name, Val, _ParseOauth) -> parse_who(Name, Val, _ParseOauth) ->
report_error(<<"Invalid value '~p' used inside 'who' section for api_permission '~s'">>, report_error(<<"Invalid value '~p' used inside 'who' section for api_permission '~s'">>,