-
Notifications
You must be signed in to change notification settings - Fork 73
[SYNPY-1674]: Implement Form #1288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
linglp
wants to merge
17
commits into
develop
Choose a base branch
from
synpy-1674
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
98bfc00
implement oop to create a form group
9190e95
added data class; be able to create form data using form group id
73bbb5d
allow list form reviewer
704112e
make validating state enum separate from individual function; add lis…
bcbb626
create a helper function for download
56b2b49
add example; fix type hint
d33a026
use protocol; use wrapper
a98ca19
adjust space; add documentation
e846755
export more functions; adjust import
7fa49eb
make imports better; add import in the examples; add test
61b4d84
add mixin test
82e0033
update import
c4e05a7
combining list data and list reviewer
e3119dd
raise value error if filter by state is empty
ba58ee1
rename to form submission status
148f178
edit docstring; just use one call
2f38b6b
remove comments in the docstring
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,22 @@ | ||
| # FormGroup and Form | ||
|
|
||
| Contained within this file are experimental interfaces for working with the Synapse Python | ||
| Client. Unless otherwise noted these interfaces are subject to change at any time. Use | ||
| at your own risk. | ||
|
|
||
| ## API Reference | ||
|
|
||
| ::: synapseclient.models.FormGroup | ||
| options: | ||
| inherited_members: true | ||
| members: | ||
| - create_async | ||
|
|
||
|
|
||
| ::: synapseclient.models.FormData | ||
| options: | ||
| inherited_members: true | ||
| members: | ||
| - create_async | ||
| - list_async | ||
| - download_async |
This file contains hidden or 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 @@ | ||
| ::: synapseclient.models.mixins.FormData |
This file contains hidden or 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 @@ | ||
| ::: synapseclient.models.mixins.FormGroup |
This file contains hidden or 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,22 @@ | ||
| # FormGroup and Form | ||
|
|
||
| Contained within this file are experimental interfaces for working with the Synapse Python | ||
| Client. Unless otherwise noted these interfaces are subject to change at any time. Use | ||
| at your own risk. | ||
|
|
||
| ## API Reference | ||
|
|
||
| ::: synapseclient.models.FormGroup | ||
| options: | ||
| inherited_members: true | ||
| members: | ||
| - create | ||
|
|
||
|
|
||
| ::: synapseclient.models.FormData | ||
| options: | ||
| inherited_members: true | ||
| members: | ||
| - create | ||
| - list | ||
| - download |
This file contains hidden or 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 hidden or 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 hidden or 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,173 @@ | ||
| import json | ||
| from typing import TYPE_CHECKING, Any, AsyncGenerator, Generator, Optional | ||
|
|
||
| from synapseclient.api.api_client import rest_post_paginated_async | ||
| from synapseclient.core.async_utils import wrap_async_generator_to_sync_generator | ||
|
|
||
| if TYPE_CHECKING: | ||
| from synapseclient import Synapse | ||
| from synapseclient.models.mixins.form import StateEnum | ||
|
|
||
|
|
||
| async def create_form_group_async( | ||
| synapse_client: "Synapse", | ||
| name: str, | ||
| ) -> dict[str, Any]: | ||
| """ | ||
| <https://rest-docs.synapse.org/rest/POST/form/group.html> | ||
| Create a form group asynchronously. | ||
|
|
||
| Arguments: | ||
| synapse_client: The Synapse client to use for the request. | ||
| name: A globally unique name for the group. Required. Between 3 and 256 characters. | ||
|
|
||
| Returns: | ||
| A Form group object as a dictionary. | ||
| Object matching <https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/form/FormGroup.html> | ||
| """ | ||
| from synapseclient import Synapse | ||
|
|
||
| client = Synapse.get_client(synapse_client=synapse_client) | ||
|
|
||
| return await client.rest_post_async(uri=f"/form/group?name={name}", body={}) | ||
|
|
||
|
|
||
| async def create_form_data_async( | ||
| synapse_client: "Synapse", | ||
| group_id: str, | ||
| form_change_request: dict[str, Any], | ||
| ) -> dict[str, Any]: | ||
| """ | ||
| <https://rest-docs.synapse.org/rest/POST/form/data.html> | ||
| Create a new FormData object. The caller will own the resulting object and will have access to read, update, and delete the FormData object. | ||
|
|
||
| Arguments: | ||
| synapse_client: The Synapse client to use for the request. | ||
| group_id: The ID of the form group. | ||
| form_change_request: a dictionary of form change request matching <https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/form/FormChangeRequest.html>. | ||
|
|
||
| Returns: | ||
| A Form data object as a dictionary. | ||
| Object matching <https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/form/FormData.html> | ||
|
|
||
| Note: The caller must have the SUBMIT permission on the FormGroup to create/update/submit FormData. | ||
| """ | ||
| from synapseclient import Synapse | ||
|
|
||
| client = Synapse.get_client(synapse_client=synapse_client) | ||
|
|
||
| return await client.rest_post_async( | ||
| uri=f"/form/data?groupId={group_id}", | ||
| body=json.dumps(form_change_request), | ||
| ) | ||
|
|
||
|
|
||
| async def list_form_data_async( | ||
| synapse_client: "Synapse", | ||
| group_id: str, | ||
| filter_by_state: Optional[list["StateEnum"]] = None, | ||
| as_reviewer: bool = False, | ||
| ) -> AsyncGenerator[dict[str, Any], None]: | ||
| """ | ||
| List FormData objects and their associated status that match the filters of the provided request. | ||
|
|
||
| When as_reviewer=False: <https://rest-docs.synapse.org/rest/POST/form/data/list.html> | ||
| Returns FormData objects owned by the caller. Only objects owned by the caller will be returned. | ||
|
|
||
| When as_reviewer=True: <https://rest-docs.synapse.org/rest/POST/form/data/list/reviewer.html> | ||
| Returns FormData objects for the entire group. This is used by service accounts to review submissions. | ||
| Requires READ_PRIVATE_SUBMISSION permission on the FormGroup. | ||
|
|
||
| Arguments: | ||
| synapse_client: The Synapse client to use for the request. | ||
| group_id: The ID of the form group. Required. | ||
| filter_by_state: Optional list of StateEnum values to filter the FormData objects. | ||
| When as_reviewer=False (default), valid values are: | ||
| - StateEnum.WAITING_FOR_SUBMISSION | ||
| - StateEnum.SUBMITTED_WAITING_FOR_REVIEW | ||
| - StateEnum.ACCEPTED | ||
| - StateEnum.REJECTED | ||
| If None, returns all FormData objects. | ||
|
|
||
| When as_reviewer=True, valid values are: | ||
| - StateEnum.SUBMITTED_WAITING_FOR_REVIEW (default if None) | ||
| - StateEnum.ACCEPTED | ||
| - StateEnum.REJECTED | ||
| Note: WAITING_FOR_SUBMISSION is NOT allowed when as_reviewer=True. | ||
|
|
||
| as_reviewer: If True, uses the reviewer endpoint to list FormData for the entire group. | ||
| If False (default), lists only FormData owned by the caller. | ||
|
|
||
| Yields: | ||
| A single page of FormData objects matching the request. | ||
| Object matching <https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/form/ListResponse.html> | ||
| """ | ||
| from synapseclient import Synapse | ||
|
|
||
| client = Synapse.get_client(synapse_client=synapse_client) | ||
|
|
||
| body: dict[str, Any] = {"groupId": group_id, "filterByState": filter_by_state} | ||
|
|
||
| if as_reviewer: | ||
| uri = "/form/data/list/reviewer" | ||
| else: | ||
| uri = "/form/data/list" | ||
|
|
||
| async for item in rest_post_paginated_async( | ||
| uri=uri, | ||
| body=body, | ||
| synapse_client=client, | ||
| ): | ||
| yield item | ||
|
|
||
|
|
||
| def list_form_data_sync( | ||
| synapse_client: "Synapse", | ||
| group_id: str, | ||
| filter_by_state: Optional[list["StateEnum"]] = None, | ||
| as_reviewer: bool = False, | ||
| ) -> Generator[dict[str, Any], None, None]: | ||
| """ | ||
| List FormData objects and their associated status that match the filters of the provided request. | ||
|
|
||
| This is the synchronous version of list_form_data_async. | ||
|
|
||
| When as_reviewer=False: <https://rest-docs.synapse.org/rest/POST/form/data/list.html> | ||
| Returns FormData objects owned by the caller. Only objects owned by the caller will be returned. | ||
|
|
||
| When as_reviewer=True: <https://rest-docs.synapse.org/rest/POST/form/data/list/reviewer.html> | ||
| Returns FormData objects for the entire group. This is used by service accounts to review submissions. | ||
| Requires READ_PRIVATE_SUBMISSION permission on the FormGroup. | ||
|
|
||
| Arguments: | ||
| synapse_client: The Synapse client to use for the request. | ||
| group_id: The ID of the form group. Required. | ||
| filter_by_state: Optional list of StateEnum values to filter the FormData objects. | ||
| When as_reviewer=False (default), valid values are: | ||
| - StateEnum.WAITING_FOR_SUBMISSION | ||
| - StateEnum.SUBMITTED_WAITING_FOR_REVIEW | ||
| - StateEnum.ACCEPTED | ||
| - StateEnum.REJECTED | ||
| If None, returns all FormData objects. | ||
|
|
||
| When as_reviewer=True, valid values are: | ||
| - StateEnum.SUBMITTED_WAITING_FOR_REVIEW (default if None) | ||
| - StateEnum.ACCEPTED | ||
| - StateEnum.REJECTED | ||
| Note: WAITING_FOR_SUBMISSION is NOT allowed when as_reviewer=True. | ||
|
|
||
| as_reviewer: If True, uses the reviewer endpoint to list FormData for the entire group. | ||
| If False (default), lists only FormData owned by the caller. | ||
|
|
||
| Yields: | ||
| A single page of FormData objects matching the request. | ||
| Object matching <https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/form/ListResponse.html> | ||
| """ | ||
| return wrap_async_generator_to_sync_generator( | ||
| list_form_data_async( | ||
| synapse_client=synapse_client, | ||
| group_id=group_id, | ||
| filter_by_state=filter_by_state, | ||
| as_reviewer=as_reviewer, | ||
| ) | ||
| ) | ||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.