Skip to content

Commit

Permalink
for review
Browse files Browse the repository at this point in the history
  • Loading branch information
rbi-aap committed Jul 26, 2024
1 parent dca96c4 commit e5e4d15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions newsroom/wire/block_media/download_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def remove_editors_media(item, allowed_tags):
if m and m.group(1):
figure = comment.getnext()
for elem in figure.iterchildren():
if elem.tag in excluded_tags:
if 'data-disable-download' not in elem.attrib or elem.attrib['data-disable-download'] != 'true':
elem.attrib['data-disable-download'] = 'true'
if (elem.tag in excluded_tags
and ('data-disable-download' not in elem.attrib
or elem.attrib['data-disable-download'] != 'true')):
elem.attrib['data-disable-download'] = 'true'
html_updated = True
break

if not download_social_tag:
social_media_embeds = root_elem.xpath('//div[@class="embed-block"]')
for social_media_embed in social_media_embeds:
Expand Down
3 changes: 2 additions & 1 deletion newsroom/wire/block_media/filter_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def get_allowed_tags(embedded_data):

allowed_tags = {
'display_tags': [tag for tag, (display_key, _) in tag_mapping.items() if embedded_data.get(display_key, False)],
'download_tags': [tag for tag, (_, download_key) in tag_mapping.items() if embedded_data.get(download_key, False)],
'download_tags': [tag for tag, (_, download_key) in tag_mapping.items()
if embedded_data.get(download_key, False)],
}

return allowed_tags
Expand Down
11 changes: 5 additions & 6 deletions newsroom/wire/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,18 +543,17 @@ def get_permitted_products(self):
def permission_embeds_in_item(self, item, permitted_products):
disable_download = []
for key, embed_item in item.get("associations", {}).items():
if key.startswith("editor_") and embed_item and (embed_item.get('type', '')) in ['audio', 'video', 'picture']:
# get the list of products that the embedded item matched in Superdesk
if (key.startswith("editor_") and embed_item
and embed_item.get('type', '') in ['audio', 'video', 'picture']):
embed_products = [p.get('code') for p in
((item.get('associations') or {}).get(key) or {}).get('products', [])]

if not len(set(embed_products) & set(permitted_products)):
disable_download.append(key)

if len(disable_download) == 0:
logger.info("No embedded items require download disabling.")
return
# logger.info(
# f"Disable download for the following embedded items:- {disable_download}- {item['body_html']}-{item['associations']}")

root_elem = lxml_html.fromstring(item.get('body_html', ''))
regex = r" EMBED START (?:Video|Audio|Image) {id: \"editor_([0-9]+)"
Expand All @@ -567,8 +566,8 @@ def permission_embeds_in_item(self, item, permitted_products):
for elem in figure.iterchildren():
if elem.tag in ['video', 'audio', 'img']:
if "editor_" + m.group(1) in disable_download:
# elem.attrib['data-disable-download'] = 'true'
if 'data-disable-download' not in elem.attrib or elem.attrib['data-disable-download'] != 'true':
if 'data-disable-download' not in elem.attrib or \
elem.attrib['data-disable-download'] != 'true':
elem.attrib['data-disable-download'] = 'true'
html_updated = True
if elem.text and ' EMBED END ' in elem.text:
Expand Down

0 comments on commit e5e4d15

Please sign in to comment.