Browse Source

[slack] Change qid_or_uuid -> qid and update Document2.DoesNotExist try/except

Harshg999 4 years ago
parent
commit
99b2b3609e
1 changed files with 9 additions and 9 deletions
  1. 9 9
      desktop/core/src/desktop/lib/botserver/views.py

+ 9 - 9
desktop/core/src/desktop/lib/botserver/views.py

@@ -92,24 +92,24 @@ def handle_on_message(channel_id, bot_id, text, user_id):
 def handle_on_link_shared(channel_id, message_ts, links):
 def handle_on_link_shared(channel_id, message_ts, links):
   for item in links:
   for item in links:
     path = urlsplit(item['url'])[2]
     path = urlsplit(item['url'])[2]
-    id_type, qid_or_uuid = urlsplit(item['url'])[3].split('=')
+    id_type, qid = urlsplit(item['url'])[3].split('=')
 
 
     try:
     try:
       if path == '/hue/editor' and id_type == 'editor':
       if path == '/hue/editor' and id_type == 'editor':
-        doc = Document2.objects.get(id=qid_or_uuid)
+        doc = Document2.objects.get(id=qid)
       elif path == '/hue/gist' and id_type == 'uuid' and ENABLE_GIST_PREVIEW.get():
       elif path == '/hue/gist' and id_type == 'uuid' and ENABLE_GIST_PREVIEW.get():
-        doc = _get_gist_document(uuid=qid_or_uuid)
+        doc = _get_gist_document(uuid=qid)
       else:
       else:
         raise PopupException(_("Cannot unfurl link"))
         raise PopupException(_("Cannot unfurl link"))
-
-      doc_data = json.loads(doc.data)
-      statement = doc_data['snippets'][0]['statement_raw'] if id_type == 'editor' else doc_data['statement_raw']
-      dialect = doc_data['dialect'].capitalize() if id_type == 'editor' else doc.extra.capitalize()
-      created_by = doc.owner.get_full_name() or doc.owner.username
     except Document2.DoesNotExist:
     except Document2.DoesNotExist:
-      msg = "Document with {key}={value} does not exist".format(key='uuid' if id_type == 'uuid' else 'id', value=qid_or_uuid)
+      msg = "Document with {key}={value} does not exist".format(key='uuid' if id_type == 'uuid' else 'id', value=qid)
       raise PopupException(_(msg))
       raise PopupException(_(msg))
 
 
+    doc_data = json.loads(doc.data)
+    statement = doc_data['snippets'][0]['statement_raw'] if id_type == 'editor' else doc_data['statement_raw']
+    dialect = doc_data['dialect'].capitalize() if id_type == 'editor' else doc.extra.capitalize()
+    created_by = doc.owner.get_full_name() or doc.owner.username
+    
     payload = _make_unfurl_payload(item['url'], statement, dialect, created_by)
     payload = _make_unfurl_payload(item['url'], statement, dialect, created_by)
     response = slack_client.chat_unfurl(channel=channel_id, ts=message_ts, unfurls=payload)
     response = slack_client.chat_unfurl(channel=channel_id, ts=message_ts, unfurls=payload)
     if not response['ok']:
     if not response['ok']: