Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ChecksComponent #17

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 1 addition & 4 deletions invenio_checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ def load_from_entry_points(self, app, ep_name):
"""Load checks from entry points."""
for ep in set(importlib_metadata.entry_points(group=ep_name)):
check_cls_or_func = ep.load()
if callable(check_cls_or_func):
check_cls = check_cls_or_func(app)
else:
check_cls = check_cls_or_func
check_cls = check_cls_or_func

self.register(check_cls)
20 changes: 16 additions & 4 deletions invenio_checks/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from flask import current_app
from invenio_drafts_resources.services.records.components import ServiceComponent

from .models import CheckConfig


class ChecksComponent(ServiceComponent):
"""Checks component."""
Expand All @@ -29,11 +31,21 @@ def update_draft(self, identity, data=None, record=None, errors=None, **kwargs):
return

communities = []
if record.review.is_open:
communities.append(record.review.community)
if record.parent.review and (
record.parent.review.status == "submitted"
or record.parent.review.status == "created"
):
# TODO handle multiple requests
communities.append(record.parent.review.receiver.resolve().id)
else:
return

communities.extend(record.parent.communities.entries)
checks = itertools.chain(*[c.checks for c in communities])
checks = itertools.chain(
*[
CheckConfig.query.filter(CheckConfig.community_id == c).all()
for c in communities
]
)

for check in checks:
try:
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ invenio_base.api_apps =
invenio_checks = invenio_checks:InvenioChecks
invenio_db.models =
invenio_checks = invenio_checks.models
invenio_checks.check_types =
metadata = invenio_checks.metadata.check:MetadataCheck

[build_sphinx]
source-dir = docs/
Expand Down
Loading