25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

prevent orphaned pubsub node (EJAB-1233)

This commit is contained in:
Christophe Romain 2010-05-19 10:42:49 +02:00
parent 5f89f481e4
commit 033bec01e3
3 changed files with 40 additions and 26 deletions

View File

@ -2534,6 +2534,11 @@ set_affiliations(Host, Node, From, EntitiesEls) ->
Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}=N) ->
case lists:member(Owner, Owners) of
true ->
OwnerJID = exmpp_jid:make(Owner),
FilteredEntities = case Owners of
[Owner] -> [E || E <- Entities, element(1, E) =/= OwnerJID];
_ -> Entities
end,
lists:foreach(
fun({JID, Affiliation}) ->
{result, _} = node_call(Type, set_affiliation, [NodeId, JID, Affiliation]),
@ -2554,10 +2559,10 @@ set_affiliations(Host, Node, From, EntitiesEls) ->
_ ->
ok
end
end, Entities),
{result, []};
_ ->
{error, 'forbidden'}
end, FilteredEntities),
{result, []};
_ ->
{error, 'forbidden'}
end
end,
case transaction(Host, Node, Action, sync_dirty) of

View File

@ -2364,14 +2364,19 @@ set_affiliations(Host, Node, From, EntitiesEls) ->
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
case lists:member(Owner, node_owners_call(Type, NodeId)) of
true ->
OwnerJID = exmpp_jid:make(Owner),
FilteredEntities = case Owners of
[Owner] -> [E || E <- Entities, element(1, E) =/= OwnerJID];
_ -> Entities
end,
lists:foreach(
fun({JID, Affiliation}) ->
% TODO, check if nothing missing here about new owners
node_call(Type, set_affiliation, [NodeId, JID, Affiliation])
end, Entities),
{result, []};
_ ->
{error, 'forbidden'}
end, FilteredEntities),
{result, []};
_ ->
{error, 'forbidden'}
end
end,
case transaction(Host, Node, Action, sync_dirty) of

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2010-05-17 22:05:12.000000000 +0200
+++ mod_pubsub_odbc.erl 2010-05-18 17:28:09.000000000 +0200
--- mod_pubsub.erl 2010-05-19 10:34:16.000000000 +0200
+++ mod_pubsub_odbc.erl 2010-05-19 10:40:00.000000000 +0200
@@ -42,7 +42,7 @@
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
%%% XEP-0060 section 12.18.
@ -545,7 +545,7 @@
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} ->
@@ -2531,29 +2361,13 @@
@@ -2531,8 +2361,8 @@
error ->
{error, 'bad-request'};
_ ->
@ -554,6 +554,10 @@
+ Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
+ case lists:member(Owner, node_owners_call(Type, NodeId)) of
true ->
OwnerJID = exmpp_jid:make(Owner),
FilteredEntities = case Owners of
@@ -2541,24 +2371,8 @@
end,
lists:foreach(
fun({JID, Affiliation}) ->
- {result, _} = node_call(Type, set_affiliation, [NodeId, JID, Affiliation]),
@ -576,10 +580,10 @@
- end
+ % TODO, check if nothing missing here about new owners
+ node_call(Type, set_affiliation, [NodeId, JID, Affiliation])
end, Entities),
{result, []};
_ ->
@@ -2608,11 +2422,11 @@
end, FilteredEntities),
{result, []};
_ ->
@@ -2613,11 +2427,11 @@
end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -593,7 +597,7 @@
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
?XMLATTR('subid', SubID) | nodeAttr(Node)],
@@ -2639,7 +2453,7 @@
@@ -2644,7 +2458,7 @@
end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
@ -602,7 +606,7 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -2669,7 +2483,7 @@
@@ -2674,7 +2488,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error('bad-request', "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) ->
@ -611,7 +615,7 @@
{error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")};
{result, _} ->
@@ -2842,8 +2656,8 @@
@@ -2847,8 +2661,8 @@
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
ejabberd_router:route(service_jid(Host), JID, Stanza)
end,
@ -622,7 +626,7 @@
true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3184,7 +2998,7 @@
@@ -3189,7 +3003,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end,
@ -631,7 +635,7 @@
{result, CollSubs} -> CollSubs;
_ -> []
end.
@@ -3198,9 +3012,9 @@
@@ -3203,9 +3017,9 @@
get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
@ -643,7 +647,7 @@
_ -> Acc
end;
(_, Acc) ->
@@ -3422,6 +3236,30 @@
@@ -3427,6 +3241,30 @@
Result
end.
@ -674,7 +678,7 @@
%% @spec (Host, Options) -> MaxItems
%% Host = host()
%% Options = [Option]
@@ -3824,7 +3662,13 @@
@@ -3829,7 +3667,13 @@
tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end,
@ -689,7 +693,7 @@
%% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) ->
@@ -3844,13 +3688,13 @@
@@ -3849,13 +3693,13 @@
node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -705,7 +709,7 @@
case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) ->
case Action(N) of
@@ -3863,8 +3707,15 @@
@@ -3868,8 +3712,15 @@
end
end, Trans).
@ -723,7 +727,7 @@
{result, Result} -> {result, Result};
{error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result};
@@ -3872,6 +3723,15 @@
@@ -3877,6 +3728,15 @@
{aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, 'internal-server-error'};
@ -739,7 +743,7 @@
{'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, 'internal-server-error'};
@@ -3880,6 +3740,16 @@
@@ -3885,6 +3745,16 @@
{error, 'internal-server-error'}
end.