]> granicus.if.org Git - ejabberd/commitdiff
PubSub: Added access-whitelist and member-affiliation features (EJAB-780)
authorChristophe Romain <christophe.romain@process-one.net>
Sat, 3 Jan 2009 00:55:05 +0000 (00:55 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Sat, 3 Jan 2009 00:55:05 +0000 (00:55 +0000)
SVN Revision: 1768

ChangeLog
src/mod_pubsub/mod_pubsub.erl
src/mod_pubsub/node_default.erl

index 0440b6a297e3311b6f26efc2fdc4066b91b3f458..de1a0384e3fe29032d62a03cc25fa21c894b28af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,9 @@
        delete-nodes for delete item use case (fix from erroneous definition
        in XEP-0060)
 
+       * src/mod_pubsub/mod_pubsub.erl: Added "access-whitelist" and
+       "member-affiliation" features (thanks to Andy Skelton)(EJAB-780)
+
 2008-12-29  Alexey Shchepin  <alexey@process-one.net>
 
        * src/ejabberd_c2s.erl: Bugfix in "from" attribute checking
index ceadbd5e641b87cf55ae31da88135f50a40b5e59..cff4daa9ddffbff1b31b27783bfb127ed1bce780 100644 (file)
@@ -2066,6 +2066,7 @@ get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, A
 %% @doc <p>Convert an affiliation type from string to atom.</p>
 string_to_affiliation("owner") -> owner;
 string_to_affiliation("publisher") -> publisher;
+string_to_affiliation("member") -> member;
 string_to_affiliation("outcast") -> outcast;
 string_to_affiliation("none") -> none;
 string_to_affiliation(_) -> false.
@@ -2086,6 +2087,7 @@ string_to_subscription(_) -> false.
 %% @doc <p>Convert an affiliation type from atom to string.</p>
 affiliation_to_string(owner) -> "owner";
 affiliation_to_string(publisher) -> "publisher";
+affiliation_to_string(member) -> "member";
 affiliation_to_string(outcast) -> "outcast";
 affiliation_to_string(_) -> "none".
 
@@ -2666,7 +2668,7 @@ features() ->
         "access-open",   % OPTIONAL this relates to access_model option in node_default
         "access-presence",   % OPTIONAL this relates to access_model option in node_pep
         %TODO "access-roster",   % OPTIONAL
-        %TODO "access-whitelist",   % OPTIONAL
+        "access-whitelist",   % OPTIONAL
         % see plugin "auto-create",   % OPTIONAL
         % see plugin "auto-subscribe",   % RECOMMENDED
         "collections",   % RECOMMENDED
@@ -2683,7 +2685,7 @@ features() ->
         %TODO "cache-last-item",
         %TODO "leased-subscription",   % OPTIONAL
         % see plugin "manage-subscriptions",   % OPTIONAL
-        %TODO "member-affiliation",   % RECOMMENDED
+        "member-affiliation",   % RECOMMENDED
         %TODO "meta-data",   % RECOMMENDED
         % see plugin "modify-affiliations",   % OPTIONAL
         %TODO "multi-collection",   % OPTIONAL
index d7fdb450e030500935330945cc7c125fd156d709..3a4faf5069747b2fdcbaed449d3389e0086b7cfb 100644 (file)
@@ -282,6 +282,7 @@ subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
     State = get_state(Host, Node, SubscriberKey),
     #pubsub_state{affiliation = Affiliation,
                  subscription = Subscription} = State,
+    Whitelisted = lists:member(Affiliation, [member, publisher, owner]),
     if
        not Authorized ->
            %% JIDs do not match
@@ -298,8 +299,8 @@ subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
        (AccessModel == roster) and (not RosterGroup) ->
            %% Entity is not authorized to create a subscription (not in roster group)
            {error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "not-in-roster-group")};
-       (AccessModel == whitelist) ->  % TODO: to be done
-           %% Node has whitelist access model
+       (AccessModel == whitelist) and (not Whitelisted) ->
+           %% Node has whitelist access model and entity lacks required affiliation
            {error, ?ERR_EXTENDED(?ERR_NOT_ALLOWED, "closed-node")};
        (AccessModel == authorize) -> % TODO: to be done
            %% Node has authorize access model
@@ -667,6 +668,7 @@ get_items(Host, Node, JID, AccessModel, PresenceSubscription, RosterGroup, _SubI
     #pubsub_state{affiliation = Affiliation,
                  subscription = Subscription} = State,
     Subscribed = not ((Subscription == none) or (Subscription == pending)),
+    Whitelisted = lists:member(Affiliation, [member, publisher, owner]),
     if
        %%SubID == "", ?? ->
            %% Entity has multiple subscriptions to the node but does not specify a subscription ID
@@ -686,8 +688,8 @@ get_items(Host, Node, JID, AccessModel, PresenceSubscription, RosterGroup, _SubI
        (AccessModel == roster) and (not RosterGroup) ->
            %% Entity is not authorized to create a subscription (not in roster group)
            {error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "not-in-roster-group")};
-       (AccessModel == whitelist) ->  % TODO: to be done
-           %% Node has whitelist access model
+       (AccessModel == whitelist) and (not Whitelisted) ->
+           %% Node has whitelist access model and entity lacks required affiliation
            {error, ?ERR_EXTENDED(?ERR_NOT_ALLOWED, "closed-node")};
        (AccessModel == authorize) -> % TODO: to be done
            %% Node has authorize access model
@@ -717,6 +719,7 @@ get_item(Host, Node, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup
     #pubsub_state{affiliation = Affiliation,
                  subscription = Subscription} = State,
     Subscribed = not ((Subscription == none) or (Subscription == pending)),
+    Whitelisted = lists:member(Affiliation, [member, publisher, owner]),
     if
        %%SubID == "", ?? ->
            %% Entity has multiple subscriptions to the node but does not specify a subscription ID
@@ -736,8 +739,8 @@ get_item(Host, Node, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup
        (AccessModel == roster) and (not RosterGroup) ->
            %% Entity is not authorized to create a subscription (not in roster group)
            {error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "not-in-roster-group")};
-       (AccessModel == whitelist) ->  % TODO: to be done
-           %% Node has whitelist access model
+       (AccessModel == whitelist) and (not Whitelisted) ->
+           %% Node has whitelist access model and entity lacks required affiliation
            {error, ?ERR_EXTENDED(?ERR_NOT_ALLOWED, "closed-node")};
        (AccessModel == authorize) -> % TODO: to be done
            %% Node has authorize access model