Make sure that api_permissions always have "console commands" section
If user didn't override it in config file, default version which allows executing all commands will be added
This commit is contained in:
parent
a31154c035
commit
af5457ba09
|
@ -230,31 +230,34 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
-spec get_definitions(#state{}) -> {#state{}, any()}.
|
-spec get_definitions(#state{}) -> {#state{}, any()}.
|
||||||
get_definitions(#state{definitions = Defs, fragments_generators = Gens} = State) ->
|
get_definitions(#state{definitions = Defs} = State) when Defs /= none ->
|
||||||
DefaultOptions = [{<<"console commands">>,
|
{State, Defs};
|
||||||
{[ejabberd_ctl],
|
get_definitions(#state{definitions = none, fragments_generators = Gens} = State) ->
|
||||||
[{acl, all}],
|
DefaultOptions = [{<<"admin access">>,
|
||||||
{all, none}}},
|
|
||||||
{<<"admin access">>,
|
|
||||||
{[],
|
{[],
|
||||||
[{acl,{acl,admin}},
|
[{acl,{acl,admin}},
|
||||||
{oauth,[<<"ejabberd:admin">>],[{acl,{acl,admin}}]}],
|
{oauth,[<<"ejabberd:admin">>],[{acl,{acl,admin}}]}],
|
||||||
{all, [start, stop]}}}],
|
{all, [start, stop]}}}],
|
||||||
NDefs = case Defs of
|
ApiPerms = ejabberd_config:get_option(api_permissions, fun(A) -> A end,
|
||||||
none ->
|
DefaultOptions),
|
||||||
ApiPerms = ejabberd_config:get_option(api_permissions, fun(A) -> A end, DefaultOptions),
|
AllCommands = ejabberd_commands:get_commands_definition(),
|
||||||
AllCommands = ejabberd_commands:get_commands_definition(),
|
Frags = lists:foldl(
|
||||||
Frags = lists:foldl(
|
fun({_Name, Generator}, Acc) ->
|
||||||
fun({_Name, Generator}, Acc) ->
|
Acc ++ Generator()
|
||||||
Acc ++ Generator()
|
end, [], Gens),
|
||||||
end, [], Gens),
|
NDefs0 = lists:map(
|
||||||
lists:map(
|
fun({Name, {From, Who, {Add, Del}}}) ->
|
||||||
fun({Name, {From, Who, {Add, Del}}}) ->
|
Cmds = filter_commands_with_permissions(AllCommands, Add, Del),
|
||||||
Cmds = filter_commands_with_permissions(AllCommands, Add, Del),
|
{Name, {From, Who, Cmds}}
|
||||||
{Name, {From, Who, Cmds}}
|
end, ApiPerms ++ Frags),
|
||||||
end, ApiPerms ++ Frags);
|
NDefs = case lists:keyfind(<<"console commands">>, 1, NDefs0) of
|
||||||
V ->
|
false ->
|
||||||
V
|
[{<<"console commands">>,
|
||||||
|
{[ejabberd_ctl],
|
||||||
|
[{acl, all}],
|
||||||
|
filter_commands_with_permissions(AllCommands, all, none)}} | NDefs0];
|
||||||
|
_ ->
|
||||||
|
NDefs0
|
||||||
end,
|
end,
|
||||||
{State#state{definitions = NDefs}, NDefs}.
|
{State#state{definitions = NDefs}, NDefs}.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue