Authorize force-check ad-hoc command to be executed on root node (a form is presented to select accounts) or on an account node
darcs-hash:20071205172536-86b55-e3d2439d97ab5d3581f6e081b73ea1d38161b15c.gz
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
##
|
##
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
from pyxmpp.jabber.dataforms import Form
|
from pyxmpp.jabber.dataforms import Form
|
||||||
import jcl.model.account as account
|
import jcl.model.account as account
|
||||||
@@ -44,7 +45,7 @@ class MailCommandManager(JCLCommandManager):
|
|||||||
JCLCommandManager.__init__(self, component, account_manager)
|
JCLCommandManager.__init__(self, component, account_manager)
|
||||||
self.__logger = logging.getLogger("jmc.jabber.command.JMCCommandManager")
|
self.__logger = logging.getLogger("jmc.jabber.command.JMCCommandManager")
|
||||||
#self.commands["jmc#retrieve-attachment"] = (False, command.account_node_re)
|
#self.commands["jmc#retrieve-attachment"] = (False, command.account_node_re)
|
||||||
self.commands["jmc#force-check"] = (False, command.account_node_re)
|
self.commands["jmc#force-check"] = (False, re.compile(".*"))
|
||||||
|
|
||||||
# Delayed to JMC 0.3.1
|
# Delayed to JMC 0.3.1
|
||||||
def execute_retrieve_attachment_1(self, info_query, session_context,
|
def execute_retrieve_attachment_1(self, info_query, session_context,
|
||||||
@@ -78,9 +79,9 @@ class MailCommandManager(JCLCommandManager):
|
|||||||
|
|
||||||
# TODO: retrieve step2: Delayed to JMC 0.3.1
|
# TODO: retrieve step2: Delayed to JMC 0.3.1
|
||||||
|
|
||||||
def execute_force_check_1(self, info_query, session_context,
|
def execute_force_check_root_node(self, info_query, session_context,
|
||||||
command_node, lang_class):
|
command_node, lang_class):
|
||||||
self.__logger.debug("Executing command 'force-check' step 1")
|
self.__logger.debug("Executing command 'force-check' step 1 on root node")
|
||||||
self.add_actions(command_node, [command.ACTION_COMPLETE])
|
self.add_actions(command_node, [command.ACTION_COMPLETE])
|
||||||
session_context["user_jids"] = [unicode(info_query.get_from().bare())]
|
session_context["user_jids"] = [unicode(info_query.get_from().bare())]
|
||||||
return (self.add_form_select_accounts(session_context, command_node,
|
return (self.add_form_select_accounts(session_context, command_node,
|
||||||
@@ -88,15 +89,31 @@ class MailCommandManager(JCLCommandManager):
|
|||||||
"TODO:DESC", format_as_xml=True,
|
"TODO:DESC", format_as_xml=True,
|
||||||
show_user_jid=False), [])
|
show_user_jid=False), [])
|
||||||
|
|
||||||
def execute_force_check_2(self, info_query, session_context,
|
def execute_force_check_1(self, info_query, session_context,
|
||||||
command_node, lang_class):
|
command_node, lang_class):
|
||||||
self.__logger.debug("Executing command 'force-check' step 2")
|
self.__logger.debug("Executing command 'force-check' step 1")
|
||||||
command_node.setProp("status", command.STATUS_COMPLETED)
|
bare_from_jid = info_query.get_from().bare()
|
||||||
|
account_name = info_query.get_to().node
|
||||||
accounts = []
|
accounts = []
|
||||||
for account_name in session_context["account_names"]:
|
if account_name is None:
|
||||||
name, user_jid = self.get_name_and_jid(account_name)
|
if session_context.has_key("account_names"):
|
||||||
_account = account.get_account(user_jid, name)
|
for account_name in session_context["account_names"]:
|
||||||
_account.lastcheck = _account.interval - 1
|
name, user_jid = self.get_name_and_jid(account_name)
|
||||||
accounts.append(_account)
|
_account = account.get_account(user_jid, name)
|
||||||
|
_account.lastcheck = _account.interval - 1
|
||||||
|
accounts.append(_account)
|
||||||
|
else:
|
||||||
|
return self.execute_force_check_root_node(info_query,
|
||||||
|
session_context,
|
||||||
|
command_node,
|
||||||
|
lang_class)
|
||||||
|
else:
|
||||||
|
_account = account.get_account(bare_from_jid, account_name)
|
||||||
|
if _account is not None:
|
||||||
|
_account.lastcheck = _account.interval - 1
|
||||||
|
accounts.append(_account)
|
||||||
|
command_node.setProp("status", command.STATUS_COMPLETED)
|
||||||
self.component.check_email_accounts(accounts, lang_class)
|
self.component.check_email_accounts(accounts, lang_class)
|
||||||
return (None, [])
|
return (None, [])
|
||||||
|
|
||||||
|
execute_force_check_2 = execute_force_check_1
|
||||||
|
|||||||
@@ -31,14 +31,12 @@ from pyxmpp.jabber.dataforms import Form
|
|||||||
import jcl.tests
|
import jcl.tests
|
||||||
from jcl.jabber.tests.command import JCLCommandManager_TestCase
|
from jcl.jabber.tests.command import JCLCommandManager_TestCase
|
||||||
from jcl.jabber.feeder import Feeder
|
from jcl.jabber.feeder import Feeder
|
||||||
from jcl.model.account import Account, PresenceAccount, LegacyJID, \
|
from jcl.model.account import User
|
||||||
User
|
|
||||||
import jcl.jabber.command as command
|
import jcl.jabber.command as command
|
||||||
|
|
||||||
from jmc.model.account import POP3Account, IMAPAccount, SMTPAccount, \
|
from jmc.model.account import POP3Account, IMAPAccount, SMTPAccount, \
|
||||||
MailAccount
|
MailAccount
|
||||||
from jmc.jabber.component import MailComponent
|
from jmc.jabber.component import MailComponent
|
||||||
from jmc.jabber.command import MailCommandManager
|
|
||||||
|
|
||||||
from jmc.jabber.tests.component import MockIMAPAccount
|
from jmc.jabber.tests.component import MockIMAPAccount
|
||||||
|
|
||||||
@@ -243,6 +241,52 @@ class MailCommandManager_TestCase(JCLCommandManager_TestCase):
|
|||||||
assert(_account.lastcheck == (_account.interval - 1))
|
assert(_account.lastcheck == (_account.interval - 1))
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
self.comp.handler.feeder = MockFeederHandler(self.comp)
|
||||||
|
user1 = User(jid="test1@test.com")
|
||||||
|
user2 = User(jid="test2@test.com")
|
||||||
|
account11 = MockIMAPAccount(user=user1,
|
||||||
|
name="account11",
|
||||||
|
jid="account11@" + unicode(self.comp.jid))
|
||||||
|
account12 = MockIMAPAccount(user=user1,
|
||||||
|
name="account12",
|
||||||
|
jid="account12@" + unicode(self.comp.jid))
|
||||||
|
account21 = MockIMAPAccount(user=user2,
|
||||||
|
name="account21",
|
||||||
|
jid="account21@" + unicode(self.comp.jid))
|
||||||
|
account22 = MockIMAPAccount(user=user2,
|
||||||
|
name="account11",
|
||||||
|
jid="account11@" + unicode(self.comp.jid))
|
||||||
|
info_query = Iq(stanza_type="set",
|
||||||
|
from_jid="test1@test.com",
|
||||||
|
to_jid="account11@" + unicode(self.comp.jid))
|
||||||
|
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||||
|
command_node.setProp("node", "jmc#force-check")
|
||||||
|
result = self.command_manager.apply_command_action(info_query,
|
||||||
|
"jmc#force-check",
|
||||||
|
"execute")
|
||||||
|
self.assertNotEquals(result, None)
|
||||||
|
self.assertEquals(len(result), 1)
|
||||||
|
xml_command = result[0].xpath_eval("c:command",
|
||||||
|
{"c": "http://jabber.org/protocol/commands"})[0]
|
||||||
|
self.assertEquals(xml_command.prop("status"), "completed")
|
||||||
|
self._check_actions(result[0])
|
||||||
|
feeder = self.comp.handler.feeder
|
||||||
|
self.assertEquals(len(feeder.checked_accounts), 1)
|
||||||
|
self.assertEquals(feeder.checked_accounts[0], account11)
|
||||||
|
|
||||||
|
def test_execute_force_check_root_node(self):
|
||||||
|
self.comp.account_manager.account_classes = (POP3Account, IMAPAccount,
|
||||||
|
SMTPAccount, MockIMAPAccount)
|
||||||
|
class MockFeederHandler(Feeder):
|
||||||
|
def __init__(self, component):
|
||||||
|
Feeder.__init__(self, component)
|
||||||
|
self.checked_accounts = []
|
||||||
|
|
||||||
|
def feed(self, _account):
|
||||||
|
self.checked_accounts.append(_account)
|
||||||
|
assert(_account.lastcheck == (_account.interval - 1))
|
||||||
|
return []
|
||||||
|
|
||||||
self.comp.handler.feeder = MockFeederHandler(self.comp)
|
self.comp.handler.feeder = MockFeederHandler(self.comp)
|
||||||
user1 = User(jid="test1@test.com")
|
user1 = User(jid="test1@test.com")
|
||||||
user2 = User(jid="test2@test.com")
|
user2 = User(jid="test2@test.com")
|
||||||
|
|||||||
Reference in New Issue
Block a user