Skip to content

Commit

Permalink
Merge branch 'main' into stojanovic/ep-139-new-record-creation-commun…
Browse files Browse the repository at this point in the history
…ities
  • Loading branch information
mirekys authored Jan 7, 2025
2 parents 6273edb + 39b197c commit 5a070d4
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export const CommunityInvitationsModal = ({ rolesCanInvite, community }) => {
const [successMessage, setSuccessMessage] = useState("");
const [httpError, setHttpError] = useState("");

const handleClose = () => {
setSuccessMessage("");
setHttpError("");
close();
}

const onSubmit = async (values, { setSubmitting, resetForm }) => {
const serializer = new OARepoDepositSerializer(
["membersEmails", "emails"],
Expand All @@ -43,24 +49,27 @@ export const CommunityInvitationsModal = ({ rolesCanInvite, community }) => {
if (response.status === 204) {
resetForm();
setSuccessMessage(i18next.t("Invitations sent successfully."));
setTimeout(() => {
if (isOpen) {
handleClose()
}
}, 2500);
}
} catch (error) {
if (error.response.status >= 400) {
setHttpError(
i18next.t(
console.error(error.response)
setHttpError(`
${i18next.t(
"The invitations could not be sent. Please try again later."
)
)}
${error.response.data.message}` // TODO: These needs to get translated in invenio_communities.members.config
);
setTimeout(() => {
setHttpError("")
}, 5000);
}
} finally {
setSubmitting(false);
setTimeout(() => {
if (isOpen) {
close();
setSuccessMessage("");
setHttpError("");
}
}, 2500);
}
};

Expand Down Expand Up @@ -98,7 +107,7 @@ export const CommunityInvitationsModal = ({ rolesCanInvite, community }) => {
className="form-modal community-invitations"
closeIcon
open={isOpen}
onClose={close}
onClose={handleClose}
onOpen={open}
trigger={
<Button
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{# -*- coding: utf-8 -*-

This file is part of Invenio.
Copyright (C) 2023 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.
#}

{% extends "invenio_communities/details/base.html" %}
{% from "invenio_communities/details/macros/custom_fields.html" import list_vocabulary_values, list_string_values, show_custom_field %}
{% set active_community_header_menu_item= 'about' %}

{%- block page_body %}
{{ super() }}
<div class="ui text container rel-m-2 rel-pt-1">
{{ community.metadata.page | safe }}
{% if community.ui.funding|length %}
<h3 class="ui header">{{ _("Awards") }}</h3>
<dl class="ui list">

{% for funding in community.ui.funding %}
<div class="item rel-mb-1">
{% if funding.award %}
<dd class="header">
{{ funding.award.title_l10n }}
<span class="ui basic small label">
{{funding.award.number}}
</span>

{% if funding.award.identifiers|length and funding.award.identifiers[0].scheme == "url" %}
<a
class="ui transparent icon button"
href="{{ funding.award.identifiers[0].identifier }}"
aria-label="{{ _('Visit external website') }}"
title="{{ _('Opens in new tab') }}"
>
<i class="external primary icon" aria-hidden="true"></i>
</a>
{% endif %}
</dd>
{% endif %}

{% if funding.funder %}
<dt class="text-muted">
{{ funding.funder.name }}
</dt>
{% endif %}
</div>
{% endfor %}

</dl>
{% endif %}
{%- endblock page_body -%}
5 changes: 0 additions & 5 deletions oarepo_communities/ui/oarepo_communities/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import marshmallow as ma
from flask import g, redirect, url_for
from flask_login import login_required
from flask_menu import current_menu
from flask_resources import from_conf, request_parser, resource_requestctx
from invenio_communities.communities.resources.serializer import (
Expand Down Expand Up @@ -93,10 +92,6 @@ def search_endpoint_url(self, identity, api_config, overrides={}, **kwargs):


class CommunityRecordsUIResource(GlobalSearchUIResource):
decorators = [
login_required,
]

@request_view_args
@request_community_view_args
def community_records(self):
Expand Down
8 changes: 4 additions & 4 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pip install .
pip install oarepo-workflows
pip install oarepo-global-search
sh forked_install.sh invenio-records-resources
#sh forked_install.sh invenio-requests
#sh forked_install.sh invenio-drafts-resources
pip install -U --force-reinstall --no-deps https://github.com/oarepo/invenio-requests/archive/oarepo-4.1.0.zip
pip install -U --force-reinstall --no-deps https://github.com/oarepo/invenio-drafts-resources/archive/oarepo-3.1.1.zip
sh forked_install.sh invenio-requests
sh forked_install.sh invenio-drafts-resources
#sh forked_install.sh invenio-rdm-records
pip install -U --force-reinstall --no-deps https://github.com/oarepo/invenio-rdm-records/archive/oarepo-10.8.0.zip

pytest ./$CODE_TEST_DIR/test_communities
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-communities
version = 5.1.2
version = 5.1.3
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down
8 changes: 2 additions & 6 deletions tests/test_communities/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ class PublishRequestsRecordOwnerInDefaultRecordCommunity(DefaultRequests):
class NoRequests(WorkflowRequestPolicy):
publish_draft = WorkflowRequest(
requesters=[],
recipients=[CommunityRole("owner")],
recipients=[DefaultCommunityRole("owner")],
transitions=WorkflowTransitions(
submitted="publishing", accepted="published", declined="draft"
),
)
delete_published_record = WorkflowRequest(
requesters=[],
recipients=[CommunityRole("owner")],
recipients=[DefaultCommunityRole("owner")],
transitions=WorkflowTransitions(
submitted="deleting", accepted="deleted", declined="published"
),
Expand Down Expand Up @@ -611,10 +611,6 @@ def ui_serialized_community_role():
def _ui_serialized_community(community_id):
return {
"label": "Owner of My Community",
"links": {
"self": f"https://127.0.0.1:5000/api/communities/{community_id}",
"self_html": "https://127.0.0.1:5000/communities/public", # todo is this correct?
},
"reference": {"community_role": f"{community_id}:owner"},
"type": "community role",
}
Expand Down
16 changes: 11 additions & 5 deletions tests/test_communities/test_community_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,19 +431,25 @@ def test_community_role_ui_serialization(
request_data_factory,
)

def compare_result(result):
assert result.items() >= ui_serialized_community_role(community.id).items()
assert result["links"].items() >= {"self": f"https://127.0.0.1:5000/api/communities/{community.id}",
"self_html": "https://127.0.0.1:5000/communities/public",
}.items()

request = owner_client.get(
f"/requests/extended/{submit.json['id']}",
headers={"Accept": "application/vnd.inveniordm.v1+json"},
)
assert request.json["receiver"] == ui_serialized_community_role(community.id)

compare_result(request.json["receiver"])

request_list = owner_client.get(
"/requests/",
headers={"Accept": "application/vnd.inveniordm.v1+json"},
)
# todo test cache use in search requests with multiple results
assert request_list.json["hits"]["hits"][0][
"receiver"
] == ui_serialized_community_role(community.id)

compare_result(request_list.json["hits"]["hits"][0]["receiver"])

"""
def test_community_role_ui_serialization_cs(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_communities/test_param_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def test_community_role_param_interpreter(
search_filtered = owner_client.get("/requests/?assigned=true")


assert len(search_filtered.json["hits"]["hits"]) == 2
assert len(search_filtered.json["hits"]["hits"]) == 0

0 comments on commit 5a070d4

Please sign in to comment.