-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from M3nin0/dev
contrib: adding feedback/comments support for marketplace items
- Loading branch information
Showing
26 changed files
with
637 additions
and
1 deletion.
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
geo_comments/alembic/21e0095448da_create_marketplace_comments_feedback_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
Oops, something went wrong.