Store error in account instead of just a boolean (in_error)
darcs-hash:20071204163906-86b55-a552731ba162d51b7a6451027bb5991594348611.gz
This commit is contained in:
@@ -573,11 +573,11 @@ class AccountManager(object):
|
||||
return result
|
||||
|
||||
def send_error_from_account(self, _account, exception):
|
||||
"""Send an error message only one time until _account.in_error
|
||||
has been reset to False"""
|
||||
"""Send an error message only one time until _account.error
|
||||
has been reset to None"""
|
||||
result = []
|
||||
if _account.in_error == False:
|
||||
_account.in_error = True
|
||||
if _account.error == None:
|
||||
_account.error = str(exception)
|
||||
result.append(Message(from_jid=_account.jid,
|
||||
to_jid=_account.user.jid,
|
||||
stanza_type="error",
|
||||
|
||||
@@ -83,13 +83,14 @@ class AccountPresenceHandler(Handler):
|
||||
class AccountPresenceAvailableHandler(AccountPresenceHandler):
|
||||
def get_account_presence(self, stanza, lang_class, _account):
|
||||
show_status = account.ONLINE
|
||||
if _account.in_error:
|
||||
if _account.error is not None:
|
||||
show_status = account.DND
|
||||
elif not _account.enabled:
|
||||
show_status = account.XA
|
||||
return self.component.account_manager.send_presence_available(_account,
|
||||
show_status,
|
||||
lang_class)
|
||||
return self.component.account_manager.send_presence_available(\
|
||||
_account,
|
||||
show_status,
|
||||
lang_class)
|
||||
|
||||
class RootPresenceHandler(AccountPresenceHandler):
|
||||
filter = jabber.get_accounts_root_filter
|
||||
|
||||
@@ -2781,6 +2781,7 @@ class JCLComponent_TestCase(JCLTestCase):
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
exception = Exception("test exception")
|
||||
self.assertEqual(_account.error, None)
|
||||
self.comp.send_error(_account, exception)
|
||||
self.assertEqual(len(self.comp.stream.sent), 1)
|
||||
error_sent = self.comp.stream.sent[0]
|
||||
@@ -2790,6 +2791,7 @@ class JCLComponent_TestCase(JCLTestCase):
|
||||
self.assertEqual(error_sent.get_subject(), _account.default_lang_class.error_subject)
|
||||
self.assertEqual(error_sent.get_body(), _account.default_lang_class.error_body \
|
||||
% (exception))
|
||||
self.assertEqual(_account.error, "test exception")
|
||||
model.db_disconnect()
|
||||
|
||||
def test_send_error_second(self):
|
||||
@@ -2799,9 +2801,10 @@ class JCLComponent_TestCase(JCLTestCase):
|
||||
_account = Account(user=User(jid="user1@test.com"),
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
_account.in_error = True
|
||||
_account.error = "test exception"
|
||||
exception = Exception("test exception")
|
||||
self.comp.send_error(_account, exception)
|
||||
self.assertEqual(_account.error, "test exception")
|
||||
self.assertEqual(len(self.comp.stream.sent), 0)
|
||||
|
||||
def test_send_stanzas(self):
|
||||
|
||||
@@ -246,7 +246,7 @@ class AccountPresenceAvailableHandler_TestCase(JCLTestCase):
|
||||
account11 = Account(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account11.in_error = True
|
||||
account11.error = "Error"
|
||||
account12 = Account(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
|
||||
@@ -91,7 +91,7 @@ class Account(InheritableSQLObject):
|
||||
name = StringCol()
|
||||
jid = StringCol()
|
||||
_status = StringCol(default=OFFLINE, dbName="status")
|
||||
in_error = BoolCol(default=False)
|
||||
error = StringCol(default=None)
|
||||
legacy_jids = MultipleJoin('LegacyJID')
|
||||
enabled = BoolCol(default=True)
|
||||
lastlogin = DateTimeCol(default=datetime.datetime.today())
|
||||
|
||||
Reference in New Issue
Block a user