changeset 686:90a5a5af2550

browser_side: let the backend check for the validity of MUC JIDs that come from a user input
author souliane <souliane@mailoo.org>
date Fri, 27 Mar 2015 00:15:42 +0100
parents 9877607c719a
children 3845a086f0b3
files src/browser/libervia_main.py src/browser/sat_browser/dialog.py src/browser/sat_browser/game_radiocol.py src/browser/sat_browser/game_tarot.py src/browser/sat_browser/menu.py
diffstat 5 files changed, 28 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Mon Mar 30 10:28:47 2015 +0200
+++ b/src/browser/libervia_main.py	Fri Mar 27 00:15:42 2015 +0100
@@ -1073,6 +1073,26 @@
             log.error(_('unmanaged dialog type: %s'), type_)
         popup.show()
 
+    def showFailure(self, err_data, msg=''):
+        """Show a failure that has been returned by an asynchronous bridge method.
+
+        @param failure (defer.Failure): Failure instance
+        @param msg (unicode): message to display
+        """
+        # FIXME: message is lost by JSON, we hardcode it for now... remove msg argument when possible
+        err_code, err_obj = err_data
+        title = err_obj['message']['faultString'] if isinstance(err_obj['message'], dict) else err_obj['message']
+        self.showDialog(msg, title, 'error')
+
+    def showFailureRoomInvalid(self, err_data):
+        """Show a failure that has been returned when trying to join an invalid room.
+
+        @param failure (defer.Failure): Failure instance
+        """
+        # FIXME: remove asap, see self.showFailure
+        msg = _(u"Invalid room identifier. Please give a room short or full identifier like 'room' or 'room@%s'.") % C.DEFAULT_MUC_SERVICE
+        self.showFailure(err_data, msg)
+
 
 if __name__ == '__main__':
     app = SatWebFrontend()
--- a/src/browser/sat_browser/dialog.py	Mon Mar 30 10:28:47 2015 +0200
+++ b/src/browser/sat_browser/dialog.py	Fri Mar 27 00:15:42 2015 +0100
@@ -21,7 +21,6 @@
 log = getLogger(__name__)
 
 from constants import Const as C
-from sat_frontends.tools.misc import DEFAULT_MUC
 from sat_frontends.tools import jid
 
 from pyjamas.ui.VerticalPanel import VerticalPanel
@@ -55,7 +54,7 @@
 
     GENERATE_MUC = "<use random name>"
 
-    def __init__(self, host, default_room=DEFAULT_MUC):
+    def __init__(self, host, default_room=C.DEFAULT_MUC):
         """
 
         @param host (SatWebFrontend)
@@ -204,7 +203,7 @@
         button_panel.add(ok_button)
         button_panel.add(Button("Cancel", self.onCancel))
 
-        self.room_panel = RoomChooser(host, "" if visible == (False, True) else DEFAULT_MUC)
+        self.room_panel = RoomChooser(host, "" if visible == (False, True) else C.DEFAULT_MUC)
         self.contact_panel = ContactsChooser(host, nb_contact, ok_button)
 
         self.stack_panel = base_panel.ToggleStackPanel(Width="100%")
@@ -263,9 +262,6 @@
 
     def onOK(self, sender):
         room = self.room  # pyjamas issue: you need to use an intermediate variable to access a property's method
-        if room and not room.is_valid():
-            Window.alert('You must enter a room jid in the form room@chat.%s' % self.host._defaultDomain)
-            return
         self.hide()
         self.callback(room, self.contacts)
 
--- a/src/browser/sat_browser/game_radiocol.py	Mon Mar 30 10:28:47 2015 +0200
+++ b/src/browser/sat_browser/game_radiocol.py	Fri Mar 27 00:15:42 2015 +0100
@@ -22,7 +22,6 @@
 log = getLogger(__name__)
 
 from sat.core.i18n import _, D_
-from sat_frontends.tools.misc import DEFAULT_MUC
 from sat_frontends.tools import host_listener
 from constants import Const as C
 
@@ -258,7 +257,7 @@
         help_msg = """Accepted file formats: Ogg Vorbis (recommended), MP3.<br />
         Please do not submit files that are protected by copyright.<br />
         Click <a style="color: red;">here</a> if you need some support :)"""
-        link_cb = lambda: self._parent.host.bridge.call('joinMUC', None, DEFAULT_MUC, self._parent.nick)
+        link_cb = lambda: self._parent.host.bridge.joinMUC(C.DEFAULT_MUC, self._parent.nick, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=self.host.showFailureRoomInvalid)
         self._parent.printInfo(help_msg, type_='link', link_cb=link_cb)
 
     def pushNextSong(self, title):
@@ -334,7 +333,7 @@
         def callback(room_jid, contacts):
             contacts = [unicode(contact) for contact in contacts]
             room_jid_s = unicode(room_jid) if room_jid else ''
-            host.bridge.launchRadioCollective(contacts, room_jid_s, profile=C.PROF_KEY_NONE)
+            host.bridge.launchRadioCollective(contacts, room_jid_s, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=host.showFailureRoomInvalid)
         dialog.RoomAndContactsChooser(host, callback, ok_button="Choose", title="Collective Radio", visible=(False, True))
 
 
--- a/src/browser/sat_browser/game_tarot.py	Mon Mar 30 10:28:47 2015 +0200
+++ b/src/browser/sat_browser/game_tarot.py	Fri Mar 27 00:15:42 2015 +0100
@@ -400,7 +400,7 @@
         def onPlayersSelected(room_jid, other_players):
             other_players = [unicode(contact) for contact in other_players]
             room_jid_s = unicode(room_jid) if room_jid else ''
-            host.bridge.launchTarotGame(other_players, room_jid_s, profile=C.PROF_KEY_NONE)
+            host.bridge.launchTarotGame(other_players, room_jid_s, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=self.host.showFailureRoomInvalid)
         dialog.RoomAndContactsChooser(host, onPlayersSelected, 3, title="Tarot", title_invite=_(u"Please select 3 other players"), visible=(False, True))
 
     def gotMenus():
--- a/src/browser/sat_browser/menu.py	Mon Mar 30 10:28:47 2015 +0200
+++ b/src/browser/sat_browser/menu.py	Fri Mar 27 00:15:42 2015 +0100
@@ -78,19 +78,21 @@
         def invite(room_jid, contacts):
             for contact in contacts:
                 self.host.bridge.call('inviteMUC', None, unicode(contact), unicode(room_jid))
+
         def join(room_jid, contacts):
             if self.host.whoami:
                 nick = self.host.whoami.node
                 contact_list = self.host.contact_list
                 if room_jid is None or room_jid not in contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP):
                     room_jid_s = unicode(room_jid) if room_jid else ''
-                    self.host.bridge.call('joinMUC', lambda room_jid: invite(room_jid, contacts), room_jid_s, nick)
+                    self.host.bridge.joinMUC(room_jid_s, nick, profile=C.PROF_KEY_NONE, callback=lambda room_jid: invite(room_jid, contacts), errback=self.host.showFailureRoomInvalid)
                 else:
                     self.host.displayWidget(chat.Chat, room_jid, type_="group", new_tab=room_jid)
                     invite(room_jid, contacts)
 
         dialog.RoomAndContactsChooser(self.host, join, ok_button="Join", visible=(True, False))
 
+
     # Help menu
 
     def onSocialContract(self):