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.
js+service: [inveniosoftware#855] 4) integrate request flow with fron…
…tend [+] This concludes the 2nd flow of the membership request feature. Remaining flows are - 'waiting for decision' flow - 'making a decision' flow This PR needs to be complemented by: - one in invenio-requests (done) - one in invenio-rdm-records (to do)
- Loading branch information
Showing
10 changed files
with
254 additions
and
26 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
29 changes: 29 additions & 0 deletions
29
invenio_communities/assets/semantic-ui/js/invenio_communities/api/RequestLinksExtractor.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,29 @@ | ||
// This file is part of Invenio-communities | ||
// Copyright (C) 2024 Northwestern University. | ||
// | ||
// Invenio-communities is free software; you can redistribute it and/or modify it | ||
// under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
export class RequestLinksExtractor { | ||
#urls; | ||
|
||
constructor(request) { | ||
if (!request?.links) { | ||
throw TypeError("Request resource links are undefined"); | ||
} | ||
this.#urls = request.links; | ||
} | ||
|
||
url(key) { | ||
const urlOfKey = this.#urls[key]; | ||
if (!urlOfKey) { | ||
throw TypeError(`"${key}" link missing from resource.`); | ||
} | ||
return urlOfKey; | ||
} | ||
|
||
get userDiscussionUrl() { | ||
const result = this.url("self_html"); | ||
return result.replace("/requests/", "/me/requests/"); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
invenio_communities/assets/semantic-ui/js/invenio_communities/api/membershipRequests/api.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,26 @@ | ||
// This file is part of Invenio-communities | ||
// Copyright (C) 2022 CERN. | ||
// Copyright (C) 2024 Northwestern University. | ||
// | ||
// Invenio-communities is free software; you can redistribute it and/or modify it | ||
// under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
import { CommunityLinksExtractor } from "../CommunityLinksExtractor"; | ||
import { http } from "react-invenio-forms"; | ||
|
||
/** | ||
* API Client for community membership requests. | ||
* | ||
* It mostly uses the API links passed to it from initial community. | ||
* | ||
*/ | ||
export class CommunityMembershipRequestsApi { | ||
constructor(community) { | ||
this.community = community; | ||
this.linksExtractor = new CommunityLinksExtractor(community); | ||
} | ||
|
||
requestMembership = async (payload) => { | ||
return await http.post(this.linksExtractor.url("membership_requests"), payload); | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
from invenio_access.permissions import system_identity | ||
from invenio_requests.records.api import Request | ||
from invenio_search import current_search | ||
from invenio_users_resources.proxies import current_users_service | ||
|
||
from invenio_communities.members.records.api import ArchivedInvitation, Member | ||
|
||
|
@@ -93,3 +94,55 @@ def invite_request_id(requests_service, invite_user): | |
type="community-invitation", | ||
).to_dict() | ||
return res["hits"]["hits"][0]["id"] | ||
|
||
|
||
# The `new_user`` module fixture leaks identity across tests, so a pure new user for | ||
# each following test is the way to go. | ||
@pytest.fixture() | ||
def create_user(UserFixture, app, db, search_clear): | ||
"""Create user factory fixture.""" | ||
|
||
def _create_user(data=None): | ||
"""Create user.""" | ||
data = data or {} | ||
default_data = dict( | ||
email="[email protected]", | ||
password="user", | ||
username="user", | ||
user_profile={ | ||
"full_name": "Created User", | ||
"affiliations": "CERN", | ||
}, | ||
preferences={ | ||
"visibility": "public", | ||
"email_visibility": "restricted", | ||
"notifications": { | ||
"enabled": True, | ||
}, | ||
}, | ||
active=True, | ||
confirmed=True, | ||
) | ||
actual_data = dict(default_data, **data) | ||
u = UserFixture(**actual_data) | ||
u.create(app, db) | ||
current_users_service.indexer.process_bulk_queue() | ||
current_users_service.record_cls.index.refresh() | ||
db.session.commit() | ||
return u | ||
|
||
return _create_user | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def membership_request(member_service, community, create_user, db, search_clear): | ||
"""A membership request.""" | ||
user = create_user() | ||
data = { | ||
"message": "Can I join the club?", | ||
} | ||
return member_service.request_membership( | ||
user.identity, | ||
community._record.id, | ||
data, | ||
) |
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
Oops, something went wrong.