Skip to content

Commit

Permalink
review police: allow all community members to submit records to commu…
Browse files Browse the repository at this point in the history
…nity without review

* closes CERNDocumentServer/cds-rdm#176
  • Loading branch information
anikachurilova authored and slint committed Jul 30, 2024
1 parent 4a5df49 commit 1498d94
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import ReactDOM from "react-dom";
import React from "react";

const domContainer = document.getElementById("community-settings-pages");
const formConfig = JSON.parse(domContainer.dataset.formConfig);
const community = JSON.parse(domContainer.dataset.community);

ReactDOM.render(
<CommunityPagesForm formConfig={formConfig} community={community} />,
domContainer
);
ReactDOM.render(<CommunityPagesForm community={community} />, domContainer);
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"description": "Community review policy.",
"enum": [
"open",
"closed"
"closed",
"members"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class ReviewPolicyEnum(AccessEnumMixin, Enum):

CLOSED = "closed"

MEMBERS = "members"


class CommunityAccess:
"""Access management per community."""
Expand Down
1 change: 1 addition & 0 deletions invenio_communities/communities/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class CommunityAccessSchema(Schema):
[
"open",
"closed",
"members",
]
)
)
Expand Down
34 changes: 32 additions & 2 deletions invenio_communities/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from flask_principal import UserNeed
from invenio_access.permissions import any_user, authenticated_user, system_process
from invenio_records.dictutils import dict_lookup
from invenio_records_permissions.generators import Generator
from invenio_search.engine import dsl

Expand Down Expand Up @@ -125,11 +126,40 @@ def __init__(self, field, then_, else_):
)


class IfPolicyClosed(IfRestrictedBase):
class ReviewPolicy(Generator):
"""If policy is closed."""

def __init__(self, field, then_, else_):
def __init__(self, closed_, open_, members_):
"""Constructor."""
self.closed_ = closed_
self.open_ = open_
self.members_ = members_

def _generators(self, record, **kwargs):
"""Get the generators."""
review_policy = dict_lookup(record, "access.review_policy")

if review_policy == "closed":
return self.closed_
elif review_policy == "open":
return self.open_
elif review_policy == "members":
return self.members_

def needs(self, record=None, **kwargs):
"""Set of Needs granting permission."""
needs = [
g.needs(record=record, **kwargs) for g in self._generators(record, **kwargs)
]
return set(chain.from_iterable(needs))


class IfRecordPolicyClosed(IfRestrictedBase):
"""If record policy is closed."""

def __init__(self, then_, else_):
"""Initialize."""
field = "record_policy"
super().__init__(
lambda r: (
getattr(r.access, field, None)
Expand Down
16 changes: 8 additions & 8 deletions invenio_communities/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
CommunityOwners,
CommunitySelfMember,
IfCommunityDeleted,
IfPolicyClosed,
IfRecordPolicyClosed,
IfRestricted,
ReviewPolicy,
)


Expand Down Expand Up @@ -82,8 +83,7 @@ class CommunityPermissionPolicy(BasePermissionPolicy):
can_rename = [CommunityOwners(), SystemProcess()]

can_submit_record = [
IfPolicyClosed(
"record_policy",
IfRecordPolicyClosed(
then_=[CommunityMembers(), SystemProcess()],
else_=[
IfRestricted(
Expand All @@ -97,11 +97,11 @@ class CommunityPermissionPolicy(BasePermissionPolicy):

# who can include a record directly, without a review
can_include_directly = [
IfPolicyClosed(
"review_policy",
then_=[Disable()],
else_=[CommunityCurators()],
),
ReviewPolicy(
closed_=[Disable()],
open_=[CommunityCurators()],
members_=[CommunityMembers()],
)
]

can_members_add = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<div
id="community-settings-pages"
data-community='{{ community | tojson }}'
data-form-config='{{ form_config | tojson }}'
>
</div>
{%- endblock settings_body %}
11 changes: 8 additions & 3 deletions invenio_communities/views/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
"Submissions to the community by default requires review, but curators, managers and owners can publish directly without review."
),
},
{
"text": "Allow all members to publish without review",
"value": "members",
"icon": "lock open",
"helpText": _(
"Submissions to the community by default requires review, but all community members can publish directly without review."
),
},
]


Expand Down Expand Up @@ -412,9 +420,6 @@ def communities_settings_pages(pid_value, community, community_ui):
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
form_config=dict(
access=dict(review_policy=REVIEW_POLICY_FIELDS),
),
)


Expand Down

0 comments on commit 1498d94

Please sign in to comment.