reenable-user ad-hoc command implementation
darcs-hash:20070725173030-86b55-35d41d00c2f069ed569930d3c421c67cf01d520e.gz
This commit is contained in:
@@ -407,8 +407,28 @@ class JCLCommandManager(CommandManager):
|
|||||||
command_node.setProp("status", STATUS_COMPLETED)
|
command_node.setProp("status", STATUS_COMPLETED)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def execute_reenable_user(self, info_query):
|
def execute_reenable_user_1(self, info_query, session_context,
|
||||||
return []
|
command_node, lang_class):
|
||||||
|
self.__logger.debug("Executing command 'reenable-user' step 1")
|
||||||
|
self.add_actions(command_node, [ACTION_NEXT])
|
||||||
|
return self.add_form_select_user_jids(command_node, lang_class)
|
||||||
|
|
||||||
|
def execute_reenable_user_2(self, info_query, session_context,
|
||||||
|
command_node, lang_class):
|
||||||
|
self.__logger.debug("Executing command 'reenable-user' step 2")
|
||||||
|
self.add_actions(command_node, [ACTION_PREVIOUS, ACTION_COMPLETE], 1)
|
||||||
|
return self.add_form_select_accounts(session_context, command_node, lang_class)
|
||||||
|
|
||||||
|
def execute_reenable_user_3(self, info_query, session_context,
|
||||||
|
command_node, lang_class):
|
||||||
|
self.__logger.debug("Executing command 'reenable-user' step 3")
|
||||||
|
result = []
|
||||||
|
for account_name in session_context["account_names"]:
|
||||||
|
name, user_jid = account_name.split("/", 1)[:2]
|
||||||
|
_account = account.get_account(user_jid, name)
|
||||||
|
_account.enabled = True
|
||||||
|
command_node.setProp("status", STATUS_COMPLETED)
|
||||||
|
return result
|
||||||
|
|
||||||
def execute_end_user_session(self, info_query):
|
def execute_end_user_session(self, info_query):
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -767,14 +767,109 @@ class JCLCommandManager_TestCase(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.assertTrue(_account.enabled)
|
self.assertTrue(_account.enabled)
|
||||||
|
|
||||||
# def test_execute_reenable_user(self):
|
def test_execute_reenable_user(self):
|
||||||
# #TODO : implement command
|
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||||
# info_query = Iq(stanza_type="set",
|
Example2Account)
|
||||||
# from_jid="user1@test.com",
|
model.db_connect()
|
||||||
# to_jid="jcl.test.com")
|
account11 = ExampleAccount(user_jid="test1@test.com",
|
||||||
# result = self.command_manager.execute_add_user(info_query)
|
name="account11",
|
||||||
# self.assertNotEquals(result, None)
|
jid="account11@jcl.test.com")
|
||||||
# self.assertEquals(len(result), 1)
|
account11.enabled = False
|
||||||
|
account12 = Example2Account(user_jid="test1@test.com",
|
||||||
|
name="account12",
|
||||||
|
jid="account12@jcl.test.com")
|
||||||
|
account12.enabled = False
|
||||||
|
account21 = ExampleAccount(user_jid="test2@test.com",
|
||||||
|
name="account21",
|
||||||
|
jid="account21@jcl.test.com")
|
||||||
|
account21.enabled = False
|
||||||
|
account22 = ExampleAccount(user_jid="test2@test.com",
|
||||||
|
name="account11",
|
||||||
|
jid="account11@jcl.test.com")
|
||||||
|
account22.enabled = False
|
||||||
|
account31 = ExampleAccount(user_jid="test3@test.com",
|
||||||
|
name="account31",
|
||||||
|
jid="account31@jcl.test.com")
|
||||||
|
account31.enabled = False
|
||||||
|
account32 = Example2Account(user_jid="test3@test.com",
|
||||||
|
name="account32",
|
||||||
|
jid="account32@jcl.test.com")
|
||||||
|
account32.enabled = False
|
||||||
|
model.db_disconnect()
|
||||||
|
info_query = Iq(stanza_type="set",
|
||||||
|
from_jid="user1@test.com",
|
||||||
|
to_jid="jcl.test.com")
|
||||||
|
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||||
|
command_node.setProp("node", "http://jabber.org/protocol/admin#reenable-user")
|
||||||
|
result = self.command_manager.apply_command_action(info_query,
|
||||||
|
"http://jabber.org/protocol/admin#reenable-user",
|
||||||
|
"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"), "executing")
|
||||||
|
self.assertNotEquals(xml_command.prop("sessionid"), None)
|
||||||
|
self.__check_actions(result[0], ["next"])
|
||||||
|
|
||||||
|
# Second step
|
||||||
|
info_query = Iq(stanza_type="set",
|
||||||
|
from_jid="user1@test.com",
|
||||||
|
to_jid="jcl.test.com")
|
||||||
|
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||||
|
command_node.setProp("node", "http://jabber.org/protocol/admin#reenable-user")
|
||||||
|
session_id = xml_command.prop("sessionid")
|
||||||
|
command_node.setProp("sessionid", session_id)
|
||||||
|
command_node.setProp("action", "next")
|
||||||
|
submit_form = Form(xmlnode_or_type="submit")
|
||||||
|
submit_form.add_field(field_type="jid-multi",
|
||||||
|
name="user_jids",
|
||||||
|
values=["test1@test.com", "test2@test.com"])
|
||||||
|
submit_form.as_xml(command_node)
|
||||||
|
result = self.command_manager.apply_command_action(info_query,
|
||||||
|
"http://jabber.org/protocol/admin#reenable-user",
|
||||||
|
"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"), "executing")
|
||||||
|
self.assertEquals(xml_command.prop("sessionid"), session_id)
|
||||||
|
self.__check_actions(result[0], ["prev", "complete"], 1)
|
||||||
|
context_session = self.command_manager.sessions[session_id][1]
|
||||||
|
self.assertEquals(context_session["user_jids"],
|
||||||
|
["test1@test.com", "test2@test.com"])
|
||||||
|
|
||||||
|
# Third step
|
||||||
|
info_query = Iq(stanza_type="set",
|
||||||
|
from_jid="user1@test.com",
|
||||||
|
to_jid="jcl.test.com")
|
||||||
|
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||||
|
command_node.setProp("node", "http://jabber.org/protocol/admin#reenable-user")
|
||||||
|
command_node.setProp("sessionid", session_id)
|
||||||
|
command_node.setProp("action", "complete")
|
||||||
|
submit_form = Form(xmlnode_or_type="submit")
|
||||||
|
submit_form.add_field(field_type="list-multi",
|
||||||
|
name="account_names",
|
||||||
|
values=["account11/test1@test.com",
|
||||||
|
"account11/test2@test.com"])
|
||||||
|
submit_form.as_xml(command_node)
|
||||||
|
result = self.command_manager.apply_command_action(info_query,
|
||||||
|
"http://jabber.org/protocol/admin#reenable-user",
|
||||||
|
"execute")
|
||||||
|
xml_command = result[0].xpath_eval("c:command",
|
||||||
|
{"c": "http://jabber.org/protocol/commands"})[0]
|
||||||
|
self.assertEquals(xml_command.prop("status"), "completed")
|
||||||
|
self.assertEquals(xml_command.prop("sessionid"), session_id)
|
||||||
|
self.__check_actions(result[0])
|
||||||
|
self.assertEquals(context_session["account_names"],
|
||||||
|
["account11/test1@test.com",
|
||||||
|
"account11/test2@test.com"])
|
||||||
|
for _account in account.get_all_accounts():
|
||||||
|
if _account.name == "account11":
|
||||||
|
self.assertTrue(_account.enabled)
|
||||||
|
else:
|
||||||
|
self.assertFalse(_account.enabled)
|
||||||
|
|
||||||
# def test_execute_end_user_session(self):
|
# def test_execute_end_user_session(self):
|
||||||
# #TODO : implement command
|
# #TODO : implement command
|
||||||
|
|||||||
Reference in New Issue
Block a user