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

fix owners cache and fix unsubscribe permissions (EJAB-840)

SVN Revision: 1800
This commit is contained in:
Christophe Romain 2009-01-11 02:05:41 +00:00
parent c77f7e727b
commit 89be1c2ede
3 changed files with 53 additions and 22 deletions

View File

@ -1,3 +1,9 @@
2009-01-11 Christophe Romain <christophe.romain@process-one.net>
* src/mod_pubsub/mod_pubsub.erl: fix owners cache and fix unsubscribe
permissions (thanks to Andy Skelton)(EJAB-840)
* src/mod_pubsub/node_default.erl: Likewise
2009-01-10 Pablo Polvorin <pablo.polvorin@process-one.net> 2009-01-10 Pablo Polvorin <pablo.polvorin@process-one.net>
* src/mod_vcard_odbc.erl: Fix bug in user search. * src/mod_vcard_odbc.erl: Fix bug in user search.

View File

@ -2033,8 +2033,26 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
Action = fun(#pubsub_node{type = Type, owners = Owners}) -> Action = fun(#pubsub_node{type = Type, owners = Owners}) ->
case lists:member(Owner, Owners) of case lists:member(Owner, Owners) of
true -> true ->
lists:foreach(fun({JID, Subscription}) -> lists:foreach(
node_call(Type, set_subscription, [Host, Node, JID, Subscription]) fun({JID, Affiliation}) ->
node_call(Type, set_affiliation, [Host, Node, JID, Affiliation]),
case Affiliation of
owner ->
NewOwner = jlib:short_prepd_bare_jid(JID),
NewOwners = [NewOwner|Owners],
tree_call(Host, set_node, [N#pubsub_node{owners = NewOwners}]);
none ->
NewOwner = jlib:short_prepd_bare_jid(JID),
case lists:member(OldOwner, Owners) of
true ->
NewOwners = Owners--[OldOwner],
tree_call(Host, set_node, [N#pubsub_node{owners = NewOwners}]);
_ ->
ok
end;
_ ->
ok
end
end, Entities), end, Entities),
{result, []}; {result, []};
_ -> _ ->

View File

@ -288,7 +288,6 @@ subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
_ -> get_state(Host, Node, SubKey) _ -> get_state(Host, Node, SubKey)
end, end,
Affiliation = GenState#pubsub_state.affiliation, Affiliation = GenState#pubsub_state.affiliation,
Subscription = SubState#pubsub_state.subscription,
Whitelisted = lists:member(Affiliation, [member, publisher, owner]), Whitelisted = lists:member(Affiliation, [member, publisher, owner]),
if if
not Authorized -> not Authorized ->
@ -297,7 +296,7 @@ subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
Affiliation == outcast -> Affiliation == outcast ->
%% Requesting entity is blocked %% Requesting entity is blocked
{error, 'forbidden'}; {error, 'forbidden'};
Subscription == pending -> SubState#pubsub_state.subscription == pending ->
%% Requesting entity has pending subscription %% Requesting entity has pending subscription
{error, ?ERR_EXTENDED('not-authorized', "pending-subscription")}; {error, ?ERR_EXTENDED('not-authorized', "pending-subscription")};
(AccessModel == presence) and (not PresenceSubscription) -> (AccessModel == presence) and (not PresenceSubscription) ->
@ -358,8 +357,6 @@ unsubscribe_node(Host, Node, Sender, Subscriber, _SubId) ->
GenKey -> GenState; GenKey -> GenState;
_ -> get_state(Host, Node, SubKey) _ -> get_state(Host, Node, SubKey)
end, end,
Affiliation = GenState#pubsub_state.affiliation,
Subscription = SubState#pubsub_state.subscription,
if if
%% Entity did not specify SubID %% Entity did not specify SubID
%%SubID == "", ?? -> %%SubID == "", ?? ->
@ -368,10 +365,10 @@ unsubscribe_node(Host, Node, Sender, Subscriber, _SubId) ->
%%InvalidSubID -> %%InvalidSubID ->
%% {error, ?ERR_EXTENDED('not-acceptable', "invalid-subid")}; %% {error, ?ERR_EXTENDED('not-acceptable', "invalid-subid")};
%% Requesting entity is not a subscriber %% Requesting entity is not a subscriber
Subscription == none -> SubState#pubsub_state.subscription == none ->
{error, ?ERR_EXTENDED('unexpected-request', "not-subscribed")}; {error, ?ERR_EXTENDED('unexpected-request', "not-subscribed")};
%% Requesting entity is prohibited from unsubscribing entity %% Requesting entity is prohibited from unsubscribing entity
(not Authorized) and (Affiliation =/= owner) -> not Authorized ->
{error, 'forbidden'}; {error, 'forbidden'};
%% Was just subscriber, remove the record %% Was just subscriber, remove the record
SubState#pubsub_state.affiliation == none -> SubState#pubsub_state.affiliation == none ->
@ -577,7 +574,12 @@ get_affiliation(Host, Node, Owner) ->
set_affiliation(Host, Node, Owner, Affiliation) -> set_affiliation(Host, Node, Owner, Affiliation) ->
GenKey = jlib:short_prepd_bare_jid(Owner), GenKey = jlib:short_prepd_bare_jid(Owner),
GenState = get_state(Host, Node, GenKey), GenState = get_state(Host, Node, GenKey),
set_state(GenState#pubsub_state{affiliation = Affiliation}), case {Affiliation, GenState#pubsub_state.subscription} of
{none, none} ->
del_state(GenState#pubsub_state.stateid);
_ ->
set_state(GenState#pubsub_state{affiliation = Affiliation})
end,
ok. ok.
%% @spec (Host, Owner) -> [{Node,Subscription}] %% @spec (Host, Owner) -> [{Node,Subscription}]
@ -614,14 +616,19 @@ get_node_subscriptions(Host, Node) ->
{result, lists:map(Tr, States)}. {result, lists:map(Tr, States)}.
get_subscription(Host, Node, Owner) -> get_subscription(Host, Node, Owner) ->
GenKey = jlib:short_prepd_bare_jid(Owner), SubKey = jlib:short_prepd_jid(Owner),
GenState = get_state(Host, Node, GenKey), SubState = get_state(Host, Node, SubKey),
{result, GenState#pubsub_state.subscription}. {result, SubState#pubsub_state.subscription}.
set_subscription(Host, Node, Owner, Subscription) -> set_subscription(Host, Node, Owner, Subscription) ->
GenKey = jlib:short_prepd_bare_jid(Owner), SubKey = jlib:short_prepd_jid(Owner),
GenState = get_state(Host, Node, GenKey), SubState = get_state(Host, Node, SubKey),
set_state(GenState#pubsub_state{subscription = Subscription}), case {Subscription, SubState#pubsub_state.affiliation} of
{none, none} ->
del_state(SubState#pubsub_state.stateid);
_ ->
set_state(SubState#pubsub_state{subscription = Subscription})
end,
ok. ok.
%% @spec (Host, Node) -> [States] | [] %% @spec (Host, Node) -> [States] | []