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, ]
class RDMFileDraftServiceConfig(FileServiceConfig, ConfiguratorMixin): """Configuration for draft files.""" record_cls = RDMDraft permission_action_prefix = "draft_" permission_policy_cls = FromConfig("RDM_PERMISSION_POLICY", default=RDMRecordPermissionPolicy) file_links_list = { "self": RecordLink("{+api}/records/{id}/draft/files"), } file_links_item = { "self": FileLink("{+api}/records/{id}/draft/files/{key}"), "content": FileLink("{+api}/records/{id}/draft/files/{key}/content"), "commit": FileLink("{+api}/records/{id}/draft/files/{key}/commit"), # FIXME: should we check if the file is IIIF compatible? # FIXME: filename instead "iiif_canvas": FileLink("{+api}/iiif/draft:{id}/canvas/{key}"), "iiif_base": FileLink("{+api}/iiif/draft:{id}:{key}"), "iiif_info": FileLink("{+api}/iiif/draft:{id}:{key}/info.json"), "iiif_api": FileLink("{+api}/iiif/draft:{id}:{key}/{region=full}" "/{size=full}/{rotation=0}/{quality=default}.{format=png}"), }
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*}")
class Marc21RecordServiceConfig(RecordServiceConfig): """Marc21 record service config.""" # Record class record_cls = Marc21Record # Draft class draft_cls = Marc21Draft # Parent class parent_record_cls = Marc21Parent # Schemas schema = Marc21RecordSchema schema_parent = Marc21ParentSchema # TODO: ussing from invenio-permissions permission_policy_cls = Marc21RecordPermissionPolicy links_search = pagination_links("{+api}/marc21{?args*}") links_search_drafts = pagination_links("{+api}/marc21/draft{?args*}") links_search_versions = pagination_links("{+api}/marc21/{id}/versions{?args*}") components = [ MetadataComponent, AccessComponent, PIDComponent, ] links_item = { "self": ConditionalLink( cond=is_record, if_=RecordLink("{+api}/marc21/{id}"), else_=RecordLink("{+api}/marc21/{id}/draft"), ), "self_html": ConditionalLink( cond=is_record, if_=RecordLink("{+ui}/marc21/{id}"), else_=RecordLink("{+ui}/uploads/{id}"), ), }
class MockFileServiceConfig(FileServiceConfig): """File service configuration.""" record_cls = RecordWithFiles permission_policy_cls = PermissionPolicy file_links_list = { "self": RecordLink("{+api}/mocks/{id}/files"), } file_links_item = { "self": FileLink("{+api}/mocks/{id}/files/{key}"), "content": FileLink("{+api}/mocks/{id}/files/{key}/content"), "commit": FileLink("{+api}/mocks/{id}/files/{key}/commit"), }
class RDMFileDraftServiceConfig(FileServiceConfig): """Configuration for draft files.""" record_cls = RDMDraft permission_action_prefix = "draft_" permission_policy_cls = RDMRecordPermissionPolicy file_links_list = { "self": RecordLink("{+api}/records/{id}/draft/files"), } file_links_item = { "self": FileLink("{+api}/records/{id}/draft/files/{key}"), "content": FileLink("{+api}/records/{id}/draft/files/{key}/content"), "commit": FileLink("{+api}/records/{id}/draft/files/{key}/commit"), }
class RDMFileDraftServiceConfig(FileServiceConfig, ConfiguratorMixin): """Configuration for draft files.""" record_cls = RDMDraft permission_action_prefix = "draft_" permission_policy_cls = FromConfig("RDM_PERMISSION_POLICY", default=RDMRecordPermissionPolicy) file_links_list = { "self": RecordLink("{+api}/records/{id}/draft/files"), } file_links_item = { "self": FileLink("{+api}/records/{id}/draft/files/{key}"), "content": FileLink("{+api}/records/{id}/draft/files/{key}/content"), "commit": FileLink("{+api}/records/{id}/draft/files/{key}/commit"), }
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, }, "unmanaged": { "provider": UnmanagedPIDProvider, "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") }
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() })), "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") }
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 = { "unmanaged": { "provider": UnmanagedPIDProvider, "required": False, "system_managed": False, }, # "doi": { # "provider": DOIDataCitePIDProvider, # "required": True, # "system_managed": True, # }, } pids_providers_clients = {"datacite": DOIDataCiteClient} # Components components = [ MetadataComponent, AccessComponent, DraftFilesComponent, # for the internal `pid` field PIDComponent, # for the `pids` field (external PIDs) ExternalPIDsComponent, ] # 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}"), ), "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"), }