Ejemplo n.º 1
0
    def processExpression(self, value, asString=True):
        """Process the string returned by tagged values.

        * python: prefixes a python expression
        * string: prefixes a string
        * fallback to default, which is string, if asString isnt set to False
        """
        return utils.processExpression(value, asString)
Ejemplo n.º 2
0
    def permissionsDefinitions(self):
        """ return a list of dictionaries with permission definitions

        Each dict contains a key 'permission' with a string value and
        a key 'roles' with a list of strings as value and a key
        'acquisition' with value 1 or 0.
        """

        ### for the records:
        ### this method contains lots of generation logic. in fact this
        ### should move over to the WorkflowGenerator.py and reduce here in
        ### just deliver the pure data
        ### the parser should really just parse to be as independent as possible

        # permissions_mapping (abbreviations for lazy guys)
        # keys are case insensitive

        # STATE_PERMISSION_MAPPING in TaggedValueSupport.py now
        # contains the handy mappings from 'access' to 'Access contents
        # information' and so.

        state = self.state
        tagged_values = state.getTaggedValues()
        permission_definitions = []

        for tag_name, tag_value in tagged_values.items():
            # list of tagged values that are NOT permissions
            if tag_name in self.non_permissions:
                # short check if its registered, registry complains in log.
                tgvRegistry.isRegistered(tag_name, state.classcategory,
                                         silent=True)
                continue
            tag_name = tag_name.strip()

            # look up abbreviations if any
            permission = STATE_PERMISSION_MAPPING.get(tag_name.lower(),
                                                      tag_name or '')

            if not tag_value:
                log.debug("Empty tag value, treating it as a reset "
                          "for acquisition, so acquisition=0.")
                permission_definitions.append({'permission' : permission,
                                               'roles' : [],
                                               'acquisition' : 0})
                continue

            # split roles-string into list
            raw_roles = tag_value.replace(';', ',')
            roles = [str(r.strip()) for r in raw_roles.split(',') if r.strip()]

            # verify if this permission is acquired
            nv = 'acquire'
            acquisition = 0
            if nv in roles:
                acquisition = 1
                roles.remove(nv)

            permission = utils.processExpression(permission, asString=False)
            permission_definitions.append(
                        {'permission' : permission,
                         'roles' : roles,
                         'acquisition' : acquisition}
            )

        # If View was defined but Access was not defined, the Access
        # permission should be generated with the same rights defined
        # for View

        has_access = 0
        has_view = 0
        view = {}
        for permission_definition in permission_definitions:
            if (permission_definition.get('permission', None) ==
                STATE_PERMISSION_MAPPING['access']):
                has_access = 1
            if (permission_definition.get('permission', None) ==
                STATE_PERMISSION_MAPPING['view']):
                view = permission_definition
                has_view = 1
        if has_view and not has_access:
            permission = STATE_PERMISSION_MAPPING['access']
            permission_definitions.append({'permission': permission,
                                           'roles': view['roles'],
                                           'acquisition': view['acquisition']})
        return permission_definitions