1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved.
# Fabien Morin <fabien@nexedi.com>
# Mohamadou Mbengue <mmbengue@gmail.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Testing import ZopeTestCase
from Products import ERP5Security
from Products import PluggableAuthService
from zLOG import LOG, WARNING, INFO
def allowAccessOnContributionRegistryPortalTypes(self):
''' Set Type Acquire Local Role '''
self.portal = self.getPortalObject()
portal_contribution_registry = self.portal.portal_contribution_registry
pt_title_list = [p.getTitle() for p in portal_contribution_registry.contentValues()]
exclude_pt_title_list = ['Web Page', 'DMS Ingestion', 'Default Predicate']
for pt_title in pt_title_list:
if pt_title not in exclude_pt_title_list:
portal_type_object = self.portal.portal_types.getTypeInfo(pt_title)
#set acquired local role on the portal type
portal_type_object.setTypeAcquireLocalRole(1)
return '- Access on Contribution Registry Portal Types allowed'
def allowAccessOnPersonAndOrganisation(self):
'''Add local role on person and organisation to give
administrative agent access.
'''
self.portal = self.getPortalObject()
person_portal_type = self.portal.portal_types.getTypeInfo('Person')
person_module_portal_type = self.portal.portal_types.getTypeInfo('Person Module')
organisation_portal_type = self.portal.portal_types.getTypeInfo('Organisation')
organisation_module_portal_type = self.portal.portal_types.getTypeInfo('Organisation Module')
portal_type_list = (person_portal_type, person_module_portal_type, organisation_portal_type, \
organisation_module_portal_type)
role_category_list = ['role/gouvernement']
for ptype in portal_type_list:
role_info_list=[role_info.getTitle() for role_info in ptype.contentValues(portal_type='Role Information')]
if 'Agent Administratif' not in role_info_list:
ptype.newContent(portal_type='Role Information',
title='Agent Administratif',
role_name='Auditor',
role_category_list=role_category_list)
for ptype in portal_type_list:
ptype.updateRoleMapping()
return '- Access on Person and Organisation allowed for administrative agent'
def enableEgovProcedureLogin(self, portal_type):
'''
set properties to enable the login on Person and Organisation
and subcription forms (citizen, company, agent)
'''
portal = self.getPortalObject()
def getAclUsers(self):
return getattr(self.getPortalObject(), 'acl_users', None)
acl_users = getAclUsers(self)
erp5security_dispatcher = acl_users.manage_addProduct['ERP5eGovSecurity']
# add the portal_type in Egov portal_type_list
if {'meta_type': 'EGOV User Manager', 'id': 'egov_users'} in \
erp5security_dispatcher._d._objects:
ptype_list = acl_users.egov_users.portal_type_list
if not portal_type in ptype_list:
ptype_list = ptype_list + (portal_type,)
acl_users.egov_users.manage_changeProperties(portal_type_list=ptype_list,)
if {'meta_type': 'EGOV Group Manager', 'id': 'egov_groups'} in \
erp5security_dispatcher._d._objects :
ptype_list = acl_users.egov_groups.portal_type_list
if not portal_type in ptype_list:
ptype_list = ptype_list + (portal_type,)
acl_users.egov_groups.manage_changeProperties(portal_type_list=ptype_list,)
return '- %s Login Enabled' % portal_type
def setUpEGovSecurityManager(self):
'''use safi PAS to be able to login organisation'''
portal = self.getPortalObject()
def getAclUsers(self):
return getattr(self.getPortalObject(), 'acl_users', None)
acl_users = getAclUsers(self)
# Add EGOVUserManager
ZopeTestCase.installProduct('ERP5eGovSecurity')
erp5security_dispatcher = acl_users.manage_addProduct['ERP5eGovSecurity']
# don't add it if it's already here
if {'meta_type': 'EGOV User Manager', 'id': 'egov_users'} not in \
erp5security_dispatcher._d._objects:
erp5security_dispatcher.addEGOVUserManager('egov_users')
if {'meta_type': 'EGOV Group Manager', 'id': 'egov_groups'} not in \
erp5security_dispatcher._d._objects :
erp5security_dispatcher.addEGOVGroupManager('egov_groups')
# Register ERP5UserManager Interface
acl_users.egov_users.manage_activateInterfaces(('IAuthenticationPlugin',
'IUserEnumerationPlugin',))
acl_users.egov_groups.manage_activateInterfaces(('IGroupsPlugin',))
# desactivate the erp5 plugin
plugins = acl_users.egov_groups.plugins
interface = plugins._getInterfaceFromName('IGroupsPlugin')
if 'erp5_groups' in list(plugins._getPlugins(interface)):
plugins.deactivatePlugin( interface, 'erp5_groups')
plugins = acl_users.egov_users.plugins
interface = plugins._getInterfaceFromName('IAuthenticationPlugin')
if 'erp5_users' in list(plugins._getPlugins(interface)):
plugins.deactivatePlugin( interface, 'erp5_users')
interface = plugins._getInterfaceFromName('IUserEnumerationPlugin')
if 'erp5_users' in list(plugins._getPlugins(interface)):
plugins.deactivatePlugin( interface, 'erp5_users')
# set properties to enable the login on Person and Organisation
# and subcription forms (citizen, company, agent)
acl_users.egov_users.manage_changeProperties(portal_type_list=[
'Person',
'Organisation'],)
acl_users.egov_groups.manage_changeProperties(portal_type_list=[
'Person',
'Organisation'],)
return '- EGOV security set up completed'
def publishAllWebPages(self):
'''web pages are accessible by anonymous users only if they are published'''
web_page_module = self.getPortalObject().web_page_module
for web_page in web_page_module.contentValues():
if web_page.getValidationState() != 'published':
web_page.publish()
return '- All web pages are published'
def setUpInstance(self):
'''call all other set up method to prepare the site for eGOV Instance'''
message_list = []
message_list.append(setUpEGovSecurityManager(self))
message_list.append(allowAccessOnPersonAndOrganisation(self))
message_list.append(allowAccessOnContributionRegistryPortalTypes(self))
message_list.append(publishAllWebPages(self))
message_list.append('')
message_list.append('Set Up sequence completed')
return '\n'.join(message_list)