Philipp Hörist pushed to branch master at gajim / gajim
Commits: eb869c38 by lovetox at 2022-01-23T12:48:37+01:00 Client: Fix raising PasswordRequired Event
- - - - - c80c9c38 by lovetox at 2022-01-23T12:50:48+01:00 Interface: Handle http-auth event in MainWindow
- - - - - 0ca879b4 by lovetox at 2022-01-23T12:57:04+01:00 HTTPAuth: Simplify code
- - - - -
5 changed files:
- gajim/common/client.py - gajim/common/events.py - gajim/common/modules/http_auth.py - gajim/gtk/main.py - gajim/gui_interface.py
Changes:
===================================== gajim/common/client.py ===================================== @@ -293,7 +293,7 @@ def _on_password(password: str) -> None: self._client.set_password(password) self._prepare_for_connect()
- app.ged.raise_event(PasswordRequired(conn=self, + app.ged.raise_event(PasswordRequired(client=self, on_password=_on_password))
app.ged.raise_event(
===================================== gajim/common/events.py ===================================== @@ -24,6 +24,7 @@ from dataclasses import field
from nbxmpp.protocol import JID +from nbxmpp.structs import HTTPAuthData from nbxmpp.structs import RosterItem from nbxmpp.structs import TuneData from nbxmpp.const import InviteType @@ -274,13 +275,10 @@ class IqErrorReceived(ApplicationEvent):
@dataclass -class HttpAuthReceived(ApplicationEvent): - name: str = field(init=False, default='http-auth-received') - conn: 'Client' - iq_id: str - method: str - url: str - msg: str +class HttpAuth(ApplicationEvent): + name: str = field(init=False, default='http-auth') + client: 'Client' + data: HTTPAuthData stanza: Any
===================================== gajim/common/modules/http_auth.py ===================================== @@ -19,7 +19,7 @@ from nbxmpp.namespaces import Namespace
from gajim.common import app -from gajim.common.events import HttpAuthReceived +from gajim.common.events import HttpAuth from gajim.common.modules.base import BaseModule
@@ -51,12 +51,9 @@ def _http_auth(self, _con, stanza, properties): raise nbxmpp.NodeProcessed
app.ged.raise_event( - HttpAuthReceived(conn=self._con, - iq_id=properties.http_auth.id, - method=properties.http_auth.method, - url=properties.http_auth.url, - msg=properties.http_auth.body, - stanza=stanza)) + HttpAuth(client=self._con, + data=properties.http_auth, + stanza=stanza)) raise nbxmpp.NodeProcessed
def build_http_auth_answer(self, stanza, answer):
===================================== gajim/gtk/main.py ===================================== @@ -32,6 +32,7 @@ from gajim.common import ged from gajim.common.const import Direction from gajim.common.events import ApplicationEvent +from gajim.common.events import HttpAuth from gajim.common.events import PasswordRequired from gajim.common.events import PlainConnection from gajim.common.events import RosterItemExchangeEvent @@ -134,6 +135,7 @@ def __init__(self) -> None: ('roster-item-exchange', ged.GUI1, self._on_roster_item_exchange), ('plain-connection', ged.GUI1, self._on_plain_connection), ('password-required', ged.GUI1, self._on_password_required), + ('http-auth', ged.GUI1, self._on_http_auth), ])
self._check_for_account() @@ -232,6 +234,37 @@ def _on_plain_connection(event: PlainConnection) -> None: def _on_password_required(event: PasswordRequired) -> None: open_window('PasswordDialog', event=event)
+ @staticmethod + def _on_http_auth(event: HttpAuth) -> None: + def _response(answer: str) -> None: + event.client.get_module('HTTPAuth').build_http_auth_answer( + event.stanza, answer) + + account = event.client.account + message = _('HTTP (%(method)s) Authorization ' + 'for %(url)s (ID: %(id)s)') % { + 'method': event.data.method, + 'url': event.data.url, + 'id': event.data.id} + sec_msg = _('Do you accept this request?') + if app.get_number_of_connected_accounts() > 1: + sec_msg = _('Do you accept this request (account: %s)?') % account + if event.data.body: + sec_msg = event.data.body + '\n' + sec_msg + message = message + '\n' + sec_msg + + ConfirmationDialog( + _('Authorization Request'), + _('HTTP Authorization Request'), + message, + [DialogButton.make('Cancel', + text=_('_No'), + callback=_response, + args=['no']), + DialogButton.make('Accept', + callback=_response, + args=['yes'])]).show() + def _add_actions(self) -> None: actions = [ ('add-workspace', 's', self._add_workspace),
===================================== gajim/gui_interface.py ===================================== @@ -81,9 +81,7 @@ from gajim.common.modules.contacts import BareContact from gajim.common.modules.httpupload import HTTPFileTransfer
-from gajim.gui.dialogs import DialogButton from gajim.gui.dialogs import ErrorDialog -from gajim.gui.dialogs import ConfirmationDialog from gajim.gui.filechoosers import FileChooserDialog from gajim.gui.filetransfer import FileTransfersWindow from gajim.gui.menus import build_accounts_menu @@ -142,7 +140,6 @@ def _create_core_handlers_list(self) -> None: # pylint: disable=line-too-long self.handlers = { 'iq-error-received': [self.handle_event_iq_error], - 'http-auth-received': [self.handle_event_http_auth], 'signed-in': [self.handle_event_signed_in], 'presence-received': [self.handle_event_presence], 'our-show': [self.handle_event_status], @@ -175,38 +172,6 @@ def handle_event_iq_error(event): if ctrl and ctrl.is_groupchat: ctrl.add_info_message(f'Error: {event.properties.error}')
- @staticmethod - def handle_event_http_auth(event): - # ('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg)) - def _response(answer: str) -> None: - event.conn.get_module('HTTPAuth').build_http_auth_answer( - event.stanza, answer) - - account = event.conn.name - message = _('HTTP (%(method)s) Authorization ' - 'for %(url)s (ID: %(id)s)') % { - 'method': event.method, - 'url': event.url, - 'id': event.iq_id} - sec_msg = _('Do you accept this request?') - if app.get_number_of_connected_accounts() > 1: - sec_msg = _('Do you accept this request (account: %s)?') % account - if event.msg: - sec_msg = event.msg + '\n' + sec_msg - message = message + '\n' + sec_msg - - ConfirmationDialog( - _('Authorization Request'), - _('HTTP Authorization Request'), - message, - [DialogButton.make('Cancel', - text=_('_No'), - callback=_response, - args=['no']), - DialogButton.make('Accept', - callback=_response, - args=['yes'])]).show() - @staticmethod def handle_event_signed_in(event): """
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/e4189cbc9ed1eccd459ae53701f82b65...