# HG changeset patch # User Goffi # Date 1634830261 -7200 # Node ID ed9e12701e0f1c498813f8e748701e4e4d66ac85 # Parent a549c8e1782764b3155a4cdec61ab3b1d2a2e283 backend: return empty roster when `NotAllowedError` is raised in `getOwnerRoster`: No error is logged either, this case can happen often is roster permission is not granted. fix 390 diff -r a549c8e17827 -r ed9e12701e0f sat_pubsub/backend.py --- a/sat_pubsub/backend.py Thu Oct 21 17:24:25 2021 +0200 +++ b/sat_pubsub/backend.py Thu Oct 21 17:31:01 2021 +0200 @@ -1090,6 +1090,8 @@ try: roster = await self.privilege.getRoster(owner_jid) + except error.NotAllowedError: + return except Exception as e: log.msg("Error while getting roster of {owner_jid}: {msg}".format( owner_jid = owner_jid.full(), diff -r a549c8e17827 -r ed9e12701e0f sat_pubsub/error.py --- a/sat_pubsub/error.py Thu Oct 21 17:24:25 2021 +0200 +++ b/sat_pubsub/error.py Thu Oct 21 17:31:01 2021 +0200 @@ -148,7 +148,6 @@ This node does not support publishing. """ - class BadAccessTypeError(Error): pass @@ -157,3 +156,6 @@ """ A requirement is not fulfilled """ + +class NotAllowedError(Error): + """A permission necessary to do a privileged action is not given""" diff -r a549c8e17827 -r ed9e12701e0f sat_pubsub/privilege.py --- a/sat_pubsub/privilege.py Thu Oct 21 17:24:25 2021 +0200 +++ b/sat_pubsub/privilege.py Thu Oct 21 17:31:01 2021 +0200 @@ -19,19 +19,21 @@ "This module implements XEP-0356 (Privileged Entity) to manage rosters, messages and " "presences" +from typing import Dict, List, Optional, Set import time -from typing import Optional, Dict, List, Set -from datetime import datetime, timezone + +from twisted.internet import defer +from twisted.python import log +from twisted.python import failure +from twisted.words.protocols.jabber import error, jid +from twisted.words.xish import domish from wokkel import xmppim -from wokkel.compat import IQ from wokkel import pubsub from wokkel import disco +from wokkel.compat import IQ from wokkel.iwokkel import IPubSubService -from twisted.python import log -from twisted.python import failure -from twisted.internet import defer -from twisted.words.xish import domish -from twisted.words.protocols.jabber import jid, error + +from .error import NotAllowedError FORWARDED_NS = 'urn:xmpp:forward:0' PRIV_ENT_NS = 'urn:xmpp:privilege:1' @@ -61,9 +63,6 @@ class InvalidStanza(Exception): pass -class NotAllowedError(Exception): - pass - class PrivilegesHandler(disco.DiscoClientProtocol): # FIXME: need to manage updates, XEP-0356 must be updated to get roster pushes # TODO: cache @@ -236,7 +235,7 @@ roster[item.entity] = item return roster - async def getRoster(self, to_jid: jid.JID) -> Roster: + async def getRoster(self, to_jid: jid.JID) -> Optional[Roster]: """Retrieve contact list. @param to_jid: jid of the entity owning the roster @@ -246,8 +245,7 @@ # no need to try to get the roster if it's not a user of our own server return None if self._permissions[PERM_ROSTER] not in ('get', 'both'): - log.msg("WARNING: permission not allowed to get roster") - raise failure.Failure(NotAllowedError('roster get is not allowed')) + raise NotAllowedError('roster get is not allowed') iq = IQ(self.xmlstream, 'get') iq.addElement((ROSTER_NS, 'query')) @@ -304,7 +302,7 @@ """ if self._permissions[PERM_MESSAGE] not in ('outgoing',): log.msg("WARNING: permission not allowed to send privileged messages") - raise failure.Failure(NotAllowedError('privileged messages are not allowed')) + raise NotAllowedError('privileged messages are not allowed') main_message = domish.Element((None, "message")) if to_jid is None: