Skip to content

Commit

Permalink
As per Denys comments
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed May 27, 2021
1 parent 00ea12c commit 5a6b556
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
8 changes: 4 additions & 4 deletions big_tests/tests/mam_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3046,10 +3046,10 @@ check_user_exist(Config) ->
JID = mongoose_helper:make_jid(AdminU, AdminS),
ok = rpc(mim(), ejabberd_auth, try_register, [JID, AdminP]),
%% admin user already registered
Acc = mongoose_helper:new_mongoose_acc(AdminS),
true = rpc(mim(), mongoose_users, does_user_exist, [Acc, JID]),
false = rpc(mim(), mongoose_users, does_user_exist, [Acc, mongoose_helper:make_jid(<<"fake-user">>, AdminS)]),
false = rpc(mim(), mongoose_users, does_user_exist, [Acc, mongoose_helper:make_jid(AdminU, <<"fake-domain">>)]),
{ok, HostType} = rpc(mim(), mongoose_domain_core, get_host_type, [AdminS]),
true = rpc(mim(), mongoose_users, does_user_exist, [HostType, JID]),
false = rpc(mim(), mongoose_users, does_user_exist, [HostType, mongoose_helper:make_jid(<<"fake-user">>, AdminS)]),
false = rpc(mim(), mongoose_users, does_user_exist, [HostType, mongoose_helper:make_jid(AdminU, <<"fake-domain">>)]),
%% cleanup
ok = rpc(mim(), ejabberd_auth, remove_user, [JID]).

Expand Down
2 changes: 1 addition & 1 deletion src/auth/ejabberd_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ remove_user(#jid{luser = LUser, lserver = LServer}) ->
host_type => HostType,
lserver => LServer,
element => undefined }),
mongoose_hooks:remove_user(HostType, Acc, LServer, LUser),
mongoose_hooks:remove_user(Acc, LServer, LUser),
ok;
Error ->
?LOG_ERROR(#{what => backend_disallows_user_removal,
Expand Down
3 changes: 2 additions & 1 deletion src/event_pusher/mod_event_pusher_push_plugin_defaults.erl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ publish_notification(Acc, _, Payload, Services) ->

-spec should_publish(Acc :: mongoose_acc:t(), To :: jid:jid()) -> boolean().
should_publish(Acc, #jid{} = To) ->
try mongoose_users:does_user_exist(Acc, To) of
HostType = mongoose_acc:host_type(Acc),
try mongoose_users:does_user_exist(HostType, To) of
false ->
false;
true ->
Expand Down
6 changes: 4 additions & 2 deletions src/inbox/mod_inbox.erl
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,11 @@ maybe_process_message(Acc, Host, From, To, Msg, Dir) ->
To :: jid:jid(),
Dir :: outgoing | incoming) -> boolean().
inbox_owner_exists(Acc, From, _To, outgoing) ->
mongoose_users:does_user_exist(Acc, From);
HostType = mongoose_acc:host_type(Acc),
mongoose_users:does_user_exist(HostType, From);
inbox_owner_exists(Acc, _From, To, incoming) ->
mongoose_users:does_user_exist(Acc, To).
HostType = mongoose_acc:host_type(Acc),
mongoose_users:does_user_exist(HostType, To).

maybe_process_acceptable_message(Host, From, To, Msg, Acc, Dir, one2one) ->
process_message(Host, From, To, Msg, Acc, Dir, one2one);
Expand Down
3 changes: 2 additions & 1 deletion src/mam/mod_mam.erl
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ filter_packet(drop) ->
drop;
filter_packet({From, To = #jid{lserver = LServer}, Acc1, Packet}) ->
?LOG_DEBUG(#{what => mam_user_receive_packet, acc => Acc1}),
HostType = mongoose_acc:host_type(Acc1),
{AmpEvent, PacketAfterArchive, Acc3} =
case mongoose_users:does_user_exist(Acc1, To) of
case mongoose_users:does_user_exist(HostType, To) of
false ->
{mam_failed, Packet, Acc1};
true ->
Expand Down
8 changes: 4 additions & 4 deletions src/mongoose_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
register_command/1,
register_subhost/2,
register_user/3,
remove_user/4,
remove_user/3,
resend_offline_messages_hook/3,
rest_user_send_packet/4,
session_cleanup/5,
Expand Down Expand Up @@ -366,13 +366,13 @@ register_user(HostType, LServer, LUser) ->
ejabberd_hooks:run_for_host_type(register_user, HostType, ok, [LUser, LServer]).

%%% @doc The `remove_user' hook is called when a user is removed.
-spec remove_user(HostType, Acc, LServer, LUser) -> Result when
HostType :: mongooseim:host_type(),
-spec remove_user(Acc, LServer, LUser) -> Result when
Acc :: mongoose_acc:t(),
LServer :: jid:lserver(),
LUser :: jid:luser(),
Result :: mongoose_acc:t().
remove_user(HostType, Acc, LServer, LUser) ->
remove_user(Acc, LServer, LUser) ->
HostType = mongoose_acc:host_type(Acc),
ejabberd_hooks:run_for_host_type(remove_user, HostType, Acc, [LUser, LServer]).

-spec resend_offline_messages_hook(HostType, Acc, JID) -> Result when
Expand Down
5 changes: 2 additions & 3 deletions src/mongoose_users.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ stop_ets(HostType) ->
Tab = tbl_name(HostType),
ets:delete(Tab).

-spec does_user_exist(Acc :: mongoose_acc:t(), JID :: jid:jid()) -> boolean().
does_user_exist(Acc, #jid{luser = LUser, lserver = LServer} = JID) ->
HostType = mongoose_acc:host_type(Acc),
-spec does_user_exist(HostType :: mongooseim:host_type(), JID :: jid:jid()) -> boolean().
does_user_exist(HostType, #jid{luser = LUser, lserver = LServer} = JID) ->
case does_cached_user_exist(HostType, LServer, LUser) of
true -> true;
false ->
Expand Down

0 comments on commit 5a6b556

Please sign in to comment.