mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
fix manage subscriptions owner's usecase
SVN Revision: 2528
This commit is contained in:
parent
1b81a2e3d6
commit
ca403c25e7
@ -2669,16 +2669,23 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
|
||||
{error, ?ERR_BAD_REQUEST};
|
||||
_ ->
|
||||
Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}) ->
|
||||
case lists:member(Owner, Owners) of
|
||||
true ->
|
||||
lists:foreach(fun({JID, Subscription, SubId}) ->
|
||||
node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId])
|
||||
end, Entities),
|
||||
{result, []};
|
||||
_ ->
|
||||
{error, ?ERR_FORBIDDEN}
|
||||
end
|
||||
end,
|
||||
case lists:member(Owner, Owners) of
|
||||
true ->
|
||||
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
||||
|
||||
case node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId]) of
|
||||
{error, Err} -> [{error, Err} | Acc];
|
||||
_ -> Acc
|
||||
end
|
||||
end, [], Entities),
|
||||
case Result of
|
||||
[] -> {result, []};
|
||||
_ -> {error, ?ERR_NOT_ACCEPTABLE}
|
||||
end;
|
||||
_ ->
|
||||
{error, ?ERR_FORBIDDEN}
|
||||
end
|
||||
end,
|
||||
case transaction(Host, Node, Action, sync_dirty) of
|
||||
{result, {_, Result}} -> {result, Result};
|
||||
Other -> Other
|
||||
|
@ -701,7 +701,10 @@ set_subscriptions(NodeId, Owner, Subscription, SubId) ->
|
||||
SubState = get_state(NodeId, SubKey),
|
||||
case {SubId, SubState#pubsub_state.subscriptions} of
|
||||
{_, []} ->
|
||||
{error, ?ERR_ITEM_NOT_FOUND};
|
||||
case Subscription of
|
||||
none -> ok;
|
||||
_ -> new_subscription(NodeId, Owner, Subscription, SubState)
|
||||
end;
|
||||
{"", [{_, SID}]} ->
|
||||
case Subscription of
|
||||
none -> unsub_with_subid(NodeId, SID, SubState);
|
||||
@ -726,6 +729,12 @@ replace_subscription(_, [], Acc) ->
|
||||
replace_subscription({Sub, SubId}, [{_, SubID} | T], Acc) ->
|
||||
replace_subscription({Sub, SubId}, T, [{Sub, SubID} | Acc]).
|
||||
|
||||
new_subscription(NodeId, Owner, Subscription, SubState) ->
|
||||
SubId = pubsub_subscription:add_subscription(Owner, NodeId, []),
|
||||
Subscriptions = SubState#pubsub_state.subscriptions,
|
||||
set_state(SubState#pubsub_state{subscriptions = [{Subscription, SubId} | Subscriptions]}),
|
||||
{Subscription, SubId}.
|
||||
|
||||
unsub_with_subid(NodeId, SubId, SubState) ->
|
||||
pubsub_subscription:delete_subscription(SubState#pubsub_state.stateid,
|
||||
NodeId, SubId),
|
||||
|
Loading…
Reference in New Issue
Block a user