def test_not_matching(self):
        self.assertEquals(
            set(['Foo']),
            set(get_roles_inheriting_from(['Foo'], [('Bar', 'Baz')])))

        self.assertEquals(
            set(['Foo']),
            set(get_roles_inheriting_from(['Foo'], [('Foo', 'Bar')])))
    def test_not_matching(self):
        self.assertEquals(
            set(['Foo']),
            set(get_roles_inheriting_from(['Foo'], [('Bar', 'Baz')])))

        self.assertEquals(
            set(['Foo']),
            set(get_roles_inheriting_from(['Foo'], [('Foo', 'Bar')])))
 def test_docstring_example(self):
     #A inherits from B
     #B inherits from C
     role_inheritance = (('A', 'B'), ('B', 'C'))
     self.assertEquals(['A'],
                       get_roles_inheriting_from(['A'], role_inheritance))
     self.assertEquals(['A', 'B'],
                       get_roles_inheriting_from(['B'], role_inheritance))
     self.assertEquals(['A', 'B', 'C'],
                       get_roles_inheriting_from(['C'], role_inheritance))
 def test_docstring_example(self):
     #A inherits from B
     #B inherits from C
     role_inheritance = (('A', 'B'), ('B', 'C'))
     self.assertEquals(['A'],
                       get_roles_inheriting_from(['A'], role_inheritance))
     self.assertEquals(['A', 'B'],
                       get_roles_inheriting_from(['B'], role_inheritance))
     self.assertEquals(['A', 'B', 'C'],
                       get_roles_inheriting_from(['C'], role_inheritance))
    def test_multi_stage(self):
        expected = set(['Foo', 'Bar', 'Baz'])
        roles = ['Foo']

        self.assertEquals(
            expected,
            set(
                get_roles_inheriting_from(roles, [('Bar', 'Foo'),
                                                  ('Baz', 'Bar')])))

        self.assertEquals(
            expected,
            set(
                get_roles_inheriting_from(roles, [('Baz', 'Bar'),
                                                  ('Bar', 'Foo')])))
示例#6
0
    def _add_worklist_when_necessary(self, status, role_inheritance):
        if not status.worklist_viewers:
            return False

        worklist = etree.SubElement(self.document, 'worklist')
        worklist.set('title', '')
        worklist.set('worklist_id', self._worklist_id(status))

        action = etree.SubElement(worklist, 'action')
        action.set('category', 'global')
        action.set('icon', '')
        action.set('url', '%%(portal_url)s/search?review_state=%s' % (
                self._status_id(status)))
        action.text = '%s (%%(count)d)' % status.title.decode('utf-8')

        match = etree.SubElement(worklist, 'match')
        match.set('name', 'review_state')
        match.set('values', self._status_id(status))

        guards = etree.SubElement(worklist, 'guard')

        roles = [self.specification.role_mapping[crole]
                 for crole in status.worklist_viewers]
        roles = get_roles_inheriting_from(roles, role_inheritance)

        for role in sorted(roles):
            rolenode = etree.SubElement(guards, 'guard-role')
            rolenode.text = role.decode('utf-8')
示例#7
0
    def _add_worklist_when_necessary(self, status, role_inheritance):
        if not status.worklist_viewers:
            return False

        worklist = etree.SubElement(self.document, 'worklist')
        worklist.set('title', '')
        worklist.set('worklist_id', self._worklist_id(status))

        action = etree.SubElement(worklist, 'action')
        action.set('category', 'global')
        action.set('icon', '')
        action.set(
            'url', '%%(portal_url)s/search?review_state=%s' %
            (self._status_id(status)))
        action.text = '%s (%%(count)d)' % status.title.decode('utf-8')

        match = etree.SubElement(worklist, 'match')
        match.set('name', 'review_state')
        match.set('values', self._status_id(status))

        guards = etree.SubElement(worklist, 'guard')

        roles = [
            self.specification.role_mapping[crole]
            for crole in status.worklist_viewers
        ]
        roles = get_roles_inheriting_from(roles, role_inheritance)

        for role in sorted(roles):
            rolenode = etree.SubElement(guards, 'guard-role')
            rolenode.text = role.decode('utf-8')
示例#8
0
    def _apply_transition_statements(self, statements, nodes,
                                     per_status_role_inheritance):
        for transition, node in nodes.items():
            guards = etree.SubElement(node, 'guard')

            role_inheritance = per_status_role_inheritance.get(
                transition.src_status, [])

            roles = []
            for customer_role, action in statements[transition.src_status]:
                if action != transition.title:
                    continue

                role = self.specification.role_mapping[customer_role]
                roles.append(role)

            roles = get_roles_inheriting_from(roles, role_inheritance)

            for role in roles:
                rolenode = etree.SubElement(guards, 'guard-role')
                rolenode.text = role.decode('utf-8')

            for option, value in transition.options.items():
                if option == 'guard-expression':
                    etree.SubElement(guards, option).text = value

            if len(guards) == 0:
                # Disable the transition by a condition guard, because there
                # were no statements about who can do the transtion.
                xprnode = etree.SubElement(guards, 'guard-expression')
                xprnode.text = u'python: False'
    def test_circular(self):
        expected = set(['Foo', 'Bar', 'Baz'])
        roles = ['Foo']
        role_inheritance = [('Foo', 'Bar'), ('Bar', 'Baz'), ('Baz', 'Foo')]

        self.assertEquals(
            expected, set(get_roles_inheriting_from(roles, role_inheritance)))
示例#10
0
    def _apply_transition_statements(self, statements, nodes,
                                     per_status_role_inheritance):
        for transition, node in nodes.items():
            guards = etree.SubElement(node, 'guard')

            role_inheritance = per_status_role_inheritance.get(
                transition.src_status, [])

            roles = []
            for customer_role, action in statements[transition.src_status]:
                if action != transition.title:
                    continue

                role = self.specification.role_mapping[customer_role]
                roles.append(role)

            roles = get_roles_inheriting_from(roles, role_inheritance)

            for role in roles:
                rolenode = etree.SubElement(guards, 'guard-role')
                rolenode.text = role.decode('utf-8')

            for option, value in transition.options.items():
                if option == 'guard-expression':
                    etree.SubElement(guards, option).text = value

            if len(guards) == 0:
                # Disable the transition by a condition guard, because there
                # were no statements about who can do the transtion.
                xprnode = etree.SubElement(guards, 'guard-expression')
                xprnode.text = u'python: False'
    def test_multi_stage(self):
        expected = set(['Foo', 'Bar', 'Baz'])
        roles = ['Foo']

        self.assertEquals(
            expected,
            set(get_roles_inheriting_from(
                    roles,
                    [('Bar', 'Foo'),
                     ('Baz', 'Bar')])))

        self.assertEquals(
            expected,
            set(get_roles_inheriting_from(
                    roles,
                    [('Baz', 'Bar'),
                     ('Bar', 'Foo')])))
    def test_recursive_resolution(self):
        self.assertEquals(
            ['Anonymous', 'Contributor', 'Editor', 'Manager'],

            get_roles_inheriting_from(
                ['Anonymous'],
                [('Contributor', 'Anonymous'),
                 ('Manager', 'Editor'),
                 ('Editor', 'Contributor')]))
    def test_circular(self):
        expected = set(['Foo', 'Bar', 'Baz'])
        roles = ['Foo']
        role_inheritance = [('Foo', 'Bar'),
                            ('Bar', 'Baz'),
                            ('Baz', 'Foo')]

        self.assertEquals(
            expected,
            set(get_roles_inheriting_from(roles, role_inheritance)))
示例#14
0
    def _apply_status_statements(self, snode, statements, role_inheritance):
        for permission in self.managed_permissions:
            pnode = etree.SubElement(snode, 'permission-map')
            pnode.set('name', permission)
            pnode.set('acquired', 'False')

            roles = self._get_roles_for_permission(permission, statements)
            roles = get_roles_inheriting_from(roles, role_inheritance)

            for role in roles:
                rolenode = etree.SubElement(pnode, 'permission-role')
                rolenode.text = role.decode('utf-8')
示例#15
0
    def _apply_status_statements(self, snode, statements, role_inheritance):
        for permission in self.managed_permissions:
            pnode = etree.SubElement(snode, 'permission-map')
            pnode.set('name', permission)
            pnode.set('acquired', 'False')

            roles = self._get_roles_for_permission(permission, statements)
            roles = get_roles_inheriting_from(roles, role_inheritance)

            for role in roles:
                rolenode = etree.SubElement(pnode, 'permission-role')
                rolenode.text = role.decode('utf-8')
 def test_basic_resolution(self):
     self.assertEquals(
         ['Anonymous', 'Manager'],
         get_roles_inheriting_from(
             ['Anonymous'],
             [('Manager', 'Anonymous')]))
 def test_basic(self):
     self.assertEquals(
         set(['Foo', 'Bar']),
         set(get_roles_inheriting_from(['Foo'], [('Bar', 'Foo')])))
 def test_recursive_resolution(self):
     self.assertEquals(['Anonymous', 'Contributor', 'Editor', 'Manager'],
                       get_roles_inheriting_from(
                           ['Anonymous'], [('Contributor', 'Anonymous'),
                                           ('Manager', 'Editor'),
                                           ('Editor', 'Contributor')]))
 def test_basic_resolution(self):
     self.assertEquals(['Anonymous', 'Manager'],
                       get_roles_inheriting_from(
                           ['Anonymous'], [('Manager', 'Anonymous')]))
 def test_basic(self):
     self.assertEquals(
         set(['Foo', 'Bar']),
         set(get_roles_inheriting_from(['Foo'], [('Bar', 'Foo')])))