Commit c2986947 authored by Jérome Perrin's avatar Jérome Perrin

handle the case of 'Site' preference, they must have different security

definition, eg. they should be enabled for anonymous.
This is done by adding a new state 'global' and a global_enable automatic
method for preferences with priority = 1.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13451 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e8e90c91
...@@ -45,6 +45,12 @@ ...@@ -45,6 +45,12 @@
</tuple> </tuple>
</value> </value>
</item> </item>
<item>
<key> <string>type_list</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
......
...@@ -42,9 +42,16 @@ ...@@ -42,9 +42,16 @@
<tuple> <tuple>
<string>disable</string> <string>disable</string>
<string>disable_action</string> <string>disable_action</string>
<string>global_enable</string>
</tuple> </tuple>
</value> </value>
</item> </item>
<item>
<key> <string>type_list</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.DCWorkflow.States</string>
<string>StateDefinition</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>global</string> </value>
</item>
<item>
<key> <string>permission_roles</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Globally Enabled</string> </value>
</item>
<item>
<key> <string>transitions</string> </key>
<value>
<tuple>
<string>disable</string>
<string>disable_action</string>
</tuple>
</value>
</item>
<item>
<key> <string>type_list</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<tuple>
<string>Persistence</string>
<string>PersistentMapping</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_container</string> </key>
<value>
<dictionary>
<item>
<key> <string>Access contents information</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Authenticated</string>
<string>Author</string>
<string>Manager</string>
<string>Member</string>
<string>Owner</string>
<string>Reviewer</string>
</tuple>
</value>
</item>
<item>
<key> <string>Modify portal content</string> </key>
<value>
<tuple>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>View</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Authenticated</string>
<string>Author</string>
<string>Manager</string>
<string>Member</string>
<string>Owner</string>
<string>Reviewer</string>
</tuple>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.DCWorkflow.Transitions</string>
<string>TransitionDefinition</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Enable a "global" preference</string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>global_enable</string> </value>
</item>
<item>
<key> <string>new_state_id</string> </key>
<value> <string>global</string> </value>
</item>
<item>
<key> <string>script_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>0</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<tuple>
<string>Products.DCWorkflow.Guard</string>
<string>Guard</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>expr</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<tuple>
<string>Products.CMFCore.Expression</string>
<string>Expression</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>python: object.getPriority() == 1</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
271 272
\ No newline at end of file \ No newline at end of file
...@@ -26,19 +26,15 @@ ...@@ -26,19 +26,15 @@
# #
############################################################################## ##############################################################################
import os, sys import unittest
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
# Needed in order to have a log file inside the current folder from AccessControl.SecurityManagement import newSecurityManager
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log') from AccessControl.SecurityManagement import noSecurityManager
os.environ['EVENT_LOG_SEVERITY'] = '-300' from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.SecurityManagement import newSecurityManager,\
getSecurityManager
from zLOG import LOG from zLOG import LOG
from DateTime import DateTime from DateTime import DateTime
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Form.Document.Preference import Priority from Products.ERP5Form.Document.Preference import Priority
...@@ -52,15 +48,16 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -52,15 +48,16 @@ class TestPreferences(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('manager', '', ['Manager', 'Assignor'], []) uf._doAddUser('manager', '', ['Manager', 'Assignor', ], [])
user = uf.getUserById('manager').__of__(uf) user = uf.getUserById('manager').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
self.createPreferences() self.createPreferences()
def beforeTearDown(self): def beforeTearDown(self):
portal_preferences = self.getPreferenceTool() portal_preferences = self.getPreferenceTool()
portal_preferences.manage_delObjects(list(portal_preferences.objectIds())) portal_preferences.manage_delObjects(list(portal_preferences.objectIds()))
get_transaction().commit() get_transaction().commit()
self.tic()
def createPreferences(self) : def createPreferences(self) :
""" create some preferences objects """ """ create some preferences objects """
...@@ -126,13 +123,13 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -126,13 +123,13 @@ class TestPreferences(ERP5TypeTestCase):
portal_workflow.doActionFor( portal_workflow.doActionFor(
site, 'enable_action', wf_id='preference_workflow') site, 'enable_action', wf_id='preference_workflow')
self.assertEquals(person1.getPreferenceState(), 'enabled') self.assertEquals(person1.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'enabled') self.assertEquals(site.getPreferenceState(), 'global')
portal_workflow.doActionFor( portal_workflow.doActionFor(
group, 'enable_action', wf_id='preference_workflow') group, 'enable_action', wf_id='preference_workflow')
self.assertEquals(person1.getPreferenceState(), 'enabled') self.assertEquals(person1.getPreferenceState(), 'enabled')
self.assertEquals(group.getPreferenceState(), 'enabled') self.assertEquals(group.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'enabled') self.assertEquals(site.getPreferenceState(), 'global')
portal_workflow.doActionFor( portal_workflow.doActionFor(
person2, 'enable_action', wf_id='preference_workflow') person2, 'enable_action', wf_id='preference_workflow')
...@@ -140,7 +137,7 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -140,7 +137,7 @@ class TestPreferences(ERP5TypeTestCase):
# enabling a preference disable all other of the same level # enabling a preference disable all other of the same level
self.assertEquals(person1.getPreferenceState(), 'disabled') self.assertEquals(person1.getPreferenceState(), 'disabled')
self.assertEquals(group.getPreferenceState(), 'enabled') self.assertEquals(group.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'enabled') self.assertEquals(site.getPreferenceState(), 'global')
def test_GetPreference(self, quiet=quiet, run=run_all_tests): def test_GetPreference(self, quiet=quiet, run=run_all_tests):
""" checks that getPreference returns the good preferred value""" """ checks that getPreference returns the good preferred value"""
...@@ -162,7 +159,7 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -162,7 +159,7 @@ class TestPreferences(ERP5TypeTestCase):
site, 'enable_action', wf_id='preference_workflow') site, 'enable_action', wf_id='preference_workflow')
self.assertEquals(person1.getPreferenceState(), 'enabled') self.assertEquals(person1.getPreferenceState(), 'enabled')
self.assertEquals(group.getPreferenceState(), 'enabled') self.assertEquals(group.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'enabled') self.assertEquals(site.getPreferenceState(), 'global')
person1.setPreferredAccountingTransactionSimulationState([]) person1.setPreferredAccountingTransactionSimulationState([])
self.assertEquals( self.assertEquals(
person1.getPreferredAccountingTransactionSimulationState(), None) person1.getPreferredAccountingTransactionSimulationState(), None)
...@@ -227,7 +224,7 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -227,7 +224,7 @@ class TestPreferences(ERP5TypeTestCase):
self.assertEquals(group.getPreferenceState(), 'enabled') self.assertEquals(group.getPreferenceState(), 'enabled')
portal_workflow.doActionFor( portal_workflow.doActionFor(
site, 'enable_action', wf_id='preference_workflow') site, 'enable_action', wf_id='preference_workflow')
self.assertEquals(site.getPreferenceState(), 'enabled') self.assertEquals(site.getPreferenceState(), 'global')
group.setPreferredAccountingTransactionSimulationStateList(['cancelled']) group.setPreferredAccountingTransactionSimulationStateList(['cancelled'])
self.assertNotEquals( None, self.assertNotEquals( None,
...@@ -347,11 +344,22 @@ class TestPreferences(ERP5TypeTestCase): ...@@ -347,11 +344,22 @@ class TestPreferences(ERP5TypeTestCase):
self.assertEquals(user_b_1.getPreferenceState(), 'enabled') self.assertEquals(user_b_1.getPreferenceState(), 'enabled')
self.assertEquals(user_a_2.getPreferenceState(), 'disabled') self.assertEquals(user_a_2.getPreferenceState(), 'disabled')
if __name__ == '__main__': def test_GlobalPreference(self):
framework() # globally enabled preference are preference for anonymous users.
else: ptool = self.getPreferenceTool()
import unittest ptool.site.setPreferredAccountingTransactionSimulationStateList(
def test_suite(): ['this_is_visible_by_anonymous'])
suite = unittest.TestSuite() self.getPortal().portal_workflow.doActionFor(
suite.addTest(unittest.makeSuite(TestPreferences)) ptool.site, 'enable_action', wf_id='preference_workflow')
return suite self.assertEquals('global', ptool.site.getPreferenceState())
get_transaction().commit()
self.tic()
noSecurityManager()
self.assertEquals(['this_is_visible_by_anonymous'],
ptool.getPreferredAccountingTransactionSimulationStateList())
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPreferences))
return suite
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