Repository: plone.app.upgrade
Branch: refs/heads/master
Date: 2014-12-21T11:57:13+01:00
Author: Jure Cerjak (jcerjak) <jcerjak@termitnjak.si>
Commit: https://github.com/plone/plone.app.upgrade/commit/5d41407ae6f9cd7893ffd982cf9898236f3946ea

add upgrade step to copy security panel settings into the registry

Files changed:
A plone/app/upgrade/v50/profiles/to_beta1/registry.xml
M CHANGES.rst
M plone/app/upgrade/v50/betas.py
M plone/app/upgrade/v50/configure.zcml
M plone/app/upgrade/v50/profiles.zcml

diff --git a/CHANGES.rst b/CHANGES.rst
index eeb195f..1bf846a 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,8 +4,12 @@ Changelog
 1.3.9 (unreleased)
 ------------------
 
+- Add upgrade step for the security control panel.
+  [jcerjak]
+
 - Add upgrade step for mail control panel. Refs PLIP 10359.
   [jcerjak, khink]
+
 - Add upgrade steps for markup control panel.
   [thet]
 
diff --git a/plone/app/upgrade/v50/betas.py b/plone/app/upgrade/v50/betas.py
index a6d9225..db48320 100644
--- a/plone/app/upgrade/v50/betas.py
+++ b/plone/app/upgrade/v50/betas.py
@@ -2,6 +2,7 @@
 from Products.CMFCore.utils import getToolByName
 from Products.CMFPlone.interfaces import IMailSchema
 from Products.CMFPlone.interfaces import IMarkupSchema
+from Products.CMFPlone.interfaces import ISecuritySchema
 from plone.registry.interfaces import IRegistry
 from zope.component import getUtility
 from zope.component.hooks import getSite
@@ -75,3 +76,50 @@ def upgrade_markup_controlpanel_settings(context):
             if _type not in forbidden_types
             and _type not in 'text/x-plone-outputfilters-html'  # removed, as in plone.app.vocabularies.types  # noqa
         ])
+
+
+def upgrade_security_controlpanel_settings(context):
+    """Copy security control panel settings from portal properties and various
+    other locations into the new registry.
+    """
+    def _get_enable_self_reg():
+        app_perms = portal.rolesOfPermission(permission='Add portal member')
+        for appperm in app_perms:
+            if appperm['name'] == 'Anonymous' and \
+               appperm['selected'] == 'SELECTED':
+                return True
+        return False
+
+    # get the old site properties
+    portal_url = getToolByName(context, 'portal_url')
+    portal = portal_url.getPortalObject()
+    portal_properties = getToolByName(portal, "portal_properties")
+    site_properties = portal_properties.site_properties
+
+    # get the new registry
+    registry = getUtility(IRegistry)
+
+    # XXX: Somehow this code is excecuted for old migration steps as well
+    # ( < Plone 4 ) and breaks because there is no registry. Looking up the
+    # registry interfaces with 'check=False' will not work, because it will
+    # return a settings object and then fail when we try to access the
+    # attributes.
+    try:
+        settings = registry.forInterface(
+            ISecuritySchema,
+            prefix='plone',
+        )
+    except KeyError:
+        settings = False
+    if settings:
+        settings.enable_self_reg = _get_enable_self_reg()
+        settings.enable_user_pwd_choice = portal.getProperty(
+            'validate_email', True)
+        pmembership = getToolByName(portal, 'portal_membership')
+        settings.enable_user_folders = pmembership.getMemberareaCreationFlag()
+        settings.allow_anon_views_about = site_properties.getProperty(
+            'allowAnonymousViewAbout', False)
+        settings.use_email_as_login = site_properties.getProperty(
+            'use_email_as_login', False)
+        settings.use_uuid_as_userid = site_properties.getProperty(
+            'use_uuid_as_userid', False)
diff --git a/plone/app/upgrade/v50/configure.zcml b/plone/app/upgrade/v50/configure.zcml
index cb79fd8..47ff249 100644
--- a/plone/app/upgrade/v50/configure.zcml
+++ b/plone/app/upgrade/v50/configure.zcml
@@ -99,6 +99,12 @@
            handler=".betas.upgrade_mail_controlpanel_settings"
            />
 
+       <gs:upgradeStep
+           title="Upgrade security control panel settings"
+           description=""
+           handler=".betas.upgrade_security_controlpanel_settings"
+           />
+
     </gs:upgradeSteps>
 
 </configure>
diff --git a/plone/app/upgrade/v50/profiles.zcml b/plone/app/upgrade/v50/profiles.zcml
index 271af6b..7655975 100644
--- a/plone/app/upgrade/v50/profiles.zcml
+++ b/plone/app/upgrade/v50/profiles.zcml
@@ -21,4 +21,13 @@
       provides="Products.GenericSetup.interfaces.EXTENSION"
       />
 
+  <genericsetup:registerProfile
+      name="to50beta1"
+      title="Upgrade profile for Plone 5003 to Plone 5.0beta1"
+      description=""
+      directory="profiles/to_beta1"
+      for="Products.CMFPlone.interfaces.IMigratingPloneSiteRoot"
+      provides="Products.GenericSetup.interfaces.EXTENSION"
+      />
+
 </configure>
diff --git a/plone/app/upgrade/v50/profiles/to_beta1/registry.xml b/plone/app/upgrade/v50/profiles/to_beta1/registry.xml
new file mode 100644
index 0000000..fd89c49
--- /dev/null
+++ b/plone/app/upgrade/v50/profiles/to_beta1/registry.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<registry>
+  <records interface="Products.CMFPlone.interfaces.ISecuritySchema"
+           prefix="plone" />
+</registry>


Repository: plone.app.upgrade
Branch: refs/heads/master
Date: 2014-12-21T15:02:33+01:00
Author: Jure Cerjak (jcerjak) <jcerjak@termitnjak.si>
Commit: https://github.com/plone/plone.app.upgrade/commit/02074684bc4a683532ce1db47d70dab589553c35

run upgrade profile so that security settings are properly registered

Files changed:
M plone/app/upgrade/v50/betas.py
M plone/app/upgrade/v50/configure.zcml

diff --git a/plone/app/upgrade/v50/betas.py b/plone/app/upgrade/v50/betas.py
index db48320..d1276fc 100644
--- a/plone/app/upgrade/v50/betas.py
+++ b/plone/app/upgrade/v50/betas.py
@@ -3,11 +3,17 @@
 from Products.CMFPlone.interfaces import IMailSchema
 from Products.CMFPlone.interfaces import IMarkupSchema
 from Products.CMFPlone.interfaces import ISecuritySchema
+from plone.app.upgrade.utils import loadMigrationProfile
 from plone.registry.interfaces import IRegistry
 from zope.component import getUtility
 from zope.component.hooks import getSite
 
 
+def to50beta1(context):
+    """5.0alpha3 -> 5.0beta1"""
+    loadMigrationProfile(context, 'profile-plone.app.upgrade.v50:to50beta1')
+
+
 def upgrade_mail_controlpanel_settings(context):
     registry = getUtility(IRegistry)
     # XXX: Somehow this code is excecuted for old migration steps as well
diff --git a/plone/app/upgrade/v50/configure.zcml b/plone/app/upgrade/v50/configure.zcml
index 47ff249..01dd8e9 100644
--- a/plone/app/upgrade/v50/configure.zcml
+++ b/plone/app/upgrade/v50/configure.zcml
@@ -88,6 +88,12 @@
         profile="Products.CMFPlone:plone">
 
        <gs:upgradeStep
+           title="Run to50beta1 upgrade profile"
+           description=""
+           handler=".betas.to50beta1"
+           />
+
+       <gs:upgradeStep
            title="Upgrade markup control panel settings"
            description=""
            handler=".betas.upgrade_markup_controlpanel_settings"


Repository: plone.app.upgrade
Branch: refs/heads/master
Date: 2014-12-21T15:25:08+01:00
Author: Jure Cerjak (jcerjak) <jcerjak@termitnjak.si>
Commit: https://github.com/plone/plone.app.upgrade/commit/1640720250969ee816747d9c76c217ea1380b0f2

properly set enable_user_pwd_choice

Files changed:
M plone/app/upgrade/v50/betas.py

diff --git a/plone/app/upgrade/v50/betas.py b/plone/app/upgrade/v50/betas.py
index d1276fc..c8dd907 100644
--- a/plone/app/upgrade/v50/betas.py
+++ b/plone/app/upgrade/v50/betas.py
@@ -119,8 +119,11 @@ def _get_enable_self_reg():
         settings = False
     if settings:
         settings.enable_self_reg = _get_enable_self_reg()
-        settings.enable_user_pwd_choice = portal.getProperty(
-            'validate_email', True)
+        validate_email = portal.getProperty('validate_email', True)
+        if validate_email:
+            settings.enable_user_pwd_choice = False
+        else:
+            settings.enable_user_pwd_choice = True
         pmembership = getToolByName(portal, 'portal_membership')
         settings.enable_user_folders = pmembership.getMemberareaCreationFlag()
         settings.allow_anon_views_about = site_properties.getProperty(


Repository: plone.app.upgrade
Branch: refs/heads/master
Date: 2014-12-21T19:45:34+01:00
Author: Timo Stollenwerk (tisto) <tisto@plone.org>
Commit: https://github.com/plone/plone.app.upgrade/commit/cd7359c1f21e1433936befc5f4a24f0929c80a66

Merge pull request #21 from jcerjak/plip10359-security-controlpanel

Add upgrade step for the security control panel

Files changed:
A plone/app/upgrade/v50/profiles/to_beta1/registry.xml
M CHANGES.rst
M plone/app/upgrade/v50/betas.py
M plone/app/upgrade/v50/configure.zcml
M plone/app/upgrade/v50/profiles.zcml

diff --git a/CHANGES.rst b/CHANGES.rst
index eeb195f..1bf846a 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,8 +4,12 @@ Changelog
 1.3.9 (unreleased)
 ------------------
 
+- Add upgrade step for the security control panel.
+  [jcerjak]
+
 - Add upgrade step for mail control panel. Refs PLIP 10359.
   [jcerjak, khink]
+
 - Add upgrade steps for markup control panel.
   [thet]
 
diff --git a/plone/app/upgrade/v50/betas.py b/plone/app/upgrade/v50/betas.py
index a6d9225..c8dd907 100644
--- a/plone/app/upgrade/v50/betas.py
+++ b/plone/app/upgrade/v50/betas.py
@@ -2,11 +2,18 @@
 from Products.CMFCore.utils import getToolByName
 from Products.CMFPlone.interfaces import IMailSchema
 from Products.CMFPlone.interfaces import IMarkupSchema
+from Products.CMFPlone.interfaces import ISecuritySchema
+from plone.app.upgrade.utils import loadMigrationProfile
 from plone.registry.interfaces import IRegistry
 from zope.component import getUtility
 from zope.component.hooks import getSite
 
 
+def to50beta1(context):
+    """5.0alpha3 -> 5.0beta1"""
+    loadMigrationProfile(context, 'profile-plone.app.upgrade.v50:to50beta1')
+
+
 def upgrade_mail_controlpanel_settings(context):
     registry = getUtility(IRegistry)
     # XXX: Somehow this code is excecuted for old migration steps as well
@@ -75,3 +82,53 @@ def upgrade_markup_controlpanel_settings(context):
             if _type not in forbidden_types
             and _type not in 'text/x-plone-outputfilters-html'  # removed, as in plone.app.vocabularies.types  # noqa
         ])
+
+
+def upgrade_security_controlpanel_settings(context):
+    """Copy security control panel settings from portal properties and various
+    other locations into the new registry.
+    """
+    def _get_enable_self_reg():
+        app_perms = portal.rolesOfPermission(permission='Add portal member')
+        for appperm in app_perms:
+            if appperm['name'] == 'Anonymous' and \
+               appperm['selected'] == 'SELECTED':
+                return True
+        return False
+
+    # get the old site properties
+    portal_url = getToolByName(context, 'portal_url')
+    portal = portal_url.getPortalObject()
+    portal_properties = getToolByName(portal, "portal_properties")
+    site_properties = portal_properties.site_properties
+
+    # get the new registry
+    registry = getUtility(IRegistry)
+
+    # XXX: Somehow this code is excecuted for old migration steps as well
+    # ( < Plone 4 ) and breaks because there is no registry. Looking up the
+    # registry interfaces with 'check=False' will not work, because it will
+    # return a settings object and then fail when we try to access the
+    # attributes.
+    try:
+        settings = registry.forInterface(
+            ISecuritySchema,
+            prefix='plone',
+        )
+    except KeyError:
+        settings = False
+    if settings:
+        settings.enable_self_reg = _get_enable_self_reg()
+        validate_email = portal.getProperty('validate_email', True)
+        if validate_email:
+            settings.enable_user_pwd_choice = False
+        else:
+            settings.enable_user_pwd_choice = True
+        pmembership = getToolByName(portal, 'portal_membership')
+        settings.enable_user_folders = pmembership.getMemberareaCreationFlag()
+        settings.allow_anon_views_about = site_properties.getProperty(
+            'allowAnonymousViewAbout', False)
+        settings.use_email_as_login = site_properties.getProperty(
+            'use_email_as_login', False)
+        settings.use_uuid_as_userid = site_properties.getProperty(
+            'use_uuid_as_userid', False)
diff --git a/plone/app/upgrade/v50/configure.zcml b/plone/app/upgrade/v50/configure.zcml
index cb79fd8..01dd8e9 100644
--- a/plone/app/upgrade/v50/configure.zcml
+++ b/plone/app/upgrade/v50/configure.zcml
@@ -88,6 +88,12 @@
         profile="Products.CMFPlone:plone">
 
        <gs:upgradeStep
+           title="Run to50beta1 upgrade profile"
+           description=""
+           handler=".betas.to50beta1"
+           />
+
+       <gs:upgradeStep
            title="Upgrade markup control panel settings"
            description=""
            handler=".betas.upgrade_markup_controlpanel_settings"
@@ -99,6 +105,12 @@
            handler=".betas.upgrade_mail_controlpanel_settings"
            />
 
+       <gs:upgradeStep
+           title="Upgrade security control panel settings"
+           description=""
+           handler=".betas.upgrade_security_controlpanel_settings"
+           />
+
     </gs:upgradeSteps>
 
 </configure>
diff --git a/plone/app/upgrade/v50/profiles.zcml b/plone/app/upgrade/v50/profiles.zcml
index 271af6b..7655975 100644
--- a/plone/app/upgrade/v50/profiles.zcml
+++ b/plone/app/upgrade/v50/profiles.zcml
@@ -21,4 +21,13 @@
       provides="Products.GenericSetup.interfaces.EXTENSION"
       />
 
+  <genericsetup:registerProfile
+      name="to50beta1"
+      title="Upgrade profile for Plone 5003 to Plone 5.0beta1"
+      description=""
+      directory="profiles/to_beta1"
+      for="Products.CMFPlone.interfaces.IMigratingPloneSiteRoot"
+      provides="Products.GenericSetup.interfaces.EXTENSION"
+      />
+
 </configure>
diff --git a/plone/app/upgrade/v50/profiles/to_beta1/registry.xml b/plone/app/upgrade/v50/profiles/to_beta1/registry.xml
new file mode 100644
index 0000000..fd89c49
--- /dev/null
+++ b/plone/app/upgrade/v50/profiles/to_beta1/registry.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<registry>
+  <records interface="Products.CMFPlone.interfaces.ISecuritySchema"
+           prefix="plone" />
+</registry>