class CommunityServiceConfig(RecordServiceConfig):
    """Communities service configuration."""

    # Common configuration
    permission_policy_cls = CommunityPermissionPolicy

    # Record specific configuration
    record_cls = Community

    # Search configuration
    search = SearchOptions

    # Service schema
    schema = CommunitySchema

    links_item = {
        "self": RecordLink("{+api}/communities/{id}"),
        "self_html": RecordLink("{+ui}/communities/{id}"),
        "settings_html": RecordLink("{+ui}/communities/{id}/settings"),
        "logo": RecordLink("{+api}/communities/{id}/logo"),
        "rename": RecordLink("{+api}/communities/{id}/rename")
    }

    links_search = pagination_links("{+api}/communities{?args*}")
    links_user_search = pagination_links("{+api}/user/communities{?args*}")

    # Service components
    components = [
        MetadataComponent,
        PIDComponent,
        CommunityAccessComponent,
    ]
示例#2
0
    def create_service_class(self):
        """Create service class."""
        permission_policy_cls_name = f"{self.record_type_name}PermissionPolicy"
        config_cls_name = f"{self.record_type_name}ServiceConfig"
        service_cls_name = f"{self.record_type_name}Service"

        # if permission policy not given, create a standard one
        if not self.permission_policy_cls:
            self.permission_policy_cls = type(permission_policy_cls_name,
                                              (RecordPermissionPolicy, ), {})

        route = self.endpoint_route or f"/{self.record_name_lower}s"

        config_cls_attributes = {
            "permission_policy_cls": self.permission_policy_cls,
            "record_cls": self.record_cls,
            "search": self.search_options,
            "schema": self.service_schema,
            "links_item": {
                "self": RecordLink("{+api}" + route + "/{id}"),
            },
            "links_search": pagination_links("{+api}" + route + "{?args*}"),
        }
        if self.service_components:
            config_cls_attributes.update(
                {"components": self.service_components})

        self.service_config_cls = type(config_cls_name,
                                       (RecordServiceConfig, ),
                                       config_cls_attributes)

        self.service_cls = type(service_cls_name, (RecordService, ), {})
class ServiceConfig(RecordServiceConfig):
    """Mock service configuration.

    Needs both configs, with File overwritting the record ones.
    """

    permission_policy_cls = PermissionPolicy
    record_cls = Record
    schema = RecordSchema
    search = MockSearchOptions

    links_item = {
        "self": RecordLink("{+api}/mocks/{id}"),
        "files": RecordLink("{+api}/mocks/{id}/files"),
    }

    links_search = pagination_links("{+api}/mocks{?args*}")
示例#4
0
class RDMRecordServiceConfig(RecordServiceConfig, ConfiguratorMixin):
    """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 = FromConfig("RDM_PERMISSION_POLICY",
                                       default=RDMRecordPermissionPolicy,
                                       import_string=True)

    # Result classes
    link_result_item_cls = SecretLinkItem
    link_result_list_cls = SecretLinkList

    # Search configuration
    search = FromConfigSearchOptions('RDM_SEARCH',
                                     search_option_cls=RDMSearchOptions)
    search_drafts = FromConfigSearchOptions(
        'RDM_SEARCH_DRAFTS', search_option_cls=RDMSearchDraftsOptions)
    search_versions = FromConfigSearchOptions(
        'RDM_SEARCH_VERSIONING', search_option_cls=RDMSearchVersionsOptions)

    # PIDs configuration
    pids_providers = FromConfigPIDsProviders()
    pids_required = FromConfigRequiredPIDs()

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

    # 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}"),
        ),
        "self_doi":
        Link("{+ui}/doi/{+pid_doi}",
             when=is_record_and_has_doi,
             vars=lambda record, vars: vars.update({
                 f"pid_{scheme}": pid["identifier"]
                 for (scheme, pid) in record.pids.items()
             })),
        "doi":
        Link("https://doi.org/{+pid_doi}",
             when=has_doi,
             vars=lambda record, vars: vars.update({
                 f"pid_{scheme}": pid["identifier"]
                 for (scheme, pid) in record.pids.items()
             })),
        'self_iiif_manifest':
        ConditionalLink(cond=is_record,
                        if_=RecordLink("{+api}/iiif/record:{id}/manifest"),
                        else_=RecordLink("{+api}/iiif/draft:{id}/manifest")),
        'self_iiif_sequence':
        ConditionalLink(
            cond=is_record,
            if_=RecordLink("{+api}/iiif/record:{id}/sequence/default"),
            else_=RecordLink("{+api}/iiif/draft:{id}/sequence/default")),
        "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", when=is_record),
        "latest_html":
        RecordLink("{+ui}/records/{id}/latest", when=is_record),
        "draft":
        RecordLink("{+api}/records/{id}/draft", when=is_record),
        "record":
        RecordLink("{+api}/records/{id}", when=is_draft),
        # TODO: record_html temporarily needed for DOI registration, until
        # problems with self_doi has been fixed
        "record_html":
        RecordLink("{+ui}/records/{id}", when=is_draft),
        "publish":
        RecordLink("{+api}/records/{id}/draft/actions/publish", when=is_draft),
        "review":
        RecordLink("{+api}/records/{id}/draft/review", when=is_draft),
        "submit-review":
        RecordLink(
            "{+api}/records/{id}/draft/actions/submit-review",
            when=is_draft_and_has_review,
        ),
        "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")
    }

    links_search_community_records = pagination_links(
        "{+api}/communities/{id}/records{?args*}")