diff --git a/geo_comments/alembic/21e0095448da_create_marketplace_comments_feedback_.py b/geo_comments/alembic/21e0095448da_create_marketplace_comments_feedback_.py new file mode 100644 index 0000000..954b23a --- /dev/null +++ b/geo_comments/alembic/21e0095448da_create_marketplace_comments_feedback_.py @@ -0,0 +1,138 @@ +# +# This file is part of Invenio. +# Copyright (C) 2016-2018 CERN. +# +# Invenio is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Create marketplace comments/feedback tables.""" + +import sqlalchemy as sa +import sqlalchemy_utils +from alembic import op +from sqlalchemy.dialects import mysql, postgresql + +# revision identifiers, used by Alembic. +revision = "21e0095448da" +down_revision = "9ee00acd3274" +branch_labels = () +depends_on = None + + +def upgrade(): + """Upgrade database.""" + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "marketplacecomment_metadata", + sa.Column( + "created", + sa.DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql"), + nullable=False, + ), + sa.Column( + "updated", + sa.DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql"), + nullable=False, + ), + sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), + sa.Column( + "json", + sa.JSON() + .with_variant(sqlalchemy_utils.types.json.JSONType(), "mysql") + .with_variant( + postgresql.JSONB(none_as_null=True, astext_type=sa.Text()), "postgresql" + ) + .with_variant(sqlalchemy_utils.types.json.JSONType(), "sqlite"), + nullable=True, + ), + sa.Column("version_id", sa.Integer(), nullable=False), + sa.Column("user", sa.Integer(), nullable=True), + sa.Column("record", sqlalchemy_utils.types.uuid.UUIDType(), nullable=True), + sa.Column("status", sa.String(), nullable=True), + sa.ForeignKeyConstraint( + ["record"], + ["geo_marketplace_items_metadata.id"], + name=op.f( + "fk_marketplacecomment_metadata_record_geo_marketplace_items_metadata" + ), + ), + sa.ForeignKeyConstraint( + ["user"], + ["accounts_user.id"], + name=op.f("fk_marketplacecomment_metadata_user_accounts_user"), + ), + sa.PrimaryKeyConstraint("id", name=op.f("pk_marketplacecomment_metadata")), + ) + op.create_table( + "marketplacefeedback_metadata", + sa.Column( + "created", + sa.DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql"), + nullable=False, + ), + sa.Column( + "updated", + sa.DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql"), + nullable=False, + ), + sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), + sa.Column( + "json", + sa.JSON() + .with_variant(sqlalchemy_utils.types.json.JSONType(), "mysql") + .with_variant( + postgresql.JSONB(none_as_null=True, astext_type=sa.Text()), "postgresql" + ) + .with_variant(sqlalchemy_utils.types.json.JSONType(), "sqlite"), + nullable=True, + ), + sa.Column("version_id", sa.Integer(), nullable=False), + sa.Column("user", sa.Integer(), nullable=True), + sa.Column("record", sqlalchemy_utils.types.uuid.UUIDType(), nullable=True), + sa.Column("status", sa.String(), nullable=True), + sa.ForeignKeyConstraint( + ["record"], + ["geo_marketplace_items_metadata.id"], + name=op.f( + "fk_marketplacefeedback_metadata_record_geo_marketplace_items_metadata" + ), + ), + sa.ForeignKeyConstraint( + ["user"], + ["accounts_user.id"], + name=op.f("fk_marketplacefeedback_metadata_user_accounts_user"), + ), + sa.PrimaryKeyConstraint("id", name=op.f("pk_marketplacefeedback_metadata")), + sa.UniqueConstraint( + "user", "record", name=op.f("uq_marketplacefeedback_metadata_user") + ), + ) + op.alter_column( + "files_objecttags", + "key", + existing_type=sa.TEXT(), + type_=sa.String(length=255), + existing_nullable=False, + ) + op.alter_column( + "records_metadata_version", + "json", + existing_type=postgresql.JSON(astext_type=sa.Text()), + type_=sa.JSON() + .with_variant(sqlalchemy_utils.types.json.JSONType(), "mysql") + .with_variant( + postgresql.JSONB(none_as_null=True, astext_type=sa.Text()), "postgresql" + ) + .with_variant(sqlalchemy_utils.types.json.JSONType(), "sqlite"), + existing_nullable=True, + autoincrement=False, + ) + # ### end Alembic commands ### + + +def downgrade(): + """Downgrade database.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table("marketplacefeedback_metadata") + op.drop_table("marketplacecomment_metadata") + # ### end Alembic commands ### diff --git a/geo_comments/contrib/marketplace/__init__.py b/geo_comments/contrib/marketplace/__init__.py new file mode 100644 index 0000000..dc59d32 --- /dev/null +++ b/geo_comments/contrib/marketplace/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2024 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""GEO Comments contrib module to support comments/feedback in Marketplace entities.""" diff --git a/geo_comments/contrib/marketplace/comments/__init__.py b/geo_comments/contrib/marketplace/comments/__init__.py new file mode 100644 index 0000000..ade0b31 --- /dev/null +++ b/geo_comments/contrib/marketplace/comments/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""GEO Comments contrib module to support comments in the Marketplace API.""" + +from .resource import ( + MarketplaceItemCommentResource, + MarketplaceItemCommentResourceConfig, +) +from .service import MarketplaceItemCommentService, MarketplaceItemCommentServiceConfig + +__all__ = ( + "MarketplaceItemCommentResource", + "MarketplaceItemCommentResourceConfig", + "MarketplaceItemCommentService", + "MarketplaceItemCommentServiceConfig", +) diff --git a/geo_comments/contrib/marketplace/comments/api.py b/geo_comments/contrib/marketplace/comments/api.py new file mode 100644 index 0000000..1408eb6 --- /dev/null +++ b/geo_comments/contrib/marketplace/comments/api.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""API for the Marketplace Items API contrib.""" + +from ..marketplace import marketplace_comments + +MarketplaceItemComment = marketplace_comments.comment_cls diff --git a/geo_comments/contrib/marketplace/comments/models.py b/geo_comments/contrib/marketplace/comments/models.py new file mode 100644 index 0000000..f717fc1 --- /dev/null +++ b/geo_comments/contrib/marketplace/comments/models.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Data Model for the Marketplace Items API contrib.""" + +from ..marketplace import marketplace_comments + +MarketplaceItemCommentMetadata = marketplace_comments.model_cls diff --git a/geo_comments/contrib/marketplace/comments/resource.py b/geo_comments/contrib/marketplace/comments/resource.py new file mode 100644 index 0000000..9767eb1 --- /dev/null +++ b/geo_comments/contrib/marketplace/comments/resource.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Resource for the Marketplace Items API contrib.""" + +from ..marketplace import marketplace_comments + +# +# Resource +# +MarketplaceItemCommentResource = marketplace_comments.resource_cls + +# +# Configuration +# +MarketplaceItemCommentResourceConfig = marketplace_comments.resource_config_cls diff --git a/geo_comments/contrib/marketplace/comments/schema.py b/geo_comments/contrib/marketplace/comments/schema.py new file mode 100644 index 0000000..2d49072 --- /dev/null +++ b/geo_comments/contrib/marketplace/comments/schema.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Service schema.""" + +from marshmallow import fields + +from geo_comments.comments.schema import CommentSchema as BaseCommentSchema +from geo_comments.comments.schema import generate_permission_schema_document +from geo_comments.proxies import current_comments + + +class CommentSchema(BaseCommentSchema): + """Comment schema class.""" + + permissions = fields.Method("get_permissions", dump_only=True) + + def get_permissions(self, obj): + """Return permissions to act on comments or empty dict.""" + service = current_comments.package_comment_service + return generate_permission_schema_document( + self.context["identity"], service, obj + ) diff --git a/geo_comments/contrib/marketplace/comments/service.py b/geo_comments/contrib/marketplace/comments/service.py new file mode 100644 index 0000000..368475d --- /dev/null +++ b/geo_comments/contrib/marketplace/comments/service.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Service for the Marketplace Item API contrib.""" + +from ..marketplace import marketplace_comments +from .schema import CommentSchema + +# +# Service +# +MarketplaceItemCommentService = marketplace_comments.comment_service_cls + + +# +# Configuration +# +class MarketplaceItemCommentServiceConfig( + marketplace_comments.comment_service_cls_config +): + """Service configuration class.""" + + schema = CommentSchema diff --git a/geo_comments/contrib/marketplace/comments/tasks.py b/geo_comments/contrib/marketplace/comments/tasks.py new file mode 100644 index 0000000..e8db0e6 --- /dev/null +++ b/geo_comments/contrib/marketplace/comments/tasks.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Marketplace Items feedback service tasks.""" + +from celery import shared_task +from geo_rdm_records.proxies import current_marketplace_service + +from geo_comments.comments.services.notification import notify_comments +from geo_comments.proxies import current_comments + + +@shared_task +def send_notification_email(): + """Send background email.""" + record_service = current_marketplace_service + comment_service = current_comments.package_comment_service + + notify_comments(record_service, comment_service, "package", "comment") diff --git a/geo_comments/contrib/marketplace/feedbacks/__init__.py b/geo_comments/contrib/marketplace/feedbacks/__init__.py new file mode 100644 index 0000000..310ef4d --- /dev/null +++ b/geo_comments/contrib/marketplace/feedbacks/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""GEO Comments contrib module to support feedback in the Marketplace API.""" + +from .resource import ( + MarketplaceItemFeedbackResource, + MarketplaceItemFeedbackResourceConfig, +) +from .service import ( + MarketplaceItemFeedbackService, + MarketplaceItemFeedbackServiceConfig, +) + +__all__ = ( + "MarketplaceItemFeedbackResource", + "MarketplaceItemFeedbackResourceConfig", + "MarketplaceItemFeedbackService", + "MarketplaceItemFeedbackServiceConfig", +) diff --git a/geo_comments/contrib/marketplace/feedbacks/api.py b/geo_comments/contrib/marketplace/feedbacks/api.py new file mode 100644 index 0000000..1a5ae6d --- /dev/null +++ b/geo_comments/contrib/marketplace/feedbacks/api.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""API for the Marketplace Items API contrib.""" + +from ..marketplace import marketplace_feedback + +MarketplaceItemFeedback = marketplace_feedback.comment_cls diff --git a/geo_comments/contrib/marketplace/feedbacks/models.py b/geo_comments/contrib/marketplace/feedbacks/models.py new file mode 100644 index 0000000..2f37280 --- /dev/null +++ b/geo_comments/contrib/marketplace/feedbacks/models.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Data Model for the Marketplace Items API contrib.""" + +from ..marketplace import marketplace_feedback + +MarketplaceItemFeedbackMetadata = marketplace_feedback.model_cls diff --git a/geo_comments/contrib/marketplace/feedbacks/resource.py b/geo_comments/contrib/marketplace/feedbacks/resource.py new file mode 100644 index 0000000..3dd303e --- /dev/null +++ b/geo_comments/contrib/marketplace/feedbacks/resource.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Resource for the Marketplace Items API contrib.""" + +from ..marketplace import marketplace_feedback + +# +# Resource +# +MarketplaceItemFeedbackResource = marketplace_feedback.resource_cls + +# +# Configuration +# +MarketplaceItemFeedbackResourceConfig = marketplace_feedback.resource_config_cls diff --git a/geo_comments/contrib/marketplace/feedbacks/schema.py b/geo_comments/contrib/marketplace/feedbacks/schema.py new file mode 100644 index 0000000..33fecdf --- /dev/null +++ b/geo_comments/contrib/marketplace/feedbacks/schema.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Service schema.""" + +from marshmallow import fields + +from geo_comments.comments.schema import FeedbackCommentSchema as BaseCommentSchema +from geo_comments.comments.schema import generate_permission_schema_document +from geo_comments.proxies import current_comments + + +class FeedbackCommentSchema(BaseCommentSchema): + """Comment schema class.""" + + permissions = fields.Method("get_permissions", dump_only=True) + + def get_permissions(self, obj): + """Return permissions to act on comments or empty dict.""" + service = current_comments.package_feedback_service + return generate_permission_schema_document( + self.context["identity"], service, obj + ) diff --git a/geo_comments/contrib/marketplace/feedbacks/service.py b/geo_comments/contrib/marketplace/feedbacks/service.py new file mode 100644 index 0000000..abc6ed9 --- /dev/null +++ b/geo_comments/contrib/marketplace/feedbacks/service.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Service for the Marketplace Item API contrib.""" + +from ..marketplace import marketplace_feedback +from .schema import FeedbackCommentSchema + +# +# Service +# +MarketplaceItemFeedbackService = marketplace_feedback.comment_service_cls + + +# +# Configuration +# +class MarketplaceItemFeedbackServiceConfig( + marketplace_feedback.comment_service_cls_config +): + """Service configuration class.""" + + schema = FeedbackCommentSchema diff --git a/geo_comments/contrib/marketplace/feedbacks/tasks.py b/geo_comments/contrib/marketplace/feedbacks/tasks.py new file mode 100644 index 0000000..6256864 --- /dev/null +++ b/geo_comments/contrib/marketplace/feedbacks/tasks.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Marketplace Items feedback service tasks.""" + +from celery import shared_task +from geo_rdm_records.proxies import current_marketplace_service + +from geo_comments.comments.services.notification import notify_comments +from geo_comments.proxies import current_comments + + +@shared_task +def send_notification_email(): + """Send background email.""" + record_service = current_marketplace_service + comment_service = current_comments.package_feedback_service + + notify_comments( + record_service, comment_service, "marketplace-item", "feedback message" + ) diff --git a/geo_comments/contrib/marketplace/marketplace.py b/geo_comments/contrib/marketplace/marketplace.py new file mode 100644 index 0000000..67a0f61 --- /dev/null +++ b/geo_comments/contrib/marketplace/marketplace.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Contrib - comments and feedback for Marketplace Items API.""" + +from geo_rdm_records.modules.marketplace.records.api import GEOMarketplaceItem +from geo_rdm_records.modules.marketplace.records.models import ( + GEOMarketplaceItemMetadata, +) + +from geo_comments.factories import CommentTypeFactory, FeedbackTypeFactory + +from .systemfield import RecordEntity + +# +# Comment +# +marketplace_comments = CommentTypeFactory( + comment_type_name="MarketplaceComment", + comment_record_type_name="marketplace-item", + comment_record_entity_cls=RecordEntity, + comment_associated_record_cls=GEOMarketplaceItem, + comment_associated_metadata_cls=GEOMarketplaceItemMetadata, + comment_service_id="marketplace_item_comments", + comment_service_name="MarketplaceItemComments", + comment_service_endpoint_route="/comments", + comment_service_endpoint_route_prefix="/marketplace/items", +) + +# +# Feedback +# +marketplace_feedback = FeedbackTypeFactory( + comment_type_name="MarketplaceFeedback", + comment_record_type_name="marketplace-item", + comment_record_entity_cls=RecordEntity, + comment_associated_record_cls=GEOMarketplaceItem, + comment_associated_metadata_cls=GEOMarketplaceItemMetadata, + comment_service_id="marketplace_item_feedback", + comment_service_name="MarketplaceItemFeedback", + comment_service_endpoint_route="/feedback", + comment_service_endpoint_route_prefix="/marketplace/items", +) diff --git a/geo_comments/contrib/marketplace/systemfield.py b/geo_comments/contrib/marketplace/systemfield.py new file mode 100644 index 0000000..accc683 --- /dev/null +++ b/geo_comments/contrib/marketplace/systemfield.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2021-2022 Geo Secretariat. +# +# geo-comments is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Contrib - System field for marketplace comments and feedback.""" + +from geo_rdm_records.modules.marketplace.records.api import GEOMarketplaceItem + +from geo_comments.comments.records.systemfields.models import BaseRecordEntity + + +class RecordEntity(BaseRecordEntity): + """Record entity abstraction class (for Marketplace Items).""" + + entity_cls = GEOMarketplaceItem + """Record entity class.""" diff --git a/geo_comments/ext.py b/geo_comments/ext.py index b9699d2..c56acc2 100644 --- a/geo_comments/ext.py +++ b/geo_comments/ext.py @@ -8,6 +8,18 @@ """Comments module for GEO Knowledge Hub.""" from geo_comments import config +from geo_comments.contrib.marketplace.comments import ( + MarketplaceItemCommentResource, + MarketplaceItemCommentResourceConfig, + MarketplaceItemCommentService, + MarketplaceItemCommentServiceConfig, +) +from geo_comments.contrib.marketplace.feedbacks import ( + MarketplaceItemFeedbackResource, + MarketplaceItemFeedbackResourceConfig, + MarketplaceItemFeedbackService, + MarketplaceItemFeedbackServiceConfig, +) from geo_comments.contrib.packages.comments import ( PackageCommentResource, PackageCommentResourceConfig, @@ -72,6 +84,13 @@ def init_services(self, app): config=ResourceFeedbackServiceConfig ) + self.marketplace_item_comment_service = MarketplaceItemCommentService( + config=MarketplaceItemCommentServiceConfig + ) + self.marketplace_item_feedback_service = MarketplaceItemFeedbackService( + config=MarketplaceItemFeedbackServiceConfig + ) + def init_resources(self, app): """Initialize the resources.""" self.package_comment_resource = PackageCommentResource( @@ -88,3 +107,12 @@ def init_resources(self, app): service=self.resource_feedback_service, config=ResourceFeedbackResourceConfig, ) + + self.marketplace_item_comment_resource = MarketplaceItemCommentResource( + service=self.marketplace_item_comment_service, + config=MarketplaceItemCommentResourceConfig, + ) + self.marketplace_item_feedback_resource = MarketplaceItemFeedbackResource( + service=self.marketplace_item_feedback_service, + config=MarketplaceItemFeedbackResourceConfig, + ) diff --git a/geo_comments/views/__init__.py b/geo_comments/views/__init__.py index 82e566f..f6aa117 100644 --- a/geo_comments/views/__init__.py +++ b/geo_comments/views/__init__.py @@ -21,22 +21,42 @@ def init(state): # Register services - cannot be done in extension because sregistry = app.extensions["invenio-records-resources"].registry + # Packages sregistry.register(ext.package_comment_service, service_id="package_comment") sregistry.register(ext.package_feedback_service, service_id="package_feedback") + # Resources sregistry.register(ext.resource_comment_service, service_id="resource_comment") sregistry.register(ext.resource_feedback_service, service_id="resource_feedback") + # Marketplace + sregistry.register( + ext.marketplace_item_comment_service, service_id="marketplace_item_comment" + ) + sregistry.register( + ext.marketplace_item_feedback_service, service_id="marketplace_item_feedback" + ) # Register indexers iregistry = app.extensions["invenio-indexer"].registry + # Packages iregistry.register( ext.package_comment_service.indexer, indexer_id="package_comment" ) iregistry.register( ext.package_feedback_service.indexer, indexer_id="package_feedback" ) + # Resources iregistry.register( ext.resource_comment_service.indexer, indexer_id="resource_comment" ) iregistry.register( ext.resource_feedback_service.indexer, indexer_id="resource_feedback" ) + # Marketplace + iregistry.register( + ext.marketplace_item_comment_service.indexer, + indexer_id="marketplace_item_comment", + ) + iregistry.register( + ext.marketplace_item_feedback_service.indexer, + indexer_id="marketplace_item_feedback", + ) diff --git a/geo_comments/views/api.py b/geo_comments/views/api.py index a27c0fc..f34161f 100644 --- a/geo_comments/views/api.py +++ b/geo_comments/views/api.py @@ -34,3 +34,17 @@ def create_resource_feedback_api_blueprint(app): ext = app.extensions["geo-comments"] return ext.resource_feedback_resource.as_blueprint() + + +def create_marketplace_item_comment_api_blueprint(app): + """Create the Package's resource comments API Blueprint.""" + ext = app.extensions["geo-comments"] + + return ext.marketplace_item_comment_resource.as_blueprint() + + +def create_marketplace_item_feedback_api_blueprint(app): + """Create the Package's resource feedbacks API Blueprint.""" + ext = app.extensions["geo-comments"] + + return ext.marketplace_item_feedback_resource.as_blueprint() diff --git a/setup.cfg b/setup.cfg index 00e7884..9f68160 100644 --- a/setup.cfg +++ b/setup.cfg @@ -75,6 +75,8 @@ invenio_base.api_blueprints = geo_comments_package_feedback = geo_comments.views.api:create_package_feedback_api_blueprint geo_comments_resource_comment = geo_comments.views.api:create_resource_comment_api_blueprint geo_comments_resource_feedback = geo_comments.views.api:create_resource_feedback_api_blueprint + geo_comments_marketplace_item_comment = geo_comments.views.api:create_marketplace_item_comment_api_blueprint + geo_comments_marketplace_item_feedback = geo_comments.views.api:create_marketplace_item_feedback_api_blueprint geo_comments_ext = geo_comments.views:blueprint invenio_i18n.translations = messages = geo_comments @@ -94,6 +96,8 @@ invenio_celery.tasks = geo_comments_package_feedback = geo_comments.contrib.packages.feedbacks.tasks.send_notification_email geo_comments_resource_comment = geo_comments.contrib.resources.comments.tasks.send_notification_email geo_comments_resource_feedback = geo_comments.contrib.resources.feedbacks.tasks.send_notification_email + geo_comments_marketplace_item_comment = geo_comments.contrib.marketplace.comments.tasks.send_notification_email + geo_comments_marketplace_item_feedback = geo_comments.contrib.marketplace.feedbacks.tasks.send_notification_email invenio_assets.webpack = geo_comments = geo_comments.webpack:theme invenio_db.alembic = diff --git a/tests/conftest.py b/tests/conftest.py index c747ff8..97efa74 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,9 +11,13 @@ from flask_principal import Identity, RoleNeed, UserNeed from flask_security import login_user from flask_security.utils import hash_password +from geo_rdm_records.modules.marketplace.records.api import GEOMarketplaceItem from geo_rdm_records.modules.packages.records.api import GEOPackageRecord from geo_rdm_records.modules.rdm.records.api import GEORecord -from geo_rdm_records.proxies import current_geo_packages_service +from geo_rdm_records.proxies import ( + current_geo_packages_service, + current_marketplace_service, +) from invenio_access.models import ActionRoles from invenio_access.permissions import ( any_user, @@ -317,3 +321,18 @@ def record_package_simple( ) return GEOPackageRecord.pid.resolve(record_item["id"]) + + +@pytest.fixture(scope="module") +def record_marketplace_item_simple( + location, resource_type_v, authenticated_identity, minimal_record +): + """Basic Package Record.""" + record_item = current_marketplace_service.create( + authenticated_identity, minimal_record + ) + record_item = current_marketplace_service.publish( + authenticated_identity, record_item["id"] + ) + + return GEOMarketplaceItem.pid.resolve(record_item["id"]) diff --git a/tests/contrib/records/test_api.py b/tests/contrib/records/test_api.py index d3a8fea..a160977 100644 --- a/tests/contrib/records/test_api.py +++ b/tests/contrib/records/test_api.py @@ -13,6 +13,8 @@ from sqlalchemy.exc import NoResultFound from geo_comments.comments.records.api import CommentStatus +from geo_comments.contrib.marketplace.comments.api import MarketplaceItemComment +from geo_comments.contrib.marketplace.feedbacks.api import MarketplaceItemFeedback from geo_comments.contrib.packages.comments.api import PackageComment from geo_comments.contrib.packages.feedbacks.api import PackageFeedback from geo_comments.contrib.resources.comments.api import ResourceComment @@ -42,6 +44,16 @@ lazy_fixture("feedback_record_data"), ResourceFeedback, ), + ( + lazy_fixture("record_marketplace_item_simple"), + lazy_fixture("comment_record_data"), + MarketplaceItemComment, + ), + ( + lazy_fixture("record_marketplace_item_simple"), + lazy_fixture("feedback_record_data"), + MarketplaceItemFeedback, + ), ], ) def test_api_basic_commenting_workflow(users, record, comment_content, comment_cls): diff --git a/tests/contrib/resources/test_resource.py b/tests/contrib/resources/test_resource.py index 0c89f54..5e3acc1 100644 --- a/tests/contrib/resources/test_resource.py +++ b/tests/contrib/resources/test_resource.py @@ -11,6 +11,8 @@ from pytest_lazyfixture import lazy_fixture from geo_comments.comments.records.api import CommentStatus +from geo_comments.contrib.marketplace.comments.api import MarketplaceItemComment +from geo_comments.contrib.marketplace.feedbacks.api import MarketplaceItemFeedback from geo_comments.contrib.packages.comments.api import PackageComment from geo_comments.contrib.packages.feedbacks.api import PackageFeedback from geo_comments.contrib.resources.comments.api import ResourceComment @@ -56,6 +58,24 @@ True, True, ), + ( + "/marketplace/items", + "/comments", + MarketplaceItemComment, + lazy_fixture("record_marketplace_item_simple"), + lazy_fixture("comment_record_data"), + False, + False, + ), + ( + "/marketplace/items", + "/feedback", + MarketplaceItemFeedback, + lazy_fixture("record_marketplace_item_simple"), + lazy_fixture("feedback_record_data"), + True, + True, + ), ], ) def test_resource_basic_commenting_workflow( diff --git a/tests/contrib/services/test_service.py b/tests/contrib/services/test_service.py index ca051fa..6119d52 100644 --- a/tests/contrib/services/test_service.py +++ b/tests/contrib/services/test_service.py @@ -12,6 +12,8 @@ from pytest_lazyfixture import lazy_fixture from geo_comments.comments.records.api import CommentStatus +from geo_comments.contrib.marketplace.comments.api import MarketplaceItemComment +from geo_comments.contrib.marketplace.feedbacks.api import MarketplaceItemFeedback from geo_comments.contrib.packages.comments.api import PackageComment from geo_comments.contrib.packages.feedbacks.api import PackageFeedback from geo_comments.contrib.resources.comments.api import ResourceComment @@ -53,6 +55,22 @@ True, True, ), + ( + "marketplace_item_comment", + MarketplaceItemComment, + lazy_fixture("record_marketplace_item_simple"), + lazy_fixture("comment_record_data"), + False, + False, + ), + ( + "marketplace_item_feedback", + MarketplaceItemFeedback, + lazy_fixture("record_marketplace_item_simple"), + lazy_fixture("feedback_record_data"), + True, + True, + ), ], ) def test_service_basic_commenting_workflow(