Repository: plone/Products.CMFPlone

Issue:
Content Settings controlpanel saves changes without notice when changing content type selection
## Content type settings changes when selecting different content type

### What I did:

- Go to @@content-controlpanel
- Select a content type from the `select` field
- Change some settings
- Select another content type without hitting the `Save` button

### What I expect to happen:

Settings for the first selected content type are not changed

### What actually happened:

Settings for the first content type are changed

### What version of Plone/ Addons I am using:

Plone 5.2.x, but applies to all 5.x versions, and 4.x as well.




Discussion:

Resolving patch:
diff --git a/Products/CMFPlone/controlpanel/browser/types.py b/Products/CMFPlone/controlpanel/browser/types.py
--- a/Products/CMFPlone/controlpanel/browser/types.py
+++ b/Products/CMFPlone/controlpanel/browser/types.py
@@ -122,7 +122,7 @@ def __call__(self):
         cancel_button = form.get('form.button.Cancel', None) is not None
         type_id = form.get('old_type_id', None)
 
-        if submitted and not cancel_button:
+        if save_button and submitted and not cancel_button:
             if type_id:
                 portal_types = getToolByName(self.context, 'portal_types')
                 portal_repository = getToolByName(self.context,
@@ -200,9 +200,9 @@ def __call__(self):
                 elif not default_page_type and type_id in default_page_types:
                     default_page_types.remove(type_id)
                 types_settings.default_page_types = default_page_types
-
-                redirect_links = form.get('redirect_links', False)
-                types_settings.redirect_links = redirect_links
+                if type_id == 'Link':
+                    redirect_links = form.get('redirect_links', False)
+                    types_settings.redirect_links = redirect_links
 
             # Update workflow
             if self.have_new_workflow() \


Test patch:
diff --git a/Products/CMFPlone/controlpanel/tests/test_controlpanel_browser_types.py b/Products/CMFPlone/controlpanel/tests/test_controlpanel_browser_types.py
--- a/Products/CMFPlone/controlpanel/tests/test_controlpanel_browser_types.py
+++ b/Products/CMFPlone/controlpanel/tests/test_controlpanel_browser_types.py
@@ -110,7 +110,7 @@ def test_disable_versioning_removes_behavior(self):
         self.browser.getControl(name='type_id').value = ['Document']
         self.browser.getForm(action=self.types_url).submit()
         self.browser.getControl(name='versionpolicy').value = ['off']
-        self.browser.getForm(action=self.types_url).submit()
+        self.browser.getControl(name="form.button.Save").click()
 
         portal_types = self.portal.portal_types
         doc_type = portal_types.Document
@@ -123,7 +123,7 @@ def test_enable_versioning_behavior_on_document(self):
         self.browser.getControl(name='type_id').value = ['Document']
         self.browser.getForm(action=self.types_url).submit()
         self.browser.getControl(name='versionpolicy').value = ['off']
-        self.browser.getForm(action=self.types_url).submit()
+        self.browser.getControl(name="form.button.Save").click()
 
         portal_types = self.portal.portal_types
         doc_type = portal_types.Document
@@ -132,7 +132,7 @@ def test_enable_versioning_behavior_on_document(self):
             not in doc_type.behaviors)  # noqa
 
         self.browser.getControl(name='versionpolicy').value = ['manual']
-        self.browser.getForm(action=self.types_url).submit()
+        self.browser.getControl(name="form.button.Save").click()
 
         self.assertTrue(
             'plone.app.versioningbehavior.behaviors.IVersionable'
@@ -157,7 +157,7 @@ def test_enable_versioning_behavior_on_file(self):
             not in file_type.behaviors)  # noqa
 
         self.browser.getControl(name='versionpolicy').value = ['manual']
-        self.browser.getForm(action=self.types_url).submit()
+        self.browser.getControl('Save').click()
 
         self.assertTrue(
             'plone.app.versioningbehavior.behaviors.IVersionable'
@@ -165,3 +165,64 @@ def test_enable_versioning_behavior_on_file(self):
         self.assertTrue(
             'plone.app.lockingbehavior.behaviors.ILocking'
             in file_type.behaviors)
+
+    def test_dont_update_settings_when_switch_types(self):
+        # First of all, set a default
+        self.browser.open(self.types_url)
+        self.browser.getControl(name='type_id').value = ['Link']
+        self.browser.getForm(action=self.types_url).submit()
+        self.browser.getControl(
+            'Redirect immediately to link target'
+        ).selected = True
+        self.browser.getControl('Save').click()
+
+        # Then switch the type
+        self.browser.getControl(name='type_id').value = ['Document']
+        self.browser.getForm(action=self.types_url).submit()
+        self.assertFalse(
+            'Redirect immediately to link target' in self.browser.contents
+        )
+
+        # Go back to the link, and check the value
+        self.browser.getControl(name='type_id').value = ['Link']
+        self.browser.getForm(action=self.types_url).submit()
+
+        self.assertTrue(
+            'Redirect immediately to link target' in self.browser.contents
+        )
+        self.assertEquals(
+            self.browser.getControl(
+                'Redirect immediately to link target').selected,
+            True
+        )
+
+    def test_dont_update_redirect_links_when_not_in_link_settings(self):
+        # First of all, set a default
+        self.browser.open(self.types_url)
+        self.browser.getControl(name='type_id').value = ['Link']
+        self.browser.getForm(action=self.types_url).submit()
+        self.browser.getControl(
+            'Redirect immediately to link target'
+        ).selected = True
+        self.browser.getControl('Save').click()
+
+        # Then switch the type
+        self.browser.getControl(name='type_id').value = ['Document']
+        self.browser.getForm(action=self.types_url).submit()
+        self.assertFalse(
+            'Redirect immediately to link target' in self.browser.contents
+        )
+        self.browser.getControl('Save').click()
+
+        # Go back to the link, and check the value
+        self.browser.getControl(name='type_id').value = ['Link']
+        self.browser.getForm(action=self.types_url).submit()
+
+        self.assertTrue(
+            'Redirect immediately to link target' in self.browser.contents
+        )
+        self.assertEquals(
+            self.browser.getControl(
+                'Redirect immediately to link target').selected,
+            True
+        )