Esempio n. 1
0
 def properties(self):
     props = ProtectedProperties(self, DEFAULT_NODE_PROPERTY_PERMISSIONS)
     props.in_navtree = True
     props.action_edit = True
     props.action_delete = True
     props.action_up = True
     return props
Esempio n. 2
0
    def test_ProtectedProperties(self):
        # Protected properties checks against permission for properties
        context = BaseNode()

        # 'viewprotected' property gets protected by 'view' permission
        permissions = {
            'viewprotected': ['view'],
        }
        props = ProtectedProperties(context, permissions)

        # Setting properties works always
        props.viewprotected = True
        props.unprotected = True

        # Unauthorized just permits access to unprotected property
        self.layer.new_request()

        self.assertTrue(props.viewprotected is None)
        self.assertTrue(props.unprotected)

        self.assertFalse('viewprotected' in props)
        self.assertTrue('unprotected' in props)

        self.assertEqual(props.keys(), ['unprotected'])
        self.assertTrue(props.get('viewprotected') is None)
        self.assertTrue(props.get('unprotected'))

        err = self.expect_error(KeyError, lambda: props['viewprotected'])
        expected = '"No permission to access \'viewprotected\'"'
        self.assertEqual(str(err).strip('u'), expected)

        self.assertTrue(props['unprotected'])

        # Authenticate, both properties are now available
        with self.layer.authenticated('viewer'):
            self.layer.new_request()

            self.assertTrue(props['viewprotected'])
            self.assertTrue(props.viewprotected)
            self.assertTrue(props.unprotected)

            self.assertEqual(
                sorted(props.keys()),
                ['unprotected', 'viewprotected']
            )
            self.assertTrue(props.get('viewprotected'))
            self.assertTrue(props.get('unprotected'))

            props.viewprotected = False
            self.assertFalse(props.viewprotected)
Esempio n. 3
0
 def properties(self):
     props = ProtectedProperties(self, DEFAULT_NODE_PROPERTY_PERMISSIONS)
     props.in_navtree = True
     props.action_edit = self.state == u'working_copy'
     props.action_delete = self.state == u'working_copy'
     props.action_up = True
     props.action_view = True
     props.wf_name = u'revision'
     props.leaf = True
     # XXX: check in repoze.workflow the intended way for naming
     #      transitions
     props.wf_transition_names = transition_names
     return props
Esempio n. 4
0
 def properties(self):
     props = ProtectedProperties(self, DEFAULT_NODE_PROPERTY_PERMISSIONS)
     props.in_navtree = True
     props.editable = False
     props.icon = 's3-static/images/s3_16_16.png'
     return props
Esempio n. 5
0
    def test_ProtectedProperties(self):
        # Protected properties checks against permission for properties
        context = BaseNode()

        # 'viewprotected' property gets protected by 'view' permission
        permissions = {
            'viewprotected': ['view'],
        }
        props = ProtectedProperties(context, permissions)
        self.assertTrue(IProperties.providedBy(props))

        # Setting properties works always
        props.viewprotected = True
        props.unprotected = True

        # Unauthorized just permits access to unprotected property
        self.layer.new_request()

        self.assertTrue(props.viewprotected is None)
        self.assertTrue(props.unprotected)

        self.assertFalse('viewprotected' in props)
        self.assertTrue('unprotected' in props)

        self.assertEqual(props.keys(), ['unprotected'])
        self.assertTrue(props.get('viewprotected') is None)
        self.assertTrue(props.get('unprotected'))

        err = self.expect_error(KeyError, lambda: props['viewprotected'])
        expected = '"No permission to access \'viewprotected\'"'
        self.assertEqual(str(err).strip('u'), expected)

        self.assertTrue(props['unprotected'])

        # Authenticate, both properties are now available
        with self.layer.authenticated('viewer'):
            self.layer.new_request()

            self.assertTrue(props['viewprotected'])
            self.assertTrue(props.viewprotected)
            self.assertTrue(props.unprotected)

            self.assertEqual(
                sorted(props.keys()),
                ['unprotected', 'viewprotected']
            )
            self.assertTrue(props.get('viewprotected'))
            self.assertTrue(props.get('unprotected'))

            props.viewprotected = False
            self.assertFalse(props.viewprotected)

        # internal data
        self.assertEqual(
            o_getattr(props, '_data'),
            {'unprotected': True, 'viewprotected': False}
        )
        self.assertTrue(o_getattr(props, '_context') is context)
        self.assertEqual(o_getattr(props, '_permissions'), permissions)

        # ``__copy__``
        props_copy = copy.copy(props)
        self.assertFalse(props_copy is props)
        self.assertEqual(props_copy.__class__, ProtectedProperties)
        self.assertEqual(
            o_getattr(props_copy, '_data'),
            o_getattr(props, '_data')
        )
        self.assertTrue(o_getattr(props, '_context') is context)
        self.assertEqual(o_getattr(props, '_permissions'), permissions)

        # ``__deepcopy__``
        props_deepcopy = copy.deepcopy(props)
        self.assertFalse(props_deepcopy is props)
        self.assertEqual(props_deepcopy.__class__, ProtectedProperties)
        self.assertEqual(
            o_getattr(props_deepcopy, '_data'),
            o_getattr(props, '_data')
        )
        self.assertTrue(o_getattr(props, '_context') is context)
        self.assertEqual(o_getattr(props, '_permissions'), permissions)
Esempio n. 6
0
 def properties(self):
     props = ProtectedProperties(self, DEFAULT_NODE_PROPERTY_PERMISSIONS)
     props.editable = True
     return props
Esempio n. 7
0
    def test_ProtectedProperties(self):
        # Protected properties checks against permission for properties
        context = BaseNode()

        # 'viewprotected' property gets protected by 'view' permission
        permissions = {
            'viewprotected': ['view'],
        }
        props = ProtectedProperties(context, permissions)

        # Setting properties works always
        props.viewprotected = True
        props.unprotected = True

        # Unauthorized just permits access to unprotected property
        self.layer.new_request()

        self.assertTrue(props.viewprotected is None)
        self.assertTrue(props.unprotected)

        self.assertFalse('viewprotected' in props)
        self.assertTrue('unprotected' in props)

        self.assertEqual(props.keys(), ['unprotected'])
        self.assertTrue(props.get('viewprotected') is None)
        self.assertTrue(props.get('unprotected'))

        err = self.expect_error(KeyError, lambda: props['viewprotected'])
        expected = '"No permission to access \'viewprotected\'"'
        self.assertEqual(str(err).strip('u'), expected)

        self.assertTrue(props['unprotected'])

        # Authenticate, both properties are now available
        with self.layer.authenticated('viewer'):
            self.layer.new_request()

            self.assertTrue(props['viewprotected'])
            self.assertTrue(props.viewprotected)
            self.assertTrue(props.unprotected)

            self.assertEqual(sorted(props.keys()),
                             ['unprotected', 'viewprotected'])
            self.assertTrue(props.get('viewprotected'))
            self.assertTrue(props.get('unprotected'))

            props.viewprotected = False
            self.assertFalse(props.viewprotected)