-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* embargo component * empty record * record restriction variables added to form config * empty_data component for access * accessrights on detail * version bump --------- Co-authored-by: Mirek Simek <[email protected]>
- Loading branch information
Showing
11 changed files
with
186 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .base import UIResourceComponent | ||
from typing import Dict | ||
|
||
|
||
class EmptyRecordAccessComponent(UIResourceComponent): | ||
def empty_record(self, *, resource_requestctx, empty_data: Dict, **kwargs) -> None: | ||
""" | ||
Called before an empty record data are returned. | ||
:param resource_requestctx: invenio request context (see https://github.com/inveniosoftware/flask-resources/blob/master/flask_resources/context.py) | ||
:param empty_data: empty record data | ||
""" | ||
empty_data.setdefault("access", {}) | ||
empty_data["access"]["files"] = "public" | ||
empty_data["access"]["record"] = "public" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from flask import current_app | ||
from .base import UIResourceComponent | ||
from datetime import timedelta | ||
|
||
|
||
class RecordRestrictionComponent(UIResourceComponent): | ||
def form_config(self, *, form_config, **kwargs): | ||
form_config["recordRestrictionGracePeriod"] = current_app.config.get( | ||
"RDM_RECORDS_RESTRICTION_GRACE_PERIOD", timedelta(days=30) | ||
).days | ||
|
||
form_config["allowRecordRestriction"] = current_app.config.get( | ||
"RDM_RECORDS_ALLOW_RESTRICTION_AFTER_GRACE_PERIOD", False | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{# def access, search_link, searchFacet="access_status" #} | ||
|
||
{% set icons = { | ||
"open": "/static/icons/locks/zamky_open_access.svg", | ||
"restricted": "/static/icons/locks/zamky_Partialy_closed_access.svg", | ||
"embargoed": "/static/icons/locks/zamky_Closed_access.svg", | ||
"metadata-only": "/static/icons/locks/zamky_Partialy_closed_access.svg" | ||
} %} | ||
|
||
{% if access.id == "embargoed" %} | ||
{% set tooltipText = "{} - {} ({})".format(access["title_l10n"], access["description_l10n"], access["embargo_date_l10n"]) %} | ||
{% else %} | ||
{% set tooltipText = "{} - {}".format(access["title_l10n"], access["description_l10n"]) %} | ||
{% endif %} | ||
|
||
|
||
{% set href = search_link ~ "?q=&f=" ~ searchFacet ~ ":" ~ access["id"] %} | ||
|
||
<div data-tooltip="{{ tooltipText }}" class="inline"> | ||
<a href="{{ href }}" target="_blank" rel="noopener noreferrer"> | ||
<img class="ui image mini inline" src="{{ icons[access.id] }}" alt="{{ access.id }}" title="{{ access.id }}" /> | ||
</a> | ||
</div> |
77 changes: 77 additions & 0 deletions
77
...me/assets/semantic-ui/js/oarepo_ui/forms/components/AccessRightField/AccessRightField.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useEffect, useRef } from "react"; | ||
import { Field, useFormikContext } from "formik"; | ||
import { AccessRightFieldCmp } from "@js/invenio_rdm_records/src/deposit/fields/AccessField/AccessRightField"; | ||
import PropTypes from "prop-types"; | ||
import { useFormConfig } from "@js/oarepo_ui"; | ||
|
||
export const AccessRightField = ({ | ||
fieldPath, | ||
label, | ||
labelIcon, | ||
showMetadataAccess, | ||
community, | ||
record, | ||
recordRestrictionGracePeriod, | ||
allowRecordRestriction, | ||
}) => { | ||
const { values } = useFormikContext(); | ||
const { | ||
formConfig: { allowed_communities }, | ||
} = useFormConfig(); | ||
|
||
const mounted = useRef(false); | ||
// when you enable embargo to scroll the embargo related inputs into view | ||
useEffect(() => { | ||
// don't scroll it into view on mount if the input exists | ||
if (!mounted.current) { | ||
mounted.current = true; | ||
return; | ||
} | ||
|
||
const embargoReasonInput = document.getElementById("access.embargo.reason"); | ||
if (embargoReasonInput) { | ||
const rect = embargoReasonInput.getBoundingClientRect(); | ||
window.scrollTo(0, document.body.scrollHeight - rect.y); | ||
} | ||
}, [values?.access?.embargo?.active]); | ||
return ( | ||
<Field name={fieldPath}> | ||
{(formik) => { | ||
const mainCommunity = | ||
community || | ||
allowed_communities.find( | ||
(c) => c.id === record?.parent?.communities?.default | ||
); | ||
return ( | ||
<AccessRightFieldCmp | ||
formik={formik} | ||
fieldPath={fieldPath} | ||
label={label} | ||
labelIcon={labelIcon} | ||
showMetadataAccess={showMetadataAccess} | ||
community={mainCommunity} | ||
record={record} | ||
recordRestrictionGracePeriod={recordRestrictionGracePeriod} | ||
allowRecordRestriction={allowRecordRestriction} | ||
/> | ||
); | ||
}} | ||
</Field> | ||
); | ||
}; | ||
|
||
AccessRightField.propTypes = { | ||
fieldPath: PropTypes.string.isRequired, | ||
label: PropTypes.string.isRequired, | ||
labelIcon: PropTypes.string.isRequired, | ||
showMetadataAccess: PropTypes.bool, | ||
community: PropTypes.object, | ||
record: PropTypes.object.isRequired, | ||
recordRestrictionGracePeriod: PropTypes.number.isRequired, | ||
allowRecordRestriction: PropTypes.bool.isRequired, | ||
}; | ||
|
||
AccessRightField.defaultProps = { | ||
showMetadataAccess: true, | ||
community: undefined, | ||
}; |
1 change: 1 addition & 0 deletions
1
oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/AccessRightField/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./AccessRightField"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters