Skip to content

Commit

Permalink
Merge pull request #2538 from auslin-aot/feature/fwf-3748-submissions…
Browse files Browse the repository at this point in the history
…-count-client-form-list

Bugfix: FWF-3748:  Fix keyerror for a user with create_designs and create_submissions on accessing formlist with includeSubmissionsCount=true
  • Loading branch information
arun-s-aot authored Jan 21, 2025
2 parents 615cb28 + ce763e3 commit f01729c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def get(): # pylint: disable=too-many-locals
is_designer=is_designer,
active_forms=active_forms,
include_submissions_count=include_submissions_count,
ignore_designer=ignore_designer,
)
return (
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def get_all_forms( # pylint: disable=too-many-positional-arguments
is_designer: bool,
active_forms: bool,
include_submissions_count: bool,
ignore_designer: bool,
**kwargs,
): # pylint: disable=too-many-arguments, too-many-locals
"""Get all forms."""
Expand Down Expand Up @@ -93,7 +94,13 @@ def get_all_forms( # pylint: disable=too-many-positional-arguments
)
mapper_schema = FormProcessMapperSchema()
mappers_response = mapper_schema.dump(mappers, many=True)
if include_submissions_count and CREATE_SUBMISSIONS in user.roles:
# Submissions count should return only for user with create_submissions permission
# & client form listing with showForOnlyCreateSubmissionUsers param true
if (
include_submissions_count
and CREATE_SUBMISSIONS in user.roles
and ignore_designer
):
current_app.logger.debug("Fetching submissions count..")
for mapper in mappers_response:
mapper["submissionsCount"] = (
Expand Down
2 changes: 1 addition & 1 deletion forms-flow-api/tests/unit/api/test_form_process_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def test_form_list_submission_count(app, client, session, jwt, create_mapper):
token = get_token(jwt, role=CREATE_SUBMISSIONS)
headers = {"Authorization": f"Bearer {token}", "content-type": "application/json"}
# submissionsCount exclude draft and return submission count
response = client.get("/form?includeSubmissionsCount=true", headers=headers)
response = client.get("/form?includeSubmissionsCount=true&showForOnlyCreateSubmissionUsers=true", headers=headers)
assert response.status_code == 200
forms = response.json["forms"]
assert len(forms) == 1
Expand Down

0 comments on commit f01729c

Please sign in to comment.