mod_http_upload: Add "rm_on_unregister" option

The new "rm_on_unregister" option allows admins to specify whether files
uploaded by a user should be removed when that user is unregistered.
This commit is contained in:
Holger Weiss 2015-08-23 17:22:32 +02:00
parent b9ece5c953
commit f4950cdc83
2 changed files with 29 additions and 9 deletions

View File

@ -132,3 +132,9 @@ The configurable mod_http_upload options are:
In any other case, a 'service-unavailable' error stanza is sent to the
client.
- rm_on_unregister (default: 'true')
This option specifies whether files uploaded by a user should be removed
when that user is unregistered. It must be set to 'false' if this is not
desired.

View File

@ -100,10 +100,16 @@ start_link(ServerHost, ProcHost, Opts) ->
-spec start(binary(), gen_mod:opts()) -> {ok, _} | {ok, _, _} | {error, _}.
start(ServerHost, Opts) ->
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE,
remove_user, 50),
ejabberd_hooks:add(anonymous_purge_hook, ServerHost, ?MODULE,
remove_user, 50),
case gen_mod:get_opt(rm_on_unregister, Opts,
fun(B) when is_boolean(B) -> B end,
true) of
true ->
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE,
remove_user, 50),
ejabberd_hooks:add(anonymous_purge_hook, ServerHost, ?MODULE,
remove_user, 50);
false -> ok
end,
PutURL = gen_mod:get_opt(put_url, Opts,
fun(<<"http://", _/binary>> = URL) -> URL;
(<<"https://", _/binary>> = URL) -> URL;
@ -125,10 +131,16 @@ start(ServerHost, Opts) ->
-spec stop(binary()) -> ok.
stop(ServerHost) ->
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE,
remove_user, 50),
ejabberd_hooks:delete(anonymous_purge_hook, ServerHost, ?MODULE,
remove_user, 50),
case gen_mod:get_module_opt(ServerHost, ?MODULE, rm_on_unregister,
fun(B) when is_boolean(B) -> B end,
true) of
true ->
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE,
remove_user, 50),
ejabberd_hooks:delete(anonymous_purge_hook, ServerHost, ?MODULE,
remove_user, 50);
false -> ok
end,
Proc = gen_mod:get_module_proc(ServerHost, ?PROCNAME),
ok = supervisor:terminate_child(ejabberd_sup, Proc),
ok = supervisor:delete_child(ejabberd_sup, Proc).
@ -165,9 +177,11 @@ mod_opt_type(service_url) ->
fun(<<"http://", _/binary>> = URL) -> URL;
(<<"https://", _/binary>> = URL) -> URL
end;
mod_opt_type(rm_on_unregister) ->
fun(B) when is_boolean(B) -> B end;
mod_opt_type(_) ->
[host, name, access, max_size, secret_length, jid_in_url, docroot,
put_url, get_url, service_url].
put_url, get_url, service_url, rm_on_unregister].
%%--------------------------------------------------------------------
%% gen_server callbacks.