Skip to content

Commit

Permalink
Merge pull request #8 from oarepo/corovcam/fe-116-display-requests-on…
Browse files Browse the repository at this point in the history
…-record-page

[FE-116] Display requests on record page
  • Loading branch information
mirekys authored Mar 27, 2024
2 parents 6959444 + e3ca268 commit 07d8890
Show file tree
Hide file tree
Showing 48 changed files with 1,975 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ dist/

tests/thesis
thesis

**/ui/theme/**/todo.md
node_modules
28 changes: 28 additions & 0 deletions babel.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015-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.

# Extraction from Python source files

[extractors]
jinja2 = jinja2.ext:babel_extract

[python: **.py]
encoding = utf-8

# Extraction from Jinja2 templates

[jinja2: **/templates/**.html]
encoding = utf-8

[jinja2: **/templates/**.jinja]
encoding = utf-8
extensions = jinjax.jinjax.JinjaX

# Special case for jinjax translation strings
[jinja2: **/jinjax_messages.jinja]
encoding = utf-8
10 changes: 10 additions & 0 deletions oarepo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
i18n:
babel_output_translations: oarepo_requests/translations
babel_source_paths:
- oarepo_requests/
i18next_output_translations: oarepo_requests/ui/theme/assets/semantic-ui/translations/oarepo_requests_ui
i18next_source_paths:
- oarepo_requests/ui/theme/assets/semantic-ui/js
languages:
- cs
- en
1 change: 1 addition & 0 deletions oarepo_requests/actions/edit_topic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# from .generic import AcceptAction
from invenio_requests.customizations import actions

from ..utils import get_matching_service_for_record
Expand Down
8 changes: 5 additions & 3 deletions oarepo_requests/resources/record/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import marshmallow as ma
from flask_resources import ResponseHandler, JSONSerializer
from invenio_records_resources.resources import RecordResourceConfig
from invenio_records_resources.resources.records.headers import etag_headers

from oarepo_requests.resources.ui import OARepoRequestsUIJSONSerializer


class RecordRequestsResourceConfig:
Expand All @@ -11,13 +15,11 @@ class RecordRequestsResourceConfig:
"request_type": ma.fields.Str()
}

"""
@property
def response_handlers(self):
return {
**RecordResourceConfig.response_handlers,
"application/vnd.inveniordm.v1+json": ResponseHandler(
OARepoRequestsUIJSONSerializer()
),
"application/json": ResponseHandler(JSONSerializer(), headers=etag_headers)
}
"""
8 changes: 5 additions & 3 deletions oarepo_requests/resources/record/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ def __init__(self, record_requests_config, config, service):
:param service:
:param record_requests_config: config specific for the record request serivce
"""
actual_config = copy.deepcopy(config)
actual_config = copy.deepcopy(record_requests_config)
actual_config.blueprint_name = f"{config.blueprint_name}_requests"
vars_to_overwrite = [
x for x in dir(record_requests_config) if not x.startswith("_")
x for x in dir(config) if not x.startswith("_")
]
actual_keys = dir(actual_config)
for var in vars_to_overwrite:
setattr(actual_config, var, getattr(record_requests_config, var))
if var not in actual_keys:
setattr(actual_config, var, getattr(config, var))
super().__init__(actual_config, service)

def create_url_rules(self):
Expand Down
6 changes: 3 additions & 3 deletions oarepo_requests/services/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from invenio_requests.services.schemas import GenericRequestSchema
from marshmallow import fields

from oarepo_requests.utils import get_matching_service_for_record, is_record

from oarepo_requests.utils import get_matching_service_for_record
from oarepo_runtime.records import is_published_record

def get_links_schema():
# TODO possibly specify more
Expand All @@ -31,7 +31,7 @@ def create_link(self, data, **kwargs):
record = self.context["record"]
service = get_matching_service_for_record(record)
link = ConditionalLink(
cond=is_record,
cond=is_published_record,
if_=Link(f"{{+api}}{service.config.url_prefix}{{id}}/requests/{type_id}"),
else_=Link(
f"{{+api}}{service.config.url_prefix}{{id}}/draft/requests/{type_id}"
Expand Down
50 changes: 50 additions & 0 deletions oarepo_requests/services/search_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from invenio_records_resources.services.records.params import FilterParam
from invenio_requests.resources.requests.config import RequestSearchRequestArgsSchema, RequestsResourceConfig
from invenio_requests.services.requests.config import RequestSearchOptions, RequestsServiceConfig
from marshmallow import fields
from opensearch_dsl.query import Bool, Term


class RequestOwnerFilterParam(FilterParam):
def apply(self, identity, search, params):
value = params.pop(self.param_name, None)
if value is not None:
search = search.filter("term", **{self.field_name: identity.id})
return search


class RequestReceiverFilterParam(FilterParam):
def apply(self, identity, search, params):
value = params.pop(self.param_name, None)
my_groups = [
n.value for n in identity.provides if n.method == 'role'
]
if value is not None:
search = search.filter(Bool(should=[
# explicitly myself
Term(**{f"{self.field_name}.user": identity.id}),
# my roles
*[
Term(**{f"{self.field_name}.group": group_id}) for group_id in my_groups
],
# TODO: add my communities where I have a role to accept requests
], minimum_should_match=1))
return search


class EnhancedRequestSearchOptions(RequestSearchOptions):
params_interpreters_cls = RequestSearchOptions.params_interpreters_cls + [
RequestOwnerFilterParam.factory("mine", "created_by.user"),
RequestReceiverFilterParam.factory("assigned", "receiver")
]


class ExtendedRequestSearchRequestArgsSchema(RequestSearchRequestArgsSchema):
mine = fields.Boolean()
assigned = fields.Boolean()


def override_invenio_request_search_options(*args, **kwargs):
# this monkey patch should be done better
RequestsServiceConfig.search = EnhancedRequestSearchOptions
RequestsResourceConfig.request_search_args = ExtendedRequestSearchRequestArgsSchema
32 changes: 32 additions & 0 deletions oarepo_requests/translations/_only_for_translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from oarepo_runtime.i18n import lazy_gettext as _

_("Create Request")
_("Open dialog for request")
_("My Requests")
_("Requests to Approve")
_("Are you sure?")
_("Cancel")
_("OK")
_("Create request")
_("Submit request")
_("Delete request")
_("Delete")
_("Accept request")
_("Accept")
_("Decline request")
_("Decline")
_("Create and submit request")
_("Create and submit")
_("Error sending request")
_("Submit")
_("Save drafted request")
_("Save")
_("Create")
_("Creator")
_("Receiver")
_("Request type")
_("Created")
_("Timeline")
_("Submit event")
_("No requests to show")
_("api.requests")
161 changes: 161 additions & 0 deletions oarepo_requests/translations/cs/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-03-27 11:31+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: cs <[email protected]>\n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);\n"
"Generated-By: Babel 2.14.0\n"

#: oarepo_requests/services/ui_schema.py:71
#, fuzzy
msgid "status"
msgstr "Stav"

#: oarepo_requests/translations/_only_for_translations.py:3
msgid "Create Request"
msgstr "Vytvořit žádost"

#: oarepo_requests/translations/_only_for_translations.py:4
msgid "Open dialog for request"
msgstr "Otevřít dialogové okno pro žádost"

#: oarepo_requests/translations/_only_for_translations.py:5
msgid "My Requests"
msgstr "Moje žádosti"

#: oarepo_requests/translations/_only_for_translations.py:6
msgid "Requests to Approve"
msgstr "Žádosti ke schválení"

#: oarepo_requests/translations/_only_for_translations.py:7
msgid "Are you sure?"
msgstr "Jste si jistí?"

#: oarepo_requests/translations/_only_for_translations.py:8
msgid "Cancel"
msgstr "Zrušit"

#: oarepo_requests/translations/_only_for_translations.py:9
msgid "OK"
msgstr "OK"

#: oarepo_requests/translations/_only_for_translations.py:10
msgid "Create request"
msgstr "Vytvořit žádost"

#: oarepo_requests/translations/_only_for_translations.py:11
msgid "Submit request"
msgstr "Odeslat žádost"

#: oarepo_requests/translations/_only_for_translations.py:12
msgid "Delete request"
msgstr "Smazat žádost"

#: oarepo_requests/translations/_only_for_translations.py:13
msgid "Delete"
msgstr "Smazat"

#: oarepo_requests/translations/_only_for_translations.py:14
msgid "Accept request"
msgstr "Přijmout žádost"

#: oarepo_requests/translations/_only_for_translations.py:15
msgid "Accept"
msgstr "Přijmout"

#: oarepo_requests/translations/_only_for_translations.py:16
msgid "Decline request"
msgstr "Zamítnout žádost"

#: oarepo_requests/translations/_only_for_translations.py:17
msgid "Decline"
msgstr "Zamítnout"

#: oarepo_requests/translations/_only_for_translations.py:18
msgid "Create and submit request"
msgstr "Vytvořit a odeslat žádost"

#: oarepo_requests/translations/_only_for_translations.py:19
msgid "Create and submit"
msgstr "Vytvořit a odeslat"

#: oarepo_requests/translations/_only_for_translations.py:20
msgid "Error sending request"
msgstr "Chyba při odesílání žádosti"

#: oarepo_requests/translations/_only_for_translations.py:21
msgid "Submit"
msgstr "Odeslat"

#: oarepo_requests/translations/_only_for_translations.py:22
msgid "Save drafted request"
msgstr "Uložit koncept žádosti"

#: oarepo_requests/translations/_only_for_translations.py:23
msgid "Save"
msgstr "Uložit"

#: oarepo_requests/translations/_only_for_translations.py:24
msgid "Create"
msgstr "Vytvořit"

#: oarepo_requests/translations/_only_for_translations.py:25
msgid "Creator"
msgstr "Tvůrce"

#: oarepo_requests/translations/_only_for_translations.py:26
msgid "Receiver"
msgstr "Příjemce"

#: oarepo_requests/translations/_only_for_translations.py:27
msgid "Request type"
msgstr "Typ žádosti"

#: oarepo_requests/translations/_only_for_translations.py:28
msgid "Created"
msgstr "Vytvořeno"

#: oarepo_requests/translations/_only_for_translations.py:29
msgid "Timeline"
msgstr "Časová osa"

#: oarepo_requests/translations/_only_for_translations.py:30
msgid "Submit event"
msgstr "Odeslat událost"

#: oarepo_requests/translations/_only_for_translations.py:31
msgid "No requests to show"
msgstr "Žádné žádosti k zobrazení"

#: oarepo_requests/translations/_only_for_translations.py:32
msgid "api.requests"
msgstr "API pro žádosti záznamu"

#: oarepo_requests/types/delete_record.py:14
msgid "Request deletion of published record"
msgstr "Žádost o smazání zveřejněného záznamu"

#: oarepo_requests/types/edit_record.py:14
msgid "Request re-opening of published record"
msgstr "Žádost o znovuotevření zveřejněného záznamu"

#: oarepo_requests/types/publish_draft.py:14
msgid "Request publishing of a draft"
msgstr "Žádost o kontrolu a zveřejnění konceptu"

msgid "No status"
msgstr "Beze stavu"

msgid "Cannot send request. Please try again later."
msgstr "Nemohu poslat žádost. Prosím, zkuste později."

msgid "Cancel request"
msgstr ""
Loading

0 comments on commit 07d8890

Please sign in to comment.