Ejemplo n.º 1
0
def _deserialize_meta(cstruct: dict, name: str) -> PMap:
    schema = create_workflow_meta_schema(cstruct)
    try:
        appstruct = schema.deserialize(cstruct)
    except Invalid as err:
        msg = 'Error add workflow with name {0}: {1}'
        raise ConfigurationError(msg.format(name, str(err.asdict())))
    return freeze(appstruct)
Ejemplo n.º 2
0
def register_cache_strategy(strategy_adapter: IHTTPCacheStrategy,
                            iresource: IInterface, registry: Registry,
                            view_or_method: str):
    """Register a cache strategy for a specific context interface and view."""
    if view_or_method in DISABLED_VIEWS_OR_METHODS:
        raise ConfigurationError('Setting cache strategy for this view_or_meth'
                                 'od is disabled: {0}'.format(view_or_method))
    registry.registerAdapter(strategy_adapter, (iresource, IRequest),
                             IHTTPCacheStrategy, view_or_method)
Ejemplo n.º 3
0
def _get_import_files(fixture: Path) -> [tuple]:
    allowed_types = ['groups', 'users', 'resources', 'local_roles', 'states']
    import_files = []
    for sub_dir in fixture.iterdir():
        if sub_dir.name in allowed_types:
            for import_file in sub_dir.iterdir():
                import_files.append((sub_dir.name, str(import_file)))
        else:
            msg = 'This is not a valid type directory {}'.format(sub_dir)
            raise ConfigurationError(details=msg)
    return sorted(import_files, key=lambda x: allowed_types.index(x[0]))
Ejemplo n.º 4
0
def _asset_to_fixture(asset: str) -> Path:
    """Translate :term:`asset` to absolute fixture path."""
    package_name, file_name = resolve_asset_spec(asset)
    if package_name:
        package = __import__(package_name)
        path = Path(package_path(package), file_name)
    else:
        path = Path(file_name)
    if not path.is_dir():
        msg = 'This is not a directory {}'.format(asset)
        raise ConfigurationError(details=msg)
    return path
Ejemplo n.º 5
0
def add_workflow(registry: Registry, cstruct: dict, name: str):
    """Create and add workflow to registry.

    :param registry: registry to register the workflow and store meta data.
    :param cstruct: meta data :term:`cstruct` to create the workflow. The data
        schema is :class:`adhocracy_core.workflows.schemas.Workflow`.
    :param name: identifier for the workflow
    :raises adhocracy_core.exceptions.ConfigurationError: if the validation
        for :term:`cstruct` and the sanity checks in
        class:`substanced.workflow.Workflow` fails.
    """
    error_msg = 'Cannot create workflow {0}: {1}'
    try:
        appstruct = _validate_workflow_cstruct(cstruct)
        workflow = _create_workflow(registry, appstruct, name)
    except Invalid as error:
        msg = error_msg.format(name, str(error.asdict()))
        raise ConfigurationError(msg)
    except WorkflowError as error:
        msg = error_msg.format(name, str(error))
        raise ConfigurationError(msg)
    _add_workflow_to_registry(registry, appstruct, workflow, name)
Ejemplo n.º 6
0
def _create_workflow(appstruct: PMap, name: str) -> Workflow:
    initial_state = appstruct['initial_state']
    workflow = ACLLocalRolesWorkflow(initial_state=initial_state, type=name)
    if appstruct.get('add_local_role_participant_to_default_group', False):
        group = 'group:' + DEFAULT_USER_GROUP_NAME
        local_roles = {group: {'role:participant'}}
    else:
        local_roles = None
    for name, data in appstruct['states'].items():
        acm = data.get('acm', {})
        acl = acm and acm_to_acl(acm) or []
        workflow.add_state(name,
                           callback=None,
                           acl=acl,
                           local_roles=local_roles)
    for name, data in appstruct['transitions'].items():
        workflow.add_transition(name, **data)
    try:
        workflow.check()
    except WorkflowError as err:
        msg = 'Error add workflow with name {0}: {1}'
        raise ConfigurationError(msg.format(name, str(err)))
    return workflow
Ejemplo n.º 7
0
def _assert_sheets_are_not_duplicated(meta: ResourceMetadata):
    isheets = meta.basic_sheets + meta.extended_sheets
    if len(isheets) != len(set(isheets)):
        msg = '{0} has duplicated sheets'.format(meta.iresource.__identifier__)
        raise ConfigurationError(details=msg)