]> granicus.if.org Git - ejabberd/commitdiff
fix manage subscriptions owner's usecase
authorChristophe Romain <christophe.romain@process-one.net>
Mon, 24 Aug 2009 22:40:40 +0000 (22:40 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Mon, 24 Aug 2009 22:40:40 +0000 (22:40 +0000)
SVN Revision: 2528

src/mod_pubsub/mod_pubsub.erl
src/mod_pubsub/node_hometree.erl

index 7135bdb374994523d95f57039e7577482a51d217..6fea31d0d78607aa2fb51aa0c165ab521185fb2b 100644 (file)
@@ -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
index 6484fbe0aa68acfd064bb11a357a40d812e1e563..cb7373677cf8d44460e5e04cf35c8c5407587947 100644 (file)
@@ -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),