Skip to content

Commit

Permalink
Merge pull request #195 from M3nin0/marketplace
Browse files Browse the repository at this point in the history
marketplace: enabling file services
  • Loading branch information
M3nin0 authored Feb 21, 2024
2 parents 8567895 + 446b9b3 commit da9b0bd
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 7 deletions.
20 changes: 18 additions & 2 deletions geo_rdm_records/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
from invenio_records_resources.services import FileService

from . import config
from .modules.marketplace.resources.config import GEOMarketplaceItemResourceConfig
from .modules.marketplace.resources.config import (
GEOMarketplaceItemDraftResourceConfig,
GEOMarketplaceItemFilesResourceConfig,
GEOMarketplaceItemResourceConfig,
)
from .modules.marketplace.resources.resource import GEOMarketplaceItemResource
from .modules.marketplace.services.config import (
GEOMarketplaceItemDraftFileServiceConfig,
Expand Down Expand Up @@ -122,7 +126,7 @@ def init_services(self, app):
# Marketplace item
self.service_marketplace = GEOMarketplaceItemService(
config=service_configs.marketplace_item,
files_service=FileService(service_configs.marketplace_item),
files_service=FileService(service_configs.marketplace_file),
draft_files_service=FileService(service_configs.marketplace_file_draft),
)

Expand Down Expand Up @@ -166,3 +170,15 @@ def init_resource(self, app):
service=self.service_marketplace,
config=GEOMarketplaceItemResourceConfig.build(app),
)

# Marketplace - Files
self.marketplace_files_resource = FileResource(
service=self.service_marketplace.files,
config=GEOMarketplaceItemFilesResourceConfig.build(app),
)

# Marketplace - Draft files
self.marketplace_draft_files_resource = FileResource(
service=self.service_marketplace.draft_files,
config=GEOMarketplaceItemDraftResourceConfig.build(app),
)
26 changes: 26 additions & 0 deletions geo_rdm_records/modules/marketplace/resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,29 @@ class GEOMarketplaceItemResourceConfig(BaseGEOResourceConfig):

# Response handlers
response_handlers = record_serializers


#
# Marketplace Item files
#
class GEOMarketplaceItemFilesResourceConfig(
rdm_resources_config.RDMRecordFilesResourceConfig
):
"""Files for marketplace items."""

allow_upload = False

blueprint_name = "marketplace-item-files"
url_prefix = "/marketplace/items/<pid_value>"


#
# Marketplace Item Draft files
#
class GEOMarketplaceItemDraftResourceConfig(
rdm_resources_config.RDMDraftFilesResourceConfig
):
"""Files for marketplace items (draft)."""

blueprint_name = "marketplace-items-draft-files"
url_prefix = "/marketplace/items/<pid_value>/draft"
6 changes: 2 additions & 4 deletions geo_rdm_records/modules/marketplace/services/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from invenio_records_resources.services import ConditionalLink
from invenio_records_resources.services.base.config import FromConfig
from invenio_records_resources.services.files.links import FileLink
from invenio_records_resources.services.records.links import RecordLink

from geo_rdm_records.base.services.config import BaseGEOServiceConfig
from geo_rdm_records.base.services.links import LinksRegistryType
Expand All @@ -42,7 +43,6 @@
from geo_rdm_records.modules.marketplace.services.permissions import (
MarketplacePermissionPolicy,
)
from geo_rdm_records.modules.packages.services.links import RecordLink


class GEOMarketplaceServiceConfig(BaseGEOServiceConfig):
Expand Down Expand Up @@ -128,9 +128,7 @@ class GEOMarketplaceServiceConfig(BaseGEOServiceConfig):
),
"draft": RecordLink("{+api}/marketplace/items/{id}/draft", when=is_record),
"record": RecordLink("{+api}/marketplace/items/{id}", when=is_draft),
# TODO: record_html temporarily needed for DOI registration, until
# problems with self_doi has been fixed
# "record_html": RecordLink("{+ui}/marketplace/items/{id}", when=is_draft),
"record_html": RecordLink("{+ui}/marketplace/items/{id}", when=is_draft),
"publish": RecordLink(
"{+api}/marketplace/items/{id}/draft/actions/publish", when=is_draft
),
Expand Down
4 changes: 4 additions & 0 deletions geo_rdm_records/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
blueprint,
create_draft_files_api_blueprint,
create_marketplace_api_blueprint,
create_marketplace_draft_files_api_blueprint,
create_marketplace_files_api_blueprint,
create_packages_api_blueprint,
create_packages_context_api_blueprint,
create_packages_files_api_blueprint,
Expand All @@ -29,6 +31,8 @@
"create_search_records_api_blueprint",
"create_packages_context_api_blueprint",
"create_marketplace_api_blueprint",
"create_marketplace_files_api_blueprint",
"create_marketplace_draft_files_api_blueprint",
# UI
"create_ui_blueprint",
)
22 changes: 21 additions & 1 deletion geo_rdm_records/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ def init(state):
idx_ext = app.extensions["invenio-indexer"]
ext = app.extensions["geo-rdm-records"]

# services
# services - packages
rr_ext.registry.register(ext.service, service_id="records_package")
rr_ext.registry.register(ext.service.files, service_id="files_package")
rr_ext.registry.register(ext.service.draft_files, service_id="files_package_draft")

# services - marketplace
rr_ext.registry.register(ext.service_marketplace, service_id="marketplace_items")
rr_ext.registry.register(
ext.service_marketplace.files, service_id="files_marketplace"
)
rr_ext.registry.register(
ext.service_marketplace.draft_files, service_id="files_marketplace_draft"
)

# indexers
idx_ext.registry.register(ext.service.indexer, indexer_id="records_packages")
Expand Down Expand Up @@ -75,3 +83,15 @@ def create_marketplace_api_blueprint(app):
"""Create Marketplace blueprint."""
ext = app.extensions["geo-rdm-records"]
return ext.marketplace_resource.as_blueprint()


def create_marketplace_files_api_blueprint(app):
"""Create marketplace files api blueprint."""
ext = app.extensions["geo-rdm-records"]
return ext.marketplace_files_resource.as_blueprint()


def create_marketplace_draft_files_api_blueprint(app):
"""Create marketplace draft files blueprint."""
ext = app.extensions["geo-rdm-records"]
return ext.marketplace_draft_files_resource.as_blueprint()
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ invenio_base.api_blueprints =
geo_rdm_records_search = geo_rdm_records.views:create_search_records_api_blueprint
geo_rdm_records_packages_context = geo_rdm_records.views:create_packages_context_api_blueprint
geo_rdm_records_marketplace = geo_rdm_records.views:create_marketplace_api_blueprint
geo_rdm_records_marketplace_files = geo_rdm_records.views:create_marketplace_files_api_blueprint
geo_rdm_records_marketplace_draft_files = geo_rdm_records.views:create_marketplace_draft_files_api_blueprint
invenio_base.blueprints =
geo_rdm_records_packages_ext = geo_rdm_records.views:blueprint
geo_rdm_records = geo_rdm_records.views:create_ui_blueprint
Expand Down

0 comments on commit da9b0bd

Please sign in to comment.