Python : Fix data retrieval from group chat.

This commit is contained in:
Schimon Jehudah, Adv. 2024-10-22 17:34:07 +03:00
parent 7dda347ebc
commit 7a01c43a57

24
fasi.py
View file

@ -101,6 +101,9 @@ class HttpInstance:
jid_bare = jid jid_bare = jid
note = 'Jabber ID appears to be malformed' note = 'Jabber ID appears to be malformed'
if jid_bare == jabber_id:
raise HTTPException(status_code=403, detail='access-denied')
#try: #try:
if True: if True:
exception = jid_vcard = messages_10 = note = node_title = \ exception = jid_vcard = messages_10 = note = node_title = \
@ -224,6 +227,9 @@ class HttpInstance:
jid_bare = jid jid_bare = jid
note = 'Jabber ID appears to be malformed' note = 'Jabber ID appears to be malformed'
if jid_bare == jabber_id:
raise HTTPException(status_code=403, detail='access-denied')
#try: #try:
if True: if True:
entries = [] entries = []
@ -401,6 +407,9 @@ class HttpInstance:
jid_bare = jid jid_bare = jid
note = 'Jabber ID appears to be malformed' note = 'Jabber ID appears to be malformed'
if jid_bare == jabber_id:
raise HTTPException(status_code=403, detail='access-denied')
#try: #try:
if True: if True:
exception = note = selection = services_sorted = None exception = note = selection = services_sorted = None
@ -526,6 +535,9 @@ class HttpInstance:
jid_bare = jid jid_bare = jid
note = 'Jabber ID appears to be malformed' note = 'Jabber ID appears to be malformed'
if jid_bare == jabber_id:
raise HTTPException(status_code=403, detail='access-denied')
#try: #try:
if True: if True:
action = count = exception = instance = jid_vcard = \ action = count = exception = instance = jid_vcard = \
@ -707,6 +719,12 @@ class HttpInstance:
response.headers['Content-Type'] = 'application/xhtml+xml' response.headers['Content-Type'] = 'application/xhtml+xml'
return response return response
@self.app.exception_handler(403)
def not_found_exception_handler(request: Request, exc: HTTPException):
action = 'Warning'
title = 'Access Denied'
return result_get(request, action, title)
@self.app.exception_handler(404) @self.app.exception_handler(404)
def not_found_exception_handler(request: Request, exc: HTTPException): def not_found_exception_handler(request: Request, exc: HTTPException):
action = 'Warning' action = 'Warning'
@ -886,8 +904,8 @@ class FileUtilities:
# TODO Create configurations for group chat preview # TODO Create configurations for group chat preview
room_info_muc = await XmppXep0045.get_room_information( room_info_muc = await XmppXep0045.get_room_information(
xmpp_instance, jid_bare, alias, maxstanzas=50) xmpp_instance, jid_bare, alias, maxstanzas=50)
# NOTE Don not mix error messages with node titles and descriptions etc. # NOTE Do not mix error messages with node titles and descriptions etc.
if isinstance(room_info_muc['iq'], stanza.iq.Iq): if isinstance(room_info_muc['iq'], tuple):
iq = room_info_muc['iq'] iq = room_info_muc['iq']
for message in iq[3]: for message in iq[3]:
messages.append({ messages.append({
@ -1427,7 +1445,7 @@ class XmppXep0045:
#presence_options = {"pfrom" : jid_from}, #presence_options = {"pfrom" : jid_from},
#seconds=seconds, #seconds=seconds,
#since=since, #since=since,
timeout=5 timeout=10
) )
except TimeoutError as e: except TimeoutError as e:
#raise HTTPException(status_code=504, detail='request-timeout-reached') #raise HTTPException(status_code=504, detail='request-timeout-reached')