Provide meaningful error when adding non-local users to shared roster (#3000)

This commit is contained in:
Badlop 2019-08-22 17:12:52 +02:00
parent a51aa2bc44
commit 12c4dfd955
1 changed files with 21 additions and 4 deletions

View File

@ -542,8 +542,16 @@ is_user_in_group(US, Group, Host) ->
true true
end. end.
%% @spec (Host::string(), {User::string(), Server::string()}, Group::string()) -> {atomic, ok} %% @spec (Host::string(), {User::string(), Server::string()}, Group::string()) -> {atomic, ok} | error
add_user_to_group(Host, US, Group) -> add_user_to_group(Host, US, Group) ->
{_LUser, LServer} = US,
case lists:member(LServer, ejabberd_config:get_myhosts()) of
true -> add_user_to_group2(Host, US, Group);
false ->
?INFO_MSG("Attempted adding to shared roster user of inexistent vhost ~s", [LServer]),
error
end.
add_user_to_group2(Host, US, Group) ->
{LUser, LServer} = US, {LUser, LServer} = US,
case ejabberd_regexp:run(LUser, <<"^@.+@\$">>) of case ejabberd_regexp:run(LUser, <<"^@.+@\$">>) of
match -> match ->
@ -871,6 +879,12 @@ shared_roster_group(Host, Group, Query, Lang) ->
[?XC(<<"h2">>, <<(translate:translate(Lang, ?T("Group ")))/binary, Group/binary>>)] ++ [?XC(<<"h2">>, <<(translate:translate(Lang, ?T("Group ")))/binary, Group/binary>>)] ++
case Res of case Res of
ok -> [?XREST(?T("Submitted"))]; ok -> [?XREST(?T("Submitted"))];
{error_jids, NonAddedList1} ->
NonAddedList2 = [jid:encode({U,S,<<>>}) || {U,S} <- NonAddedList1],
NonAddedList3 = str:join(NonAddedList2, <<", ">>),
NonAddedText1 = translate:translate(Lang, ?T("Members not added (inexistent vhost): ")),
NonAddedText2 = str:concat(NonAddedText1, NonAddedList3),
[?XRES(NonAddedText2)];
error -> [?XREST(?T("Bad format"))]; error -> [?XREST(?T("Bad format"))];
nothing -> [] nothing -> []
end end
@ -951,12 +965,15 @@ shared_roster_group_parse_query(Host, Group, Query) ->
Group) Group)
end, end,
RemovedMembers), RemovedMembers),
lists:foreach(fun (US) -> NonAddedMembers = lists:filter(fun (US) ->
mod_shared_roster:add_user_to_group(Host, US, error == mod_shared_roster:add_user_to_group(Host, US,
Group) Group)
end, end,
AddedMembers), AddedMembers),
ok case NonAddedMembers of
[] -> ok;
_ -> {error_jids, NonAddedMembers}
end
end; end;
_ -> nothing _ -> nothing
end. end.