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.


PasswordResetView::getErrors function never called.
## BUG

<!--

Read https://plone.org/support/bugs first!

Please use the labels at Github, at least one of the types: bug, regression, question, enhancement.

Please include tracebacks, screenshots, code of debugging sessions or code that reproduces the issue if possible.
The best reproductions are in plain Plone installations without addons or at least with minimal needed addons installed.

-->

### What I did:
I am trying to reset the password, using a normal Plone user and I made a PDB inside https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/browser/login/password_reset.py#L159

URL: {site url}/passwordreset/e3127df738bc41e1976cc36cc9832132?userid=local_manager

### What I expect to happen:
I expected a call `RegistrationTool.testPasswordValidity(password, password2)
` as I have some business logic inside testPasswordValidity but I saw code never coming here

### What actually happened:
As I see inside ''getErrors''  method, there is a call to registration tool testPasswordValidity method but the ''getErrors'' never called.
### What version of Plone/ Addons I am using:
Plone 5.2.5rc




Discussion:

Fix in password_reset which works for me 
https://github.com/plone/Products.CMFPlone/blob/bd98bd05a3eaf1c5b9579a7fb49da9c37f6721fd/Products/CMFPlone/browser/login/password_reset.py#L141

 ```
    errors = self.getErrors()
    if errors:
        self.status = errors
        return self.form()
```



@benkummer did you make a pull request or just tried in your local.
@nazrulworld I did try it local. Icannot do pull requests yet

Resolving patch:
diff --git a/Products/CMFPlone/browser/login/password_reset.py b/Products/CMFPlone/browser/login/password_reset.py
--- a/Products/CMFPlone/browser/login/password_reset.py
+++ b/Products/CMFPlone/browser/login/password_reset.py
@@ -117,6 +117,9 @@ def _auto_login(self, userid, password):
         return
 
     def _reset_password(self, pw_tool, randomstring):
+        state = self.getErrors()
+        if state:
+            return self.form()
         userid = self.request.form.get('userid')
         password = self.request.form.get('password')
         try:
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
+        )