|
|
@@ -95,17 +95,20 @@ def handle_on_link_shared(channel_id, message_ts, links):
|
|
|
path = urlsplit(item['url'])[2]
|
|
|
id_type, qid_or_uuid = urlsplit(item['url'])[3].split('=')
|
|
|
|
|
|
- if path == '/hue/editor' and id_type == 'editor':
|
|
|
- doc = Document2.objects.get(id=qid_or_uuid)
|
|
|
- elif path == '/hue/gist' and id_type == 'uuid' and ENABLE_GIST_PREVIEW.get():
|
|
|
- doc = _get_gist_document(uuid=qid_or_uuid)
|
|
|
- else:
|
|
|
- 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
|
|
|
+ try:
|
|
|
+ if path == '/hue/editor' and id_type == 'editor':
|
|
|
+ doc = Document2.objects.get(id=qid_or_uuid)
|
|
|
+ elif path == '/hue/gist' and id_type == 'uuid' and ENABLE_GIST_PREVIEW.get():
|
|
|
+ doc = _get_gist_document(uuid=qid_or_uuid)
|
|
|
+ else:
|
|
|
+ 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:
|
|
|
+ raise PopupException(_("Document with {key}={value} does not exist").format(key='uuid' if id_type == 'uuid' else 'id', value=qid_or_uuid))
|
|
|
|
|
|
payload = _make_unfurl_payload(item['url'], statement, dialect, created_by)
|
|
|
response = slack_client.chat_unfurl(channel=channel_id, ts=message_ts, unfurls=payload)
|