Esempio n. 1
0
class RDMRecordServiceConfig(RecordServiceConfig):
    """RDM record draft service config."""

    # Record and draft classes
    record_cls = RDMRecord
    draft_cls = RDMDraft

    # Schemas
    schema = RDMRecordSchema
    schema_parent = RDMParentSchema
    schema_secret_link = SecretLink

    # Permission policy
    permission_policy_cls = RDMRecordPermissionPolicy

    # Result classes
    link_result_item_cls = SecretLinkItem
    link_result_list_cls = SecretLinkList

    # Search configuration
    search = RDMSearchOptions
    search_drafts = RDMSearchDraftsOptions
    search_versions = SearchVersionsOptions

    # PIDs providers
    pids_providers = {
        "doi": {
            "datacite": {
                "provider": DOIDataCitePIDProvider,
                "required": True,
                "system_managed": True,
            },
            "external": {
                "provider": partial(UnmanagedPIDProvider, pid_type="doi"),
                "required": False,
                "system_managed": False,
            },
        },
    }

    pids_providers_clients = {"datacite": DOIDataCiteClient}

    # Components - order matters!
    components = [
        MetadataComponent,
        AccessComponent,
        DraftFilesComponent,
        # for the internal `pid` field
        PIDComponent,
        # for the `pids` field (external PIDs)
        ExternalPIDsComponent,
        RelationsComponent,
    ]

    # Links
    links_item = {
        "self":
        ConditionalLink(
            cond=is_record,
            if_=RecordLink("{+api}/records/{id}"),
            else_=RecordLink("{+api}/records/{id}/draft"),
        ),
        "self_html":
        ConditionalLink(
            cond=is_record,
            if_=RecordLink("{+ui}/records/{id}"),
            else_=RecordLink("{+ui}/uploads/{id}"),
        ),
        # TODO: only include link when DOI support is enabled.
        "self_doi":
        Link("{+ui}/doi/{pid_doi}",
             when=is_record,
             vars=lambda record, vars: vars.update({
                 f"pid_{scheme}": pid["identifier"]
                 for (scheme, pid) in record.pids.items()
             })),
        "files":
        ConditionalLink(
            cond=is_record,
            if_=RecordLink("{+api}/records/{id}/files"),
            else_=RecordLink("{+api}/records/{id}/draft/files"),
        ),
        "latest":
        RecordLink("{+api}/records/{id}/versions/latest"),
        "latest_html":
        RecordLink("{+ui}/records/{id}/latest"),
        "draft":
        RecordLink("{+api}/records/{id}/draft", when=is_record),
        "record":
        RecordLink("{+api}/records/{id}", when=is_draft),
        "publish":
        RecordLink("{+api}/records/{id}/draft/actions/publish", when=is_draft),
        "versions":
        RecordLink("{+api}/records/{id}/versions"),
        "access_links":
        RecordLink("{+api}/records/{id}/access/links"),
        # TODO: only include link when DOI support is enabled.
        "reserve_doi":
        RecordLink("{+api}/records/{id}/draft/pids/doi")
    }