-
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.
Merge pull request #40 from oarepo/miroslavsimek/be-397-add-ifrequest…
…edby-generator-to-oarepo_requests Adding IfRequestedBy
- Loading branch information
Showing
11 changed files
with
208 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,3 +96,5 @@ node_modules | |
|
||
dummy-record.js | ||
jsconfig.json | ||
|
||
forked_install.sh |
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 |
---|---|---|
@@ -1,16 +1,23 @@ | ||
from oarepo_requests.errors import RequestTypeNotInWorkflow | ||
|
||
|
||
def default_workflow_receiver_function(record=None, request_type=None, **kwargs): | ||
from oarepo_workflows.proxies import current_oarepo_workflows | ||
|
||
workflow_id = current_oarepo_workflows.get_workflow_from_record(record) | ||
if not workflow_id: | ||
return None | ||
|
||
try: | ||
|
||
request = getattr( | ||
current_oarepo_workflows.record_workflows[workflow_id].requests(), | ||
request_type.type_id, | ||
) | ||
receiver = request.reference_receivers( | ||
record=record, request_type=request_type, **kwargs | ||
) | ||
return receiver | ||
except (KeyError, AttributeError): | ||
return None | ||
except AttributeError: | ||
raise RequestTypeNotInWorkflow(request_type.type_id, workflow_id) | ||
|
||
receiver = request.reference_receivers( | ||
record=record, request_type=request_type, **kwargs | ||
) | ||
return receiver |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[metadata] | ||
name = oarepo-requests | ||
version = 2.0.1 | ||
version = 2.0.2 | ||
description = | ||
authors = Ronald Krist <[email protected]> | ||
readme = README.md | ||
|
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,59 @@ | ||
import pytest | ||
|
||
from oarepo_requests.errors import OpenRequestAlreadyExists | ||
|
||
from .utils import link_api2testclient | ||
|
||
|
||
def test_conditional_receiver_creator_matches( | ||
logged_client, | ||
users, | ||
urls, | ||
conditional_recipient_request_data_function, | ||
create_draft_via_resource, | ||
search_clear, | ||
): | ||
# user[0] is creator, user[1] is receiver | ||
# user[0] is not a creator, user[2] is receiver | ||
|
||
creator = users[0] | ||
assert creator.id == '1' | ||
|
||
creator_client = logged_client(creator) | ||
|
||
draft1 = create_draft_via_resource(creator_client, custom_workflow="with_ct") | ||
|
||
resp_request_create = creator_client.post( | ||
urls["BASE_URL_REQUESTS"], | ||
json=conditional_recipient_request_data_function(draft1.json["id"]), | ||
) | ||
|
||
assert resp_request_create.status_code == 201 | ||
assert resp_request_create.json["receiver"] == {"user": '2'} | ||
|
||
|
||
def test_conditional_receiver_creator_does_not_match( | ||
logged_client, | ||
users, | ||
urls, | ||
conditional_recipient_request_data_function, | ||
create_draft_via_resource, | ||
search_clear, | ||
): | ||
# user[0] is creator, user[1] is receiver | ||
# user[0] is not a creator, user[2] is receiver | ||
|
||
creator = users[1] | ||
assert creator.id != 1 | ||
|
||
creator_client = logged_client(creator) | ||
|
||
draft1 = create_draft_via_resource(creator_client, custom_workflow="with_ct") | ||
|
||
resp_request_create = creator_client.post( | ||
urls["BASE_URL_REQUESTS"], | ||
json=conditional_recipient_request_data_function(draft1.json["id"]), | ||
) | ||
|
||
assert resp_request_create.status_code == 201 | ||
assert resp_request_create.json["receiver"] == {"user": '3'} |
Oops, something went wrong.