Commit ef6f1147 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_erp5: Update utility scripts for introspect security_uids

parent 6fe46d7d
import transaction
def Base_getSecurityUidDictAndRoleColumnDictForUser(self, user_id):
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.SecurityManagement import setSecurityManager
from AccessControl.SecurityManagement import newSecurityManager
sm = getSecurityManager()
try:
u = self.acl_users.getUserById(user_id)
newSecurityManager(None, u.__of__(self.acl_users))
return [dict(item) for item in
self.portal_catalog.getSecurityUidDictAndRoleColumnDict()]
finally:
transaction.abort() # why ???
setSecurityManager(sm)
def Base_getAllowedRolesAndUsers(self, user_id):
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.SecurityManagement import setSecurityManager
from AccessControl.SecurityManagement import newSecurityManager
sm = getSecurityManager()
try:
u = self.acl_users.getUserById(user_id)
newSecurityManager(None, u.__of__(self.acl_users))
return self.portal_catalog.getAllowedRolesAndUsers()
finally:
transaction.abort() # why ???
setSecurityManager(sm)
def ERP5Site_getSecurityUidListForRecreateTable(self):
security_uid_entry_list = []
for item in self.getPortalObject().portal_catalog.getSQLCatalog().getRoleAndSecurityUidList():
security_uid_entry_list.append((item[2], item[1]))
return security_uid_entry_list
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Extension Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>SlapOSAdministration</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>extension.erp5.SlapOSAdministration</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Extension Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>Base_getAllowedRolesAndUsers</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>SlapOSAdministration</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getAllowedRolesAndUsers</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>Base_getSecurityUidDictAndRoleColumnDictForUser</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>SlapOSAdministration</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getSecurityUidDictAndRoleColumnDictForUser</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
security_uid_entry_list = []
for item in context.getPortalObject().portal_catalog.getSQLCatalog().getRoleAndSecurityUidList():
if isinstance(item[0], tuple):
for role in item[0]:
security_uid_entry_list.append((item[1], role))
return security_uid_entry_list
......@@ -2,60 +2,26 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
<key> <string>_function</string> </key>
<value> <string>ERP5Site_getSecurityUidListForRecreateTable</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<key> <string>_module</string> </key>
<value> <string>SlapOSAdministration</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getSecurityUidListForRecreateTable</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
......
portal = context.getPortalObject()
uid_groups_columns_dict = portal.portal_catalog.getSQLCatalog().getSQLCatalogSecurityUidGroupsColumnsDict()
uid_groups_columns_items = sorted(uid_groups_columns_dict.items())
security_column_list = sorted(uid_groups_columns_dict.values())
user_id_list = ['claudie', 'rafael', 'vifib-admin', 'nexedi_development_service']
#for user in portal.person_module.searchFolder(
# reference='%',
# validation_state='validated',
# default_role_uid=portal.portal_categories.role.internal.getUid()):
# user_id_list.append(user.getReference())
info_list = []
for user_id in sorted(user_id_list):
user = portal.acl_users.getUserById(user_id)
if user is None:
continue
groups = user.getGroups()
uid_dict_and_roles_column_dict = portal.Base_getSecurityUidDictAndRoleColumnDictForUser(user_id)
info = [user_id, len(groups)]
for local_roles_group_id, security_column in uid_groups_columns_items:
info.append(len(uid_dict_and_roles_column_dict[0].get(local_roles_group_id,[])))
info_list.append(info)
print ','.join(['user_id', 'group_count',] + [x[1] for x in
uid_groups_columns_items])
for info in info_list:
print ','.join([str(x) for x in info])
response = portal.REQUEST.RESPONSE
response.setHeader('Content-Disposition', 'attachement;filename=%s-%s.csv' %
(script.getId(), DateTime().strftime('%Y%m%d')))
response.setHeader('Content-Type', 'text/csv')
return printed
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getSecurityUidStat</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
extension.erp5.SlapOSCheckConsistency
extension.erp5.SlapOSLoginMigration
\ No newline at end of file
extension.erp5.SlapOSLoginMigration
extension.erp5.SlapOSAdministration
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment