comparison psgxs.js @ 18:75625771e410

Send subscription request only if node access_model is authorize.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 19 Oct 2010 18:51:34 +0200
parents ec7cea92fe8a
children 032090a13fe8
comparison
equal deleted inserted replaced
17:ec7cea92fe8a 18:75625771e410
520 return makeError(response, subID); 520 return makeError(response, subID);
521 } else if (configuration['pubsub#access_model'] == 'authorize') { 521 } else if (configuration['pubsub#access_model'] == 'authorize') {
522 subID = storage.subscribe(nodeID, jid, 'pending', conf); 522 subID = storage.subscribe(nodeID, jid, 'pending', conf);
523 if (typeof subID == 'number') 523 if (typeof subID == 'number')
524 return makeError(response, subID); 524 return makeError(response, subID);
525 } else if (configuration['pubsub#access_model'] == 'whitelist') { 525
526 var affil = storage.getAffiliation(jid, nodeID);
527 if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'member')
528 return makeError(response, errors.sub.subscribe.not_on_whitelist.n);
529
530 subID = storage.subscribe(nodeID, jid, conf);
531 if (typeof subID == 'number')
532 return makeError(response, subID);
533 }
534
535 response.c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
536 .c('subscription', {node: nodeID, jid: jid, subid: subID.subid, subscription: subID.type});
537
538 if (conf)
539 response.cnode(options);
540
541 if (config.enabled('get-pending')) {
542 var affiliates = storage.getAffiliationsFromNodeID(nodeID); 526 var affiliates = storage.getAffiliationsFromNodeID(nodeID);
543 var form = forms.build('form', 'subscribe_authorization', {allow: false, node: nodeID, subscriber_jid: jid}, true); //168 527 var form = forms.build('form', 'subscribe_authorization', {allow: false, node: nodeID, subscriber_jid: jid}, true); //168
528
544 for (var i in affiliates) { 529 for (var i in affiliates) {
545 if (affiliates[i] == 'super-owner' || affiliates[i] == 'owner') { 530 if (affiliates[i] == 'super-owner' || affiliates[i] == 'owner') {
546 var message = xmpp.message({to: i}).cnode(form); 531 var message = xmpp.message({to: i}).cnode(form);
547 conn.send(message); 532 conn.send(message);
548 } 533 }
549 } 534 }
550 } 535 } else if (configuration['pubsub#access_model'] == 'whitelist') {
536 var affil = storage.getAffiliation(jid, nodeID);
537 if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'member')
538 return makeError(response, errors.sub.subscribe.not_on_whitelist.n);
539
540 subID = storage.subscribe(nodeID, jid, conf);
541 if (typeof subID == 'number')
542 return makeError(response, subID);
543 }
544
545 response.c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
546 .c('subscription', {node: nodeID, jid: jid, subid: subID.subid, subscription: subID.type});
547
548 if (conf)
549 response.cnode(options);
551 550
552 if (config.enabled('last-published')) { 551 if (config.enabled('last-published')) {
553 var last = storage.getLastItem(nodeID); 552 var last = storage.getLastItem(nodeID);
554 if (typeof last != 'number') { 553 if (typeof last != 'number') {
555 var item = storage.getItem(nodeID, last); 554 var item = storage.getItem(nodeID, last);