From 23b2b5fdcfae56301c4685fae4b9ff626721ec8e Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Fri, 10 Apr 2020 20:45:20 +0900
Subject: [PATCH] erp5_certificate_authority: Certificate Authority Tool: All
 ERP5 objects *must* have have a Portal Type in Types Tool.

And remove hack in erp5_promise which was creating a non-Portal Type class of
portal_certificate_authority. Instead, add a depend on erp5_certificate_authority.
`providesI*` accessors are now in BaseAccessorHolder rather than Base due to ZODB
Components, this breaks reindexing (`AttributeError: providesIPredicate`).

This gets rid of:
  WARNING ERP5Type.dynamic Cannot find a portal type definition for 'Certificate Authority Tool', trying to guess...
---
 .../Certificate%20Authority%20Tool.xml        | 162 ++++++++++++++++++
 .../bt/template_portal_type_id_list           |   1 +
 ...larm_installPromiseCertificateAuthority.py |   7 +-
 bt5/erp5_promise/bt/dependency_list           |   3 +-
 product/ERP5/Tool/CertificateAuthorityTool.py |   8 -
 product/ERP5Type/tests/testERP5Promise.py     |   2 +-
 6 files changed, 167 insertions(+), 16 deletions(-)
 create mode 100644 bt5/erp5_certificate_authority/PortalTypeTemplateItem/portal_types/Certificate%20Authority%20Tool.xml
 create mode 100644 bt5/erp5_certificate_authority/bt/template_portal_type_id_list

diff --git a/bt5/erp5_certificate_authority/PortalTypeTemplateItem/portal_types/Certificate%20Authority%20Tool.xml b/bt5/erp5_certificate_authority/PortalTypeTemplateItem/portal_types/Certificate%20Authority%20Tool.xml
new file mode 100644
index 0000000000..c622f295ab
--- /dev/null
+++ b/bt5/erp5_certificate_authority/PortalTypeTemplateItem/portal_types/Certificate%20Authority%20Tool.xml
@@ -0,0 +1,162 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="Base Type" module="erp5.portal_type"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_property_domain_dict</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value>
+                      <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>short_title</string> </key>
+                    <value>
+                      <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value>
+                      <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
+                    </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>acquire_local_roles</string> </key>
+            <value> <int>1</int> </value>
+        </item>
+        <item>
+            <key> <string>content_icon</string> </key>
+            <value> <string>folder_icon.gif</string> </value>
+        </item>
+        <item>
+            <key> <string>content_meta_type</string> </key>
+            <value> <string>ERP5 Folder</string> </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>factory</string> </key>
+            <value> <string>addFolder</string> </value>
+        </item>
+        <item>
+            <key> <string>filter_content_types</string> </key>
+            <value> <int>1</int> </value>
+        </item>
+        <item>
+            <key> <string>group_list</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Certificate Authority Tool</string> </value>
+        </item>
+        <item>
+            <key> <string>init_script</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>permission</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string>Contribution Tool</string> </value>
+        </item>
+        <item>
+            <key> <string>type_class</string> </key>
+            <value> <string>CertificateAuthorityTool</string> </value>
+        </item>
+        <item>
+            <key> <string>type_interface</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>type_mixin</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="2" aka="AAAAAAAAAAI=">
+    <pickle>
+      <global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>domain_name</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>property_name</string> </key>
+            <value> <string>description</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="3" aka="AAAAAAAAAAM=">
+    <pickle>
+      <global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>domain_name</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>property_name</string> </key>
+            <value> <string>short_title</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="4" aka="AAAAAAAAAAQ=">
+    <pickle>
+      <global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>domain_name</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>property_name</string> </key>
+            <value> <string>title</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_certificate_authority/bt/template_portal_type_id_list b/bt5/erp5_certificate_authority/bt/template_portal_type_id_list
new file mode 100644
index 0000000000..69d9219445
--- /dev/null
+++ b/bt5/erp5_certificate_authority/bt/template_portal_type_id_list
@@ -0,0 +1 @@
+Certificate Authority Tool
\ No newline at end of file
diff --git a/bt5/erp5_promise/SkinTemplateItem/portal_skins/erp5_promise/Alarm_installPromiseCertificateAuthority.py b/bt5/erp5_promise/SkinTemplateItem/portal_skins/erp5_promise/Alarm_installPromiseCertificateAuthority.py
index 16cfa761a7..1789de85d4 100644
--- a/bt5/erp5_promise/SkinTemplateItem/portal_skins/erp5_promise/Alarm_installPromiseCertificateAuthority.py
+++ b/bt5/erp5_promise/SkinTemplateItem/portal_skins/erp5_promise/Alarm_installPromiseCertificateAuthority.py
@@ -1,11 +1,6 @@
 portal = context.getPortalObject()
 
-portal_certificate_authority = getattr(portal, 'portal_certificate_authority', None)
+portal_certificate_authority = portal.portal_certificate_authority
 promise_ca_path = portal.getPromiseParameter('portal_certificate_authority', 'certificate_authority_path')
-
-if portal_certificate_authority is None:
-   portal.manage_addProduct['ERP5'].manage_addTool('ERP5 Certificate Authority Tool', None)
-   portal_certificate_authority = getattr(portal, 'portal_certificate_authority')
-
 portal_certificate_authority.manage_editCertificateAuthorityTool(
    certificate_authority_path=promise_ca_path)
diff --git a/bt5/erp5_promise/bt/dependency_list b/bt5/erp5_promise/bt/dependency_list
index d0ca7aef23..43c190dbe6 100644
--- a/bt5/erp5_promise/bt/dependency_list
+++ b/bt5/erp5_promise/bt/dependency_list
@@ -1 +1,2 @@
-erp5_core
\ No newline at end of file
+erp5_core
+erp5_certificate_authority
\ No newline at end of file
diff --git a/product/ERP5/Tool/CertificateAuthorityTool.py b/product/ERP5/Tool/CertificateAuthorityTool.py
index 4ed29ebad2..d7270e6268 100644
--- a/product/ERP5/Tool/CertificateAuthorityTool.py
+++ b/product/ERP5/Tool/CertificateAuthorityTool.py
@@ -289,12 +289,4 @@ class CertificateAuthorityTool(BaseTool):
     serial = self._getValidSerial(common_name)
     self.revokeCertificate(serial)
 
-  # XXX: This class lacks a corresponding portal type, so its instances are not
-  # actual documents. A portal type should be created from it, and backward
-  # compatibility added to keep existing instances working.
-  # Until then, hardcode some methods expected to exist on all document
-  # classes so that they can be removed from Base.
-  def _getAcquireLocalRoles(self):
-    return True
-
 InitializeClass(CertificateAuthorityTool)
diff --git a/product/ERP5Type/tests/testERP5Promise.py b/product/ERP5Type/tests/testERP5Promise.py
index cf695c7ea6..1c99d96c90 100644
--- a/product/ERP5Type/tests/testERP5Promise.py
+++ b/product/ERP5Type/tests/testERP5Promise.py
@@ -38,7 +38,7 @@ class TestERP5Promise(ERP5TypeTestCase):
       """
         Return the list of business templates.
       """
-      return ("erp5_promise", "erp5_base")
+      return ("erp5_base", "erp5_certificate_authority", "erp5_promise")
 
     def _test_promise_alarm(self, alarm_id):
       alarm = self.portal.portal_alarms[alarm_id]
-- 
2.30.9