diff --git a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges/CommunityPriviledgesForm.js b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges/CommunityPrivilegesForm.js
similarity index 70%
rename from invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges/CommunityPriviledgesForm.js
rename to invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges/CommunityPrivilegesForm.js
index ce4d30036..c609ff091 100644
--- a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges/CommunityPriviledgesForm.js
+++ b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges/CommunityPrivilegesForm.js
@@ -10,6 +10,7 @@
import { i18next } from "@translations/invenio_communities/i18next";
import { CommunitySettingsForm } from "..//components/CommunitySettingsForm";
import _get from "lodash/get";
+import _isEmpty from "lodash/isEmpty";
import { useField } from "formik";
import React, { Component } from "react";
import { RadioField } from "react-invenio-forms";
@@ -18,17 +19,31 @@ import PropTypes from "prop-types";
const VisibilityField = ({ label, formConfig, ...props }) => {
const [field] = useField(props);
+ const fieldPath = "access.visibility";
+
+ function createHandleChange(radioValue) {
+ function handleChange({ event, data, formikProps }) {
+ formikProps.form.setFieldValue(fieldPath, radioValue);
+ // dependent fields
+ if (radioValue === "restricted") {
+ formikProps.form.setFieldValue("access.member_policy", "closed");
+ }
+ }
+ return handleChange;
+ }
+
return (
<>
{formConfig.access.visibility.map((item) => (
@@ -76,14 +91,47 @@ MembersVisibilityField.defaultProps = {
label: "",
};
+const MemberPolicyField = ({ label, formConfig, ...props }) => {
+ const [field] = useField(props);
+ const isDisabled = _get(field.value, "access.visibility") === "restricted";
+
+ return (
+ <>
+ {formConfig.access.member_policy.map((item) => (
+
+
+
+
+ ))}
+ >
+ );
+};
+
+MemberPolicyField.propTypes = {
+ label: PropTypes.string,
+ formConfig: PropTypes.object.isRequired,
+};
+
+MemberPolicyField.defaultProps = {
+ label: "",
+};
+
class CommunityPrivilegesForm extends Component {
getInitialValues = () => {
return {
access: {
visibility: "public",
members_visibility: "public",
+ member_policy: "closed",
// TODO: Re-enable once properly integrated to be displayed
- // member_policy: "open",
// record_policy: "open",
},
};
@@ -105,6 +153,7 @@ class CommunityPrivilegesForm extends Component {
+
{i18next.t("Members visibility")}
@@ -114,6 +163,19 @@ class CommunityPrivilegesForm extends Component {
+
+ {!_isEmpty(formConfig.access.member_policy) && (
+ <>
+
+ {i18next.t("Membership Policy")}
+
+ {i18next.t("Controls if anyone can request to join your community.")}
+
+
+
+ >
+ )}
+
{/* TODO: Re-enable once properly integrated to be displayed */}
{/*
diff --git a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges/index.js b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges/index.js
index ecbfcbd2d..fff65cd03 100644
--- a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges/index.js
+++ b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/privileges/index.js
@@ -1,4 +1,4 @@
-import CommunityPrivilegesForm from "./CommunityPriviledgesForm";
+import CommunityPrivilegesForm from "./CommunityPrivilegesForm";
import ReactDOM from "react-dom";
import React from "react";
diff --git a/invenio_communities/config.py b/invenio_communities/config.py
index 1e9185740..bb325fb82 100644
--- a/invenio_communities/config.py
+++ b/invenio_communities/config.py
@@ -314,3 +314,6 @@
COMMUNITIES_ALWAYS_SHOW_CREATE_LINK = False
"""Controls visibility of 'New Community' btn based on user's permission when set to True."""
+
+COMMUNITIES_ALLOW_MEMBERSHIP_REQUESTS = False
+"""Feature flag for membership request."""
diff --git a/invenio_communities/views/communities.py b/invenio_communities/views/communities.py
index 5cf36793a..8795f28b0 100644
--- a/invenio_communities/views/communities.py
+++ b/invenio_communities/views/communities.py
@@ -82,6 +82,24 @@
]
+MEMBER_POLICY_FIELDS = [
+ {
+ "text": "Open",
+ "value": "open",
+ "icon": "user plus",
+ "helpText": _("Users can request to join your community."),
+ },
+ {
+ "text": "Closed",
+ "value": "closed",
+ "icon": "user times",
+ "helpText": _(
+ "Users cannot request to join your community. Only invited users can become members of your community."
+ ),
+ },
+]
+
+
HEADER_PERMISSIONS = {
"read",
"update",
@@ -341,6 +359,12 @@ def communities_settings_privileges(pid_value, community, community_ui):
if not permissions["can_manage_access"]:
raise PermissionDeniedError()
+ member_policy = (
+ MEMBER_POLICY_FIELDS
+ if current_app.config["COMMUNITIES_ALLOW_MEMBERSHIP_REQUESTS"]
+ else {}
+ )
+
return render_community_theme_template(
"invenio_communities/details/settings/privileges.html",
theme=community_ui.get("theme", {}),
@@ -349,6 +373,7 @@ def communities_settings_privileges(pid_value, community, community_ui):
access=dict(
visibility=VISIBILITY_FIELDS,
members_visibility=MEMBERS_VISIBILITY_FIELDS,
+ member_policy=member_policy,
),
),
permissions=permissions,