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