Repository: django-cms/django-cms

Issue:
CMS_PLACEHOLDER_CONF is not limiting the dropdown
This happened in 2.2rc1.post2...

I have a page titled "My content page" that uses a template called "sub.html" and I want to restrict all the installed plugins to 'cms.plugins.text' only. The template "sub.html" has a placeholder called "content".

So I define CMS_PLACEHOLDER_CONF in the settings:

``` python
CMS_PLACEHOLDER_CONF = {
    'sub.html content': {
        'plugins': ('TextPlugin',),
    },
}
```

This is working fine for the mentioned page "My content page".

But if I create a child page of "My content page" called "Child of My content page" and set the template to inherit the template from its parent, all the installed plugins are available to that page instead of limiting the plugins to the ones defined in CMS_PLACEHOLDER_CONF.



Discussion:

Resolving patch:
diff --git a/cms/plugin_pool.py b/cms/plugin_pool.py
--- a/cms/plugin_pool.py
+++ b/cms/plugin_pool.py
@@ -77,10 +77,14 @@ def get_all_plugins(self, placeholder=None, page=None, setting_key="plugins", in
         plugins = self.plugins.values()[:]
         plugins.sort(key=lambda obj: unicode(obj.name))
         final_plugins = []
+        if page:
+            template = page.get_template()
+        else:
+            template = None
         allowed_plugins = get_placeholder_conf(
             setting_key,
             placeholder,
-            getattr(page, 'template', None)
+            template,
         )
         for plugin in plugins:
             include_plugin = False


Test patch:
diff --git a/cms/tests/placeholder.py b/cms/tests/placeholder.py
--- a/cms/tests/placeholder.py
+++ b/cms/tests/placeholder.py
@@ -1,21 +1,22 @@
 # -*- coding: utf-8 -*-
 from __future__ import with_statement
-from cms.api import add_plugin
+from cms.api import add_plugin, create_page
+from cms.conf.global_settings import CMS_TEMPLATE_INHERITANCE_MAGIC
 from cms.exceptions import DuplicatePlaceholderWarning
 from cms.models.placeholdermodel import Placeholder
-from cms.plugins.text.models import Text
+from cms.plugin_pool import plugin_pool
 from cms.plugin_rendering import render_placeholder
+from cms.plugins.link.cms_plugins import LinkPlugin
 from cms.plugins.text.cms_plugins import TextPlugin
+from cms.plugins.text.models import Text
 from cms.test_utils.fixtures.fakemlng import FakemlngFixtures
-from cms.test_utils.testcases import CMSTestCase
+from cms.test_utils.testcases import CMSTestCase, TestCase
 from cms.test_utils.util.context_managers import (SettingsOverride, 
     UserLoginContext)
 from cms.test_utils.util.mock import AttributeObject
-from cms.utils.placeholder import PlaceholderNoAction, MLNGPlaceholderActions
+from cms.utils.placeholder import (PlaceholderNoAction, MLNGPlaceholderActions, 
+    get_placeholder_conf)
 from cms.utils.plugins import get_placeholders
-from cms.api import create_page, add_plugin
-from cms.models import Placeholder
-from cms.plugins.text.cms_plugins import TextPlugin
 from django.conf import settings
 from django.contrib import admin
 from django.contrib.auth.models import User, Permission
@@ -494,3 +495,37 @@ def test_plugin_edit_requires_permissions(self):
         # It looks like it breaks here because of a missing csrf token in the request
         # I have no idea how to fix this
         self.assertEqual(response.status_code, HttpResponse.status_code)
+
+
+class PlaceholderConfTests(TestCase):
+    def test_get_all_plugins_single_page(self):
+        page = create_page('page', 'col_two.html', 'en')
+        placeholder = page.placeholders.get(slot='col_left')
+        conf = {
+            'col_two': {
+                'plugins': ['TextPlugin', 'LinkPlugin'],
+            },
+            'col_two.html col_left': {
+                'plugins': ['LinkPlugin'],
+            },
+        }
+        with SettingsOverride(CMS_PLACEHOLDER_CONF=conf):
+            plugins = plugin_pool.get_all_plugins(placeholder, page)
+            self.assertEqual(len(plugins), 1, plugins)
+            self.assertEqual(plugins[0], LinkPlugin)
+    def test_get_all_plugins_inherit(self):
+        parent = create_page('parent', 'col_two.html', 'en')
+        page = create_page('page', CMS_TEMPLATE_INHERITANCE_MAGIC, 'en', parent=parent)
+        placeholder = page.placeholders.get(slot='col_left')
+        conf = {
+            'col_two': {
+                'plugins': ['TextPlugin', 'LinkPlugin'],
+            },
+            'col_two.html col_left': {
+                'plugins': ['LinkPlugin'],
+            },
+        }
+        with SettingsOverride(CMS_PLACEHOLDER_CONF=conf):
+            plugins = plugin_pool.get_all_plugins(placeholder, page)
+            self.assertEqual(len(plugins), 1, plugins)
+            self.assertEqual(plugins[0], LinkPlugin)