Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 228 additions & 0 deletions site/cds_rdm/administration/committee_approval_enrollments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2026 CERN.
#
# CDS-RDM is free software; you can redistribute it and/or modify it
# under the terms of the GPL-2.0 License; see LICENSE file for more details.

"""Administration views for committee approval communities."""

from flask import request
from invenio_administration.views.base import (
AdminResourceCreateView,
AdminResourceDetailView,
AdminResourceEditView,
AdminResourceListView,
)
from invenio_communities.communities.records.models import CommunityMetadata
from invenio_i18n import lazy_gettext as _

from cds_rdm.committee_approval_enrollments.models import CommitteeApprovalEnrollment


def _community_options(include=None):
"""Return dropdown options for communities not yet enrolled.

``include`` is the id of a community to list even though it is enrolled
(the one being edited).

The option text includes slug, title and UUID so the search box matches
on any of them.
"""
enrolled = {entry.community_id for entry in CommitteeApprovalEnrollment.get_all()}
options = []
for community in CommunityMetadata.query.order_by(CommunityMetadata.slug):
if str(community.id) != include and (
community.id in enrolled or community.is_deleted
):
continue
title = (community.json or {}).get("metadata", {}).get("title", "")
options.append(
{
"id": str(community.id),
"title_l10n": f"{community.slug} — {title} ({community.id})",
}
)
return options


class CommitteeApprovalEnrollmentAdminMixin:
"""Common admin properties."""

api_endpoint = "/committee-approval-enrollments"
resource_config = "committee_approval_enrollments_resource"
pid_path = "id"
# Access is restricted to ``administration-access`` (the base class default).


_form_fields = {
"community_id": {
"order": 1,
"text": _("Community ID"),
"description": _(
"UUID of the community to enrol in the approval workflow "
"(not the slug, as slugs can be renamed)."
),
},
"label": {
"order": 2,
"text": _("Label"),
"description": _("Shown in request buttons/headings, e.g. 'EP approval'."),
},
"committee_name": {
"order": 3,
"text": _("Committee name"),
"description": _("Shown in review-step labels/text, e.g. 'EP Board'."),
},
"referee_group": {
"order": 4,
"text": _("Referee group"),
"description": _(
"Id of the group whose members act as referees, i.e. the CERN "
"e-group name. Must be an existing group."
),
},
"read_only": {
"order": 5,
"text": _("Read only"),
"description": _("Only allow read-only access to the workflow."),
},
"report_number_prefix": {
"order": 6,
"text": _("Report number prefix"),
"description": _("Fixed prefix, e.g. 'CERN-EP'."),
},
"report_number_include_year": {
"order": 7,
"text": _("Include year"),
"description": _("Append the current year after the prefix."),
},
"report_number_counter_digits": {
"order": 8,
"text": _("Counter digits"),
"description": _("Zero-padding width of the counter, e.g. 3 gives '001'."),
},
}


class CommitteeApprovalEnrollmentListView(
CommitteeApprovalEnrollmentAdminMixin, AdminResourceListView
):
"""List view."""

name = "committee-approval-enrollments"
title = _("Committee approval")
menu_label = _("Committee approval")
category = _("Communities")
icon = "check circle"
search_request_headers = {"Accept": "application/vnd.inveniordm.v1+json"}

display_search = True
display_create = True
display_edit = True
display_delete = True

create_view_name = "committee-approval-enrollment-create"

search_config_name = "COMMITTEE_APPROVAL_ENROLLMENTS_SEARCH"
search_facets_config_name = "COMMITTEE_APPROVAL_ENROLLMENTS_FACETS"
search_sort_config_name = "COMMITTEE_APPROVAL_ENROLLMENTS_SORT_OPTIONS"

item_field_list = {
"community_title": {"text": _("Community"), "order": 1, "width": 3},
"community_slug": {"text": _("Slug"), "order": 2, "width": 2},
"label": {"text": _("Label"), "order": 3, "width": 2},
"committee_name": {"text": _("Committee"), "order": 4, "width": 2},
"referee_group_name": {"text": _("Referee group"), "order": 5, "width": 3},
"report_number_prefix": {"text": _("Prefix"), "order": 6, "width": 2},
"read_only": {"text": _("Read only"), "order": 7, "width": 1},
}


class CommitteeApprovalEnrollmentCreateView(
CommitteeApprovalEnrollmentAdminMixin, AdminResourceCreateView
):
"""Create view."""

name = "committee-approval-enrollment-create"
url = "/committee-approval-enrollments/create"
title = _("Enrol community in committee approval")
list_view_name = "committee-approval-enrollments"

@property
def form_fields(self):
"""Form fields, with the community picker populated at request time."""
return {
**_form_fields,
"community_id": {
**_form_fields["community_id"],
"text": _("Community"),
"description": _(
"Search by slug, title or UUID. Communities that are already "
"enrolled are not listed."
),
"options": _community_options(),
"search": True,
"placeholder": _("Select a community"),
},
}


class CommitteeApprovalEnrollmentEditView(
CommitteeApprovalEnrollmentAdminMixin, AdminResourceEditView
):
"""Edit view."""

name = "committee-approval-enrollment-edit"
url = "/committee-approval-enrollments/<pid_value>/edit"
title = _("Edit committee approval community")
list_view_name = "committee-approval-enrollments"

@property
def form_fields(self):
"""Form fields, with the (read-only) community picker for this entry."""
entry = CommitteeApprovalEnrollment.get_by_id(
(request.view_args or {}).get("pid_value")
)
current = str(entry.community_id) if entry else None
return {
**_form_fields,
"community_id": {
**_form_fields["community_id"],
"text": _("Community"),
"description": _("The enrolled community cannot be changed."),
"options": _community_options(include=current),
"search": True,
},
"created": {"order": 9},
"updated": {"order": 10},
}


class CommitteeApprovalEnrollmentDetailView(
CommitteeApprovalEnrollmentAdminMixin, AdminResourceDetailView
):
"""Detail view."""

name = "committee-approval-enrollment-details"
url = "/committee-approval-enrollments/<pid_value>"
title = _("Committee approval community")
list_view_name = "committee-approval-enrollments"
display_edit = True
display_delete = True
request_headers = {"Accept": "application/vnd.inveniordm.v1+json"}

item_field_list = {
"community_id": {"text": _("Community ID"), "order": 1},
"community_title": {"text": _("Community"), "order": 2},
"community_slug": {"text": _("Slug"), "order": 3},
"label": {"text": _("Label"), "order": 4},
"committee_name": {"text": _("Committee name"), "order": 5},
"referee_group_name": {"text": _("Referee group"), "order": 6},
"read_only": {"text": _("Read only"), "order": 7},
"report_number_prefix": {"text": _("Report number prefix"), "order": 8},
"report_number_include_year": {"text": _("Include year"), "order": 9},
"report_number_counter_digits": {"text": _("Counter digits"), "order": 10},
"created": {"text": _("Created"), "order": 11},
"updated": {"text": _("Updated"), "order": 12},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2026 CERN.
#
# CDS-RDM is free software; you can redistribute it and/or modify it
# under the terms of the GPL-2.0 License; see LICENSE file for more details.

"""Create committee approval enrollment table."""

import sqlalchemy as sa
import sqlalchemy_utils
from alembic import op

# revision identifiers, used by Alembic.
revision = "1778000000"
down_revision = "1771314900"
branch_labels = ()
depends_on = "de9c14cbb0b2" # invenio-communities: communities tables


def upgrade():
"""Upgrade database."""
op.create_table(
"cds_committee_approval_enrollment",
sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False),
sa.Column(
"community_id",
sqlalchemy_utils.types.uuid.UUIDType(),
nullable=False,
comment="The enrolled community",
),
sa.Column(
"label",
sa.String(length=255),
nullable=False,
comment="Workflow label shown in the UI, e.g. 'EP approval'",
),
sa.Column(
"committee_name",
sa.String(length=255),
nullable=True,
comment="Reviewer/board name shown in review-step labels, e.g. 'EP Board'",
),
sa.Column(
"referee_group",
sa.String(length=80),
nullable=False,
comment="Id of the group (role) whose members act as referees",
),
sa.Column(
"read_only",
sa.Boolean(),
nullable=False,
comment="Only allow read-only access to the workflow in this community",
),
sa.Column(
"report_number_prefix",
sa.String(length=255),
nullable=False,
comment="Fixed prefix, e.g. 'CERN-EP'",
),
sa.Column(
"report_number_include_year",
sa.Boolean(),
nullable=False,
comment="Append the current year after the prefix",
),
sa.Column(
"report_number_counter_digits",
sa.Integer(),
nullable=False,
comment="Zero-padding width of the counter",
),
sa.Column(
"created",
sa.DateTime(timezone=True),
nullable=False,
),
sa.Column(
"updated",
sa.DateTime(timezone=True),
nullable=False,
),
sa.ForeignKeyConstraint(
["community_id"],
["communities_metadata.id"],
name=op.f("fk_cds_committee_approval_enrollment_community_id_commu_d461"),
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
["referee_group"],
["accounts_role.id"],
name=op.f("fk_cds_committee_approval_enrollment_referee_group_acco_7c22"),
ondelete="RESTRICT",
),
sa.PrimaryKeyConstraint(
"id", name=op.f("pk_cds_committee_approval_enrollment")
),
sa.UniqueConstraint(
"community_id",
name=op.f("uq_cds_committee_approval_enrollment_community_id"),
),
)


def downgrade():
"""Downgrade database."""
op.drop_table("cds_committee_approval_enrollment")
Loading
Loading