Repository: django-cms/django-cms

Issue:
CMS Page with redirect - no access to extended toolbar menu
I have a page with a redirect to an external site setup. I also have extended properties for this page saved in an extendedpage (icon, color and tags). I created a toolbar menu Item for editors to be able to change icons, colors .... 

Problem is obviously, once the redirect is setup, I cant access anymore the toolbar and the custom menu. Is there no way to access custom toolbar menu items from the CMS Pages Admin ? 



Discussion:
that is a valid point.

Could it not be possible to load the redirect into an iframe, with the toolbar overlaid (if in admin mode)? 

that would be a possibility.... and an elegant one.


Resolving patch:
diff --git a/cms/views.py b/cms/views.py
--- a/cms/views.py
+++ b/cms/views.py
@@ -86,14 +86,7 @@ def details(request, slug):
     for frontend_lang in user_languages:
         if frontend_lang in page_languages:
             available_languages.append(frontend_lang)
-    attrs = ''
-    if 'edit' in request.GET:
-        attrs = '?edit=1'
-    elif 'preview' in request.GET:
-        attrs = '?preview=1'
-        if 'draft' in request.GET:
-            attrs += '&draft=1'
-            # Check that the language is in FRONTEND_LANGUAGES:
+    # Check that the language is in FRONTEND_LANGUAGES:
     if not current_language in user_languages:
         #are we on root?
         if not slug:
@@ -108,7 +101,7 @@ def details(request, slug):
                     if new_language in get_public_languages():
                         with force_language(new_language):
                             pages_root = reverse('pages-root')
-                            return HttpResponseRedirect(pages_root + attrs)
+                            return HttpResponseRedirect(pages_root)
             else:
                 _handle_no_page(request, slug)
         else:
@@ -125,7 +118,7 @@ def details(request, slug):
                         # In the case where the page is not available in the
                     # preferred language, *redirect* to the fallback page. This
                     # is a design decision (instead of rendering in place)).
-                    return HttpResponseRedirect(path + attrs)
+                    return HttpResponseRedirect(path)
                 else:
                     found = True
         if not found:
@@ -170,8 +163,10 @@ def details(request, slug):
             '/%s' % request.path,
             request.path,
         ]
-        if redirect_url not in own_urls:
-            return HttpResponseRedirect(redirect_url + attrs)
+        if hasattr(request, 'toolbar') and request.user.is_staff and request.toolbar.show_toolbar:
+            request.toolbar.redirect_url = redirect_url
+        elif redirect_url not in own_urls:
+            return HttpResponseRedirect(redirect_url)
 
     # permission checks
     if page.login_required and not request.user.is_authenticated():


Test patch:
diff --git a/cms/tests/frontend.py b/cms/tests/frontend.py
--- a/cms/tests/frontend.py
+++ b/cms/tests/frontend.py
@@ -13,7 +13,7 @@
 from selenium.webdriver.common.action_chains import ActionChains
 from selenium.common.exceptions import NoSuchElementException, NoAlertPresentException
 
-from cms.models import Page
+from cms.models import Page, CMSPlugin
 from cms.api import create_page, create_title, add_plugin
 from cms.test_utils.testcases import SettingsOverrideTestCase
 from cms.test_utils.util.context_managers import SettingsOverride
@@ -250,6 +250,7 @@ def test_copy_from_language(self):
         self.assertEqual(plugin_instance.body, 'test')
 
     def test_copy_to_from_clipboard(self):
+        self.assertEqual(CMSPlugin.objects.count(), 1)
         self._login()
 
         build_button = self.driver.find_element_by_css_selector('.cms_toolbar-item-cms-mode-switcher a[href="?build"]')
@@ -279,6 +280,8 @@ def test_copy_to_from_clipboard(self):
 
         time.sleep(0.1)
 
+        self.assertEqual(CMSPlugin.objects.count(), 2)
+
         drag = ActionChains(self.driver).click_and_hold(
             clipboard.find_element_by_css_selector('.cms_draggable:nth-child(1)')
         );
@@ -300,6 +303,10 @@ def test_copy_to_from_clipboard(self):
 
         drag.perform()
 
+        time.sleep(0.5)
+
+        self.assertEqual(CMSPlugin.objects.count(), 3)
+
         plugins = self.page.placeholders.all()[0].get_plugins_list('en')
 
-        self.assertEqual(len(plugins), 1)
+        self.assertEqual(len(plugins), 2)
diff --git a/cms/tests/views.py b/cms/tests/views.py
--- a/cms/tests/views.py
+++ b/cms/tests/views.py
@@ -120,6 +120,14 @@ def test_redirect_to_self_with_host(self):
         response = details(request, one.get_path())
         self.assertEqual(response.status_code, 200)
 
+    def test_redirect_with_toolbar(self):
+        create_page("one", "nav_playground.html", "en", published=True,
+                          redirect='/en/page2')
+        superuser = self.get_superuser()
+        with self.login_user_context(superuser):
+            response = self.client.get('/en/?edit')
+            self.assertEqual(response.status_code, 200)
+
     def test_login_required(self):
         create_page("page", "nav_playground.html", "en", published=True,
                     login_required=True)