Skip to content

Commit

Permalink
Merge pull request #90 from M3nin0/dev
Browse files Browse the repository at this point in the history
contrib: adding feedback/comments support for marketplace items
  • Loading branch information
M3nin0 authored Apr 18, 2024
2 parents 83e5f3b + 9c765c1 commit 8ffeff7
Show file tree
Hide file tree
Showing 26 changed files with 637 additions and 1 deletion.
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 ###
8 changes: 8 additions & 0 deletions geo_comments/contrib/marketplace/__init__.py
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."""
21 changes: 21 additions & 0 deletions geo_comments/contrib/marketplace/comments/__init__.py
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",
)
12 changes: 12 additions & 0 deletions geo_comments/contrib/marketplace/comments/api.py
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
12 changes: 12 additions & 0 deletions geo_comments/contrib/marketplace/comments/models.py
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
20 changes: 20 additions & 0 deletions geo_comments/contrib/marketplace/comments/resource.py
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
27 changes: 27 additions & 0 deletions geo_comments/contrib/marketplace/comments/schema.py
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
)
27 changes: 27 additions & 0 deletions geo_comments/contrib/marketplace/comments/service.py
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
23 changes: 23 additions & 0 deletions geo_comments/contrib/marketplace/comments/tasks.py
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")
24 changes: 24 additions & 0 deletions geo_comments/contrib/marketplace/feedbacks/__init__.py
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",
)
12 changes: 12 additions & 0 deletions geo_comments/contrib/marketplace/feedbacks/api.py
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
12 changes: 12 additions & 0 deletions geo_comments/contrib/marketplace/feedbacks/models.py
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
20 changes: 20 additions & 0 deletions geo_comments/contrib/marketplace/feedbacks/resource.py
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
27 changes: 27 additions & 0 deletions geo_comments/contrib/marketplace/feedbacks/schema.py
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
)
Loading

0 comments on commit 8ffeff7

Please sign in to comment.