25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Simplify code for command policy group expansion

This commit is contained in:
Mickael Remond 2016-07-25 18:28:05 +02:00
parent d7ad99f147
commit c183092aa4
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3

View File

@ -496,7 +496,7 @@ execute_command(AccessCommands, Auth, Name, Arguments) ->
%% Can return the following exceptions: %% Can return the following exceptions:
%% command_unknown | account_unprivileged | invalid_account_data | no_auth_provided | access_rules_unauthorized %% command_unknown | account_unprivileged | invalid_account_data | no_auth_provided | access_rules_unauthorized
execute_command(AccessCommands1, Auth1, Name, Arguments, Version) -> execute_command(AccessCommands1, Auth1, Name, Arguments, Version) ->
execute_command(AccessCommands1, Auth1, Name, Arguments, Version, #{}). execute_command(AccessCommands1, Auth1, Name, Arguments, Version, #{}).
execute_command(AccessCommands1, Auth1, Name, Arguments, Version, CallerInfo) -> execute_command(AccessCommands1, Auth1, Name, Arguments, Version, CallerInfo) ->
Auth = case is_admin(Name, Auth1, CallerInfo) of Auth = case is_admin(Name, Auth1, CallerInfo) of
@ -506,6 +506,7 @@ execute_command(AccessCommands1, Auth1, Name, Arguments, Version, CallerInfo) ->
TokenJID = oauth_token_user(Auth1), TokenJID = oauth_token_user(Auth1),
Command = get_command_definition(Name, Version), Command = get_command_definition(Name, Version),
AccessCommands = get_all_access_commands(AccessCommands1), AccessCommands = get_all_access_commands(AccessCommands1),
case check_access_commands(AccessCommands, Auth, Name, Command, Arguments, CallerInfo) of case check_access_commands(AccessCommands, Auth, Name, Command, Arguments, CallerInfo) of
ok -> execute_check_policy(Auth, TokenJID, Command, Arguments) ok -> execute_check_policy(Auth, TokenJID, Command, Arguments)
end. end.
@ -766,19 +767,15 @@ get_commands(Version) ->
end, [], Opts), end, [], Opts),
Cmds. Cmds.
%% This is used to allow mixing command policy (like open, user, admin, restricted), with command entry
expand_commands(L, OpenCmds, UserCmds, AdminCmds, RestrictedCmds) when is_list(L) -> expand_commands(L, OpenCmds, UserCmds, AdminCmds, RestrictedCmds) when is_list(L) ->
lists:foldl(fun(El, Acc) -> lists:foldl(fun(open, Acc) -> OpenCmds ++ Acc;
expand_commands(El, OpenCmds, UserCmds, AdminCmds, RestrictedCmds) ++ Acc (user, Acc) -> UserCmds ++ Acc;
end, [], L); (admin, Acc) -> AdminCmds ++ Acc;
expand_commands(El, OpenCmds, UserCmds, AdminCmds, RestrictedCmds) -> (restricted, Acc) -> RestrictedCmds ++ Acc;
case El of (Command, Acc) when is_atom(Command) ->
open -> OpenCmds; [Command, Acc]
restricted -> RestrictedCmds; end, [], L).
admin -> AdminCmds;
user -> UserCmds;
_ -> [El]
end.
oauth_token_user(noauth) -> oauth_token_user(noauth) ->
undefined; undefined;