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 @@
</tuple>
</value>
</item>
<item>
<key> <string>type_list</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
......
......@@ -42,9 +42,16 @@
<tuple>
<string>disable</string>
<string>disable_action</string>
<string>global_enable</string>
</tuple>
</value>
</item>
<item>
<key> <string>type_list</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</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
\ No newline at end of file
272
\ No newline at end of file
......@@ -26,19 +26,15 @@
#
##############################################################################
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
import unittest
# Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300'
from AccessControl.SecurityManagement import newSecurityManager,\
getSecurityManager
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
from AccessControl.SecurityManagement import getSecurityManager
from zLOG import LOG
from DateTime import DateTime
from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Form.Document.Preference import Priority
......@@ -52,15 +48,16 @@ class TestPreferences(ERP5TypeTestCase):
def afterSetUp(self):
uf = self.getPortal().acl_users
uf._doAddUser('manager', '', ['Manager', 'Assignor'], [])
uf._doAddUser('manager', '', ['Manager', 'Assignor', ], [])
user = uf.getUserById('manager').__of__(uf)
newSecurityManager(None, user)
self.createPreferences()
def beforeTearDown(self):
portal_preferences = self.getPreferenceTool()
portal_preferences.manage_delObjects(list(portal_preferences.objectIds()))
get_transaction().commit()
self.tic()
def createPreferences(self) :
""" create some preferences objects """
......@@ -126,13 +123,13 @@ class TestPreferences(ERP5TypeTestCase):
portal_workflow.doActionFor(
site, 'enable_action', wf_id='preference_workflow')
self.assertEquals(person1.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'global')
portal_workflow.doActionFor(
group, 'enable_action', wf_id='preference_workflow')
self.assertEquals(person1.getPreferenceState(), 'enabled')
self.assertEquals(group.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'global')
portal_workflow.doActionFor(
person2, 'enable_action', wf_id='preference_workflow')
......@@ -140,7 +137,7 @@ class TestPreferences(ERP5TypeTestCase):
# enabling a preference disable all other of the same level
self.assertEquals(person1.getPreferenceState(), 'disabled')
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):
""" checks that getPreference returns the good preferred value"""
......@@ -162,7 +159,7 @@ class TestPreferences(ERP5TypeTestCase):
site, 'enable_action', wf_id='preference_workflow')
self.assertEquals(person1.getPreferenceState(), 'enabled')
self.assertEquals(group.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'global')
person1.setPreferredAccountingTransactionSimulationState([])
self.assertEquals(
person1.getPreferredAccountingTransactionSimulationState(), None)
......@@ -227,7 +224,7 @@ class TestPreferences(ERP5TypeTestCase):
self.assertEquals(group.getPreferenceState(), 'enabled')
portal_workflow.doActionFor(
site, 'enable_action', wf_id='preference_workflow')
self.assertEquals(site.getPreferenceState(), 'enabled')
self.assertEquals(site.getPreferenceState(), 'global')
group.setPreferredAccountingTransactionSimulationStateList(['cancelled'])
self.assertNotEquals( None,
......@@ -347,11 +344,22 @@ class TestPreferences(ERP5TypeTestCase):
self.assertEquals(user_b_1.getPreferenceState(), 'enabled')
self.assertEquals(user_a_2.getPreferenceState(), 'disabled')
if __name__ == '__main__':
framework()
else:
import unittest
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPreferences))
return suite
def test_GlobalPreference(self):
# globally enabled preference are preference for anonymous users.
ptool = self.getPreferenceTool()
ptool.site.setPreferredAccountingTransactionSimulationStateList(
['this_is_visible_by_anonymous'])
self.getPortal().portal_workflow.doActionFor(
ptool.site, 'enable_action', wf_id='preference_workflow')
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