anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: digitalfabrik/integreat-cms
Issue: Deliver content of mirrored page via API

So far the content of the mirrored page isn't delivered via the API

Steps to reproduce:

1. Add mirrored content to page
2. Save
3. Access API (for example http://0.0.0.0:8000/api/augsburg/de-de/pages/)

Changed files:
backend/cms/models/pages/page_translation.py, backend/api/v3/pages.py, backend/cms/models/pages/page.py

diff --git a/backend/api/v3/pages.py b/backend/api/v3/pages.py
index 77eae21ba..b884fb58e 100644
--- a/backend/api/v3/pages.py
+++ b/backend/api/v3/pages.py
@@ -23,7 +23,7 @@ def transform_page(page_translation):
         'title': page_translation.title,
         'modified_gmt': page_translation.last_updated,
         'excerpt': page_translation.text,
-        'content': page_translation.text,
+        'content': page_translation.combined_text,
         'parent': parent,
         'order': page_translation.page.lft, # use left edge indicator of mptt model for order
         'available_languages': page_translation.available_languages,
diff --git a/backend/cms/models/pages/page.py b/backend/cms/models/pages/page.py
index 528581adb..11b4abf08 100644
--- a/backend/cms/models/pages/page.py
+++ b/backend/cms/models/pages/page.py
@@ -88,7 +88,9 @@ class Page(MPTTModel):
         """
         This content needs to be added when delivering content to end users
         """
-        return self.mirrored_page.get_translation(language_code).text
+        if self.mirrored_page:
+            return self.mirrored_page.get_translation(language_code).text
+        return None
 
     def get_absolute_url(self):
         return reverse('edit_page', kwargs={
diff --git a/backend/cms/models/pages/page_translation.py b/backend/cms/models/pages/page_translation.py
index 204b8406b..65eee13a8 100644
--- a/backend/cms/models/pages/page_translation.py
+++ b/backend/cms/models/pages/page_translation.py
@@ -130,9 +130,12 @@ class PageTranslation(models.Model):
         """
         Combines the text from the PageTranslation with the text from the mirrored page.
         """
+        attached_text = self.page.get_mirrored_text(self.language.code)
+        if attached_text is None:
+            return self.text
         if self.page.mirrored_page_first:
-            return self.page.get_mirrored_text(self.language.code) + self.text
-        return self.text + self.page.get_mirrored_text(self.language.code)
+            return attached_text + self.text
+        return self.text + attached_text
 
     def __str__(self):
         if self.id:
Repository: digitalfabrik/integreat-cms
Issue: Enforce new SECRET_KEY in production environments

The server should refuse to start if the SECRET_KEY does not differ from the default value in our repository.

The importance of this issue depends on whether the Federated Cloud feature is using this key or not.

Changed files:
backend/cms/apps.py

diff --git a/backend/cms/apps.py b/backend/cms/apps.py
index 3c1abd7f3..ad324df24 100644
--- a/backend/cms/apps.py
+++ b/backend/cms/apps.py
@@ -1,8 +1,12 @@
 """
 Django related class representing a config of an app
 """
+import logging
+import sys
+from django.conf import settings
 from django.apps import AppConfig
 
+logger = logging.getLogger(__name__)
 
 class CmsConfig(AppConfig):
     """
@@ -10,3 +14,8 @@ class CmsConfig(AppConfig):
     """
 
     name = 'cms'
+
+    def ready(self):
+        if settings.SECRET_KEY == '-!v282$zj815_q@htaxcubylo)(l%a+k*-xi78hw*#s2@i86@_' and not settings.DEBUG:
+            logger.error("You are running the Integreat CMS in production mode. Change the SECRET_KEY in the settings.py!")
+            sys.exit(1)
Repository: digitalfabrik/integreat-cms
Issue: Don't use objects.get in best_language_title()

Reproduce bug:
There must be at least one page without english translation. Then edit a page in the english backend. => Error

Reason:
To show the page in the page mirroring drop down menu, the root language of the region is used. A language node of the region is chosen by `LanguageTreeNode.objects.get(region__id=self.region.id)`.
But get() apparently only works if there is excactly one matching object. So it would only work if the region had only one language at all.

Changed files:
backend/cms/models/page.py

diff --git a/backend/cms/models/page.py b/backend/cms/models/page.py
index d72ea8884..c24f537ee 100644
--- a/backend/cms/models/page.py
+++ b/backend/cms/models/page.py
@@ -11,7 +11,7 @@ from django.utils.translation import get_language
 
 from mptt.models import MPTTModel, TreeForeignKey
 
-from .language import Language, LanguageTreeNode
+from .language import Language
 from .region import Region
 from ..constants import status
 
@@ -143,7 +143,7 @@ class Page(MPTTModel):
     def best_language_title(self):
         page_translation = self.page_translations.filter(language__code=get_language())
         if not page_translation:
-            alt_code = LanguageTreeNode.objects.get(region__id=self.region.id).get_root().language.code
+            alt_code = self.region.default_language.code
             page_translation = self.page_translations.filter(language__code=alt_code)
         return page_translation.first().title
Repository: digitalfabrik/integreat-cms
Issue: IntegrityError in language tree

I just found a bug causing an `IntegrityError` in the language tree. The error can be reproduced reliably in the current state of the develop branch.

Steps to reproduce:
- In the network admin view:
  - Create a new region
  - Create at least two languages (in the following steps, we assume the two languages to be German and Englisch, works with any other languages as well)
- In the region view (in the region we just created):
  - Create a new language node for the base language (German in this example)
  - **Bug occurs in the next steps, therefore I provide a more precise description of the following steps:** in the language tree view, click on "create language tree node"
  - Choose "English" as language, "German" as source language, check the checkbox for language activation
  - click on "save", a success message should show up
  - click on "save" again without changing any form fields
  - now the form fields should have the following contents:
    - language: "English"
    - source language: "German"
    - activate language: is checked (`true`)
  - change language field to "German", as all languages can be chosen again
  - now the form fields should have the following contents:
    - language: "German"
    - source language: "German"
    - activate language: is checked (`true`)
  - click on "save" again
  - `IntegrityError` occurs

Changed files:
backend/cms/views/language_tree/language_tree_node.py

diff --git a/backend/cms/views/language_tree/language_tree_node.py b/backend/cms/views/language_tree/language_tree_node.py
index 6e88117f9..aa8bf3806 100644
--- a/backend/cms/views/language_tree/language_tree_node.py
+++ b/backend/cms/views/language_tree/language_tree_node.py
@@ -55,17 +55,17 @@ class LanguageTreeNodeView(PermissionRequiredMixin, TemplateView):
         form = LanguageTreeNodeForm(data=request.POST, site_slug=site_slug)
         if form.is_valid():
             if language_tree_node_id:
-                form.save_language_node(
+                language_tree_node = form.save_language_node(
                     language_tree_node_id=language_tree_node_id,
                 )
                 messages.success(request, _('Language tree node was saved successfully.'))
             else:
                 language_tree_node = form.save_language_node()
                 messages.success(request, _('Language tree node was created successfully.'))
-                return redirect('edit_language_tree_node', **{
-                    'language_tree_node_id': language_tree_node.id,
-                    'site_slug': site_slug,
-                })
+            return redirect('edit_language_tree_node', **{
+                'language_tree_node_id': language_tree_node.id,
+                'site_slug': site_slug,
+            })
             # TODO: improve messages
         else:
             messages.error(request, _('Errors have occurred.'))
Repository: digitalfabrik/integreat-cms
Issue: PDF Export URL pattern

### Describe the Bug
The web app calls `/REGION/LANG/wp-json/ig-mpdf/v1/pdf` to export a PDF which returns a 404. Our API currently uses `REGION/LANG/pdf`.

The normal mapping does not work, as we

### Steps to Reproduce

```shell
curl 'https://malte-test.tuerantuer.org/joerdenstorf/de/wp-json/ig-mpdf/v1/pdf'
```

### Expected Behavior
Map old URL pattern to new endpoint.


### Actual Behavior
404

Changed files:
integreat_cms/api/urls.py

diff --git a/integreat_cms/api/urls.py b/integreat_cms/api/urls.py
index 0244538a5..6f4a30225 100644
--- a/integreat_cms/api/urls.py
+++ b/integreat_cms/api/urls.py
@@ -136,6 +136,11 @@ urlpatterns = [
                     "<slug:language_slug>/wp-json/extensions/v3/",
                     include(content_api_urlpatterns),
                 ),
+                path(
+                    "<slug:language_slug>/wp-json/ig-mpdf/v1/pdf/",
+                    pdf_export,
+                    name="pdf_export",
+                ),
             ]
         ),
     ),