forked from inveniosoftware/invenio-communities
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
permissions: add can_request_membership
- Loading branch information
Showing
5 changed files
with
105 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 Northwestern University. | ||
# | ||
# Invenio-RDM-Records is free software; you can redistribute it | ||
# and/or modify it under the terms of the MIT License; see LICENSE file for | ||
# more details. | ||
|
||
"""Test permissions.""" | ||
|
||
from invenio_communities.permissions import CommunityPermissionPolicy | ||
|
||
|
||
def test_can_request_membership( | ||
app, community, owner, anon_identity, any_user, superuser_identity | ||
): | ||
|
||
policy = CommunityPermissionPolicy | ||
community_record = community._record | ||
authenticated_identity = any_user.identity | ||
|
||
allow_membership_requests_orig = app.config["COMMUNITIES_ALLOW_MEMBERSHIP_REQUESTS"] | ||
|
||
# Case - feature disabled | ||
app.config["COMMUNITIES_ALLOW_MEMBERSHIP_REQUESTS"] = False | ||
assert not ( | ||
policy(action="request_membership", record=community_record).allows( | ||
superuser_identity | ||
) | ||
) | ||
|
||
app.config["COMMUNITIES_ALLOW_MEMBERSHIP_REQUESTS"] = True | ||
|
||
# Case - setting disabled | ||
community_record.access.member_policy = "closed" | ||
assert not ( | ||
policy(action="request_membership", record=community_record).allows( | ||
superuser_identity | ||
) | ||
) | ||
|
||
community_record.access.member_policy = "open" | ||
|
||
# Case - unlogged user | ||
assert not ( | ||
policy(action="request_membership", record=community_record).allows( | ||
anon_identity | ||
) | ||
) | ||
|
||
# Case - logged user not part of community | ||
assert policy(action="request_membership", record=community_record).allows( | ||
authenticated_identity | ||
) | ||
|
||
# Case - member of community | ||
assert not ( | ||
policy(action="request_membership", record=community_record).allows( | ||
owner.identity | ||
) | ||
) | ||
|
||
app.config["COMMUNITIES_ALLOW_MEMBERSHIP_REQUESTS"] = allow_membership_requests_orig |