2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

[Bug] Ensure links are prepended with base URL on receipt (#8367) (#8370)

* Ensure links are prepended with base URL on receipt

* Bug fix

(cherry picked from commit 3253a4a93c61c405da6c5d62ddd80bf74579e4c2)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot] 2024-10-26 12:49:16 +11:00 committed by GitHub
parent 2bccbffe56
commit 343f63c6ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 2 deletions

View File

@ -33,7 +33,8 @@ from . import config, locales
checkMinPythonVersion()
INVENTREE_NEWS_URL = 'https://inventree.org/news/feed.atom'
INVENTREE_BASE_URL = 'https://inventree.org'
INVENTREE_NEWS_URL = f'{INVENTREE_BASE_URL}/news/feed.atom'
# Determine if we are running in "test" mode e.g. "manage.py test"
TESTING = 'test' in sys.argv or 'TESTING' in os.environ

View File

@ -29,5 +29,5 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(set_default_currency),
migrations.RunPython(set_default_currency, reverse_code=migrations.RunPython.noop),
]

View File

@ -0,0 +1,39 @@
# Generated by Django 4.2.16 on 2024-10-26 00:24
from django.conf import settings
from django.db import migrations
import logging
logger = logging.getLogger('inventree')
def update_news_feed_urls(apps, schema_editor):
"""Update and validate the news feed URLs."""
from common.models import NewsFeedEntry
n = 0
for entry in NewsFeedEntry.objects.all():
if entry.link and entry.link.startswith('/'):
entry.link = settings.INVENTREE_BASE_URL + entry.link
entry.save()
n += 1
if n > 0:
logger.info("Updated link for %s NewsFeedEntry objects", n)
class Migration(migrations.Migration):
dependencies = [
('common', '0030_barcodescanresult'),
]
operations = [
migrations.RunPython(
update_news_feed_urls,
reverse_code=migrations.RunPython.noop
)
]

View File

@ -70,6 +70,10 @@ def update_news_feed():
if entry.id in id_list:
continue
# Enforce proper links for the entries
if entry.link and str(entry.link).startswith('/'):
entry.link = settings.INVENTREE_BASE_URL + str(entry.link)
# Create entry
try:
NewsFeedEntry.objects.create(