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

Stojanovic/fe 237 support moving record from one community to another UI #98

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ coverage.xml
*,cover

# Translations
*.mo
# *.mo

# Django stuff:
*.log
Expand Down
94 changes: 93 additions & 1 deletion oarepo_communities/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
from flask_babelex import lazy_gettext as _
#
# Copyright (C) 2024 CESNET z.s.p.o.
#
# oarepo-requests is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.
#
"""Configuration of the draft record requests resource."""

from __future__ import annotations

import json
from typing import Any, Optional, Union

from flask import g
from flask_resources import (
HTTPJSONException,
create_error_handler,
)
from flask_resources.serializers.json import JSONEncoder
from marshmallow import ValidationError
from oarepo_runtime.i18n import lazy_gettext as _


class CustomHTTPJSONException(HTTPJSONException):
"""Custom HTTP Exception delivering JSON error responses with an error_type."""

def __init__(
self,
code: Optional[int] = None,
errors: Optional[Union[dict[str, any], list]] = None,
error_type: Optional[str] = None,
**kwargs: Any,
) -> None:
"""Initialize CustomHTTPJSONException."""
super().__init__(code=code, errors=errors, **kwargs)
self.error_type = error_type # Save the error_type passed in the constructor

def get_body(self, environ: any = None, scope: any = None) -> str:
"""Get the request body."""
body = {"status": self.code, "message": self.get_description(environ)}

errors = self.get_errors()
if errors:
body["errors"] = errors

# Add error_type to the response body
if self.error_type:
body["error_type"] = self.error_type

# TODO: Revisit how to integrate error monitoring services. See issue #56
# Temporarily kept for expediency and backward-compatibility
if self.code and (self.code >= 500) and hasattr(g, "sentry_event_id"):
body["error_id"] = str(g.sentry_event_id)

return json.dumps(body, cls=JSONEncoder)


class CommunityAlreadyIncludedException(Exception):
Expand All @@ -8,6 +62,12 @@ class CommunityAlreadyIncludedException(Exception):
description = _("The record is already included in this community.")


class TargetCommunityNotProvidedException(Exception):
"""Target community not provided in the migration request"""

description = "Target community not provided in the migration request."


class CommunityNotIncludedException(Exception):
"""The record is already in the community."""

Expand Down Expand Up @@ -67,3 +127,35 @@ def __init__(self, request_id: str):
def description(self) -> str:
"""Exception's description."""
return _("There is already an open inclusion request for this community.")


RESOURCE_ERROR_HANDLERS = {
CommunityAlreadyIncludedException: create_error_handler(
lambda e: CustomHTTPJSONException(
code=400,
description=_("The community is already included in the record."),
errors=[
{
"field": "payload.community",
"messages": [
_("Record is already in this community. Please choose another.")
],
}
],
error_type="cf_validation_error",
)
),
TargetCommunityNotProvidedException: create_error_handler(
lambda e: CustomHTTPJSONException(
code=400,
description=_("Target community not provided in the migration request."),
errors=[
{
"field": "payload.community",
"messages": [_("Please select the community")],
}
],
error_type="cf_validation_error",
)
),
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// This file is part of React-Invenio-Deposit
// Copyright (C) 2021 Graz University of Technology.
//
// Invenio-app-rdm is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.
/*
* Copyright (C) 2024 CESNET z.s.p.o.
*
* oarepo-tools is free software; you can redistribute it and/or
* modify it under the terms of the MIT License; see LICENSE file for more
* details.
*/

import i18n from "i18next";

Expand Down

Large diffs are not rendered by default.

Binary file not shown.
222 changes: 221 additions & 1 deletion oarepo_communities/i18n/translations/cs/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ msgstr "Záznam není v této komunitě."

#: /home/ron/prace/oarepo-communities/oarepo_communities/errors.py:20
msgid "Primary community can't be removed, can only be migrated to another."
msgstr "Záznam nemůže být odebrán z hlavní komunity, je možné ho pouze přesunout do jiné."
msgstr ""
"Záznam nemůže být odebrán z hlavní komunity, je možné ho pouze přesunout do "
"jiné."

#: /home/ron/prace/oarepo-communities/oarepo_communities/errors.py:28
msgid "Default community is not present in the input."
Expand All @@ -348,6 +350,220 @@ msgstr "Na vstupu chybí výchozí komunita."
msgid "Communities are not present in the input."
msgstr "Na vstupu chybí komunity."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:93
msgid "Request initiation of Community migration."
Ducica marked this conversation as resolved.
Show resolved Hide resolved
msgstr "Požádejte o zahájení migrace komunity."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:113
msgid "Inititiate record community migration"
msgstr "Zahajte migraci záznamu do komunity"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:115
msgid "Request community migration"
msgstr "Požádejte o migraci komunity"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:118
msgid "Record community migration initiated"
msgstr "Migrace záznamu do komunity byla zahájena"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:120
msgid "Request record community migration"
msgstr "Požádejte o migraci záznamu do komunity"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:133
msgid ""
"Click to immediately start record migration. After submitting the request "
"will immediatelly be forwarded to responsible person(s) in the target "
"community. "
msgstr ""
"Klikněte pro okamžité zahájení migrace záznamu. Po odeslání bude žádost "
"ihned předána odpovědným osobám v cílové komunitě."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:139
msgid ""
"After you submit record community migration request, it will first have to "
"be approved by responsible person(s) of the current community. Then it will "
"have to be accepted by responsible persons(s) of the target community. You "
"will be notified about the decision by email."
msgstr ""
"Po odeslání žádosti o migraci záznamu do komunity ji nejprve musí schválit "
"odpovědné osoby aktuální komunity. Poté ji musí přijmout odpovědné osoby "
"cílové komunity. O rozhodnutí budete informováni e-mailem."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:147
msgid ""
"Record community migration request has been submitted. You will be notified "
"about the decision by email."
msgstr ""
"Žádost o migraci záznamu do komunity byla odeslána. O rozhodnutí budete "
"informováni e-mailem."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:152
msgid ""
"User has requested record community migration. You can now accept or decline"
" the request."
msgstr ""
"Uživatel požádal o migraci záznamu do komunity. Nyní můžete žádost přijmout "
"nebo odmítnout."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:156
msgid "Record community migration request has been submitted."
msgstr "Žádost o migraci záznamu do komunity byla odeslána."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:159
msgid "Submit to initiate record community migration. "
msgstr "Odešlete žádost o zahájení migrace záznamu do komunity."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:161
#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:306
#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/submission_secondary.py:137
msgid "Request not yet submitted."
msgstr "Žádost ještě nebyla odeslána."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:177
#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:252
msgid "Target community:"
msgstr "Cílová komunita:"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:267
#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:272
msgid "Confirm record community migration"
msgstr "Potvrďte migraci záznamu do komunity"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:270
msgid "Record community migration confirmation pending"
msgstr "Čeká se na potvrzení migrace záznamu do komunity"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:285
msgid ""
"Confirm the migration of the record to the new primary community. This "
"request must be accepted by responsible person(s) of the new community."
msgstr ""
"Potvrďte migraci záznamu do nové primární komunity. Tuto žádost musí "
"přijmout odpovědné osoby nové komunity."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:293
msgid ""
"The confirmation request has been submitted to the target community. You "
"will be notified about their decision by email."
msgstr ""
"Potvrzovací žádost byla odeslána cílové komunitě. O jejich rozhodnutí budete"
" informováni e-mailem."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:298
msgid ""
"A request to confirm record community migration has been received. You can "
"now accept or decline the request."
msgstr ""
"Byla přijata žádost o potvrzení migrace záznamu do komunity. Nyní můžete "
"žádost přijmout nebo odmítnout."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:302
msgid "Record community migration confirmation request is pending."
msgstr "Žádost o potvrzení migrace záznamu do komunity čeká na vyřízení."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:305
msgid "Submit to confirm record community migration."
msgstr "Odešlete žádost o potvrzení migrace záznamu do komunity."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/submission_secondary.py:76
msgid "Secondary community:"
msgstr "Sekundární komunita:"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/submission_secondary.py:94
msgid "Initiate record secondary community submission"
Copy link
Member

@mirekys mirekys Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above, shorter text would be nicer:
Add to secondary community / Přidat do sekundarní komunity

msgstr "Zahajte přidání záznamu do sekundární komunity"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/submission_secondary.py:97
msgid "Confirm record secondary community submission"
msgstr "Potvrďte přidání záznamu do sekundární komunity"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/submission_secondary.py:99
msgid "Request record secondary community submission"
msgstr "Požádejte o přidání záznamu do sekundární komunity"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/submission_secondary.py:112
msgid ""
"After submitting record secondary community submission request, it will "
"first have to be approved by responsible person(s) of the target community. "
"You will be notified about the decision by email."
msgstr ""
"Po odeslání žádosti o přidání záznamu do sekundární komunity ji musí nejprve"
" schválit odpovědné osoby cílové komunity. O rozhodnutí budete informováni "
"e-mailem."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/submission_secondary.py:119
msgid ""
"Record secondary community submission request has been submitted. You will "
"be notified about the decision by email."
msgstr ""
"Žádost o přidání záznamu do sekundární komunity byla odeslána. O rozhodnutí "
"budete informováni e-mailem."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/submission_secondary.py:124
msgid ""
"User has requested to add secondary community to a record. You can now "
"accept or decline the request."
msgstr ""
"Uživatel požádal o přidání záznamu do sekundární komunity. Nyní můžete "
"žádost přijmout nebo odmítnout."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/submission_secondary.py:128
msgid "Record secondary community submission request has been submitted."
msgstr "Žádost o přidání záznamu do sekundární komunity byla odeslána."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/submission_secondary.py:133
msgid "Submit to initiate record secondary community submission."
msgstr "Odešlete žádost o zahájení přidání záznamu do sekundární komunity."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/ui/communities_components/templates/oarepo/invenio_communities/details/about/index.html:19
msgid "Awards"
msgstr "Ocenění"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/ui/communities_components/templates/oarepo/invenio_communities/details/about/index.html:35
msgid "Visit external website"
msgstr "Navštivte externí webovou stránku"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/ui/communities_components/templates/oarepo/invenio_communities/details/about/index.html:36
msgid "Opens in new tab"
msgstr "Otevře se v nové záložce"

msgid "Target community"
msgstr "Cílová komunita"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:95
msgid "Move record to another primary community."
msgstr "Převést pod jinou primarni komunitu"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/requests/migration.py:135
msgid ""
"Click to immediately start record migration. After submitting the request "
"will immediatelly be forwarded to responsible person(s) in the target "
"community. You will be notified about the decision by email."
msgstr ""
"Kliknutím okamžitě zahájíte migraci záznamu. Po odeslání žádosti bude "
"okamžitě předána odpovědné osobě (osobám) v cílové komunitě. O rozhodnutí "
"budete informováni e-mailem."

#: /Users/m/w/cesnet/oarepo-communities/oarepo_communities/errors.py:130
msgid "The community is already included in the record."
msgstr "Komunita je již zahrnuta v záznamu"

#: /Users/m/w/cesnet/oarepo-communities/oarepo_communities/errors.py:135
msgid "Record is already in this community. Please choose another."
msgstr "Záznam je již v této komunitě. Prosím vyberte jinou."

#: /Users/m/w/cesnet/oarepo-communities/oarepo_communities/errors.py:145
msgid "Target community not provided in the migration request."
msgstr "Cílová komunita nebyla uvedena v požadavku na migraci."

#: /Users/m/w/cesnet/oarepo-communities/oarepo_communities/errors.py:149
msgid "Please select the community"
msgstr "Prosím vyberte komunitu"

msgid "Could not fetch community."
msgstr "Nepodařilo se načíst komunitu."

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/ui/communities_components/templates/RecordCommunities.jinja:19
msgid "primary"
msgstr "primární"
Expand All @@ -371,3 +587,7 @@ msgstr ""
#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/ui/communities_components/templates/CommunityItem.jinja:12
msgid "Community title not provided"
msgstr "Název komunity není uveden"

#: /home/dusanst/Projects/oarepo-communities/oarepo_communities/resources/components/allowed_communities.py:58
msgid "You have no permission to create record in this community."
msgstr ""
Binary file not shown.
Loading