getodk / getodk/central

Form count is not always filtered

Open
#687 4 comments 0 reactions 0 assignees View on GitHub
backend
Dominant language
JavaScript
Stars
226
Forks
235
Avg merge
2d 22h
Merged PRs (30d)
19

Description

#### Problem description

Central filters the list of forms that it returns to the user based on the user's role on the project. For example:

- A Data Collector user will not see closed or draft forms.
- A Project Viewer will not see closing forms.

That's true both on the homepage and on the forms page.

However, this filter is not applied to the `forms` count returned with the extended metadata of the individual project response (on the forms page). The `forms` count always includes all forms.

That differs from the `forms` count returned with the project list on the homepage (/v1/projects?forms=true). That count does seem to be filtered. That said, I suspect that if ?forms=true were not specified, then the count would not be filtered (though I haven't confirmed this).

To summarize:

- /v1/projects/:id/forms: filters the list
- /v1/projects/:id (extended metadata): doesn't filter `forms`
- /v1/projects?forms=true: filters `formList` and `forms`
- /v1/projects (extended metadata but not ?forms=true): doesn't filter `forms` (I think)

I don't think we surface the `forms` count in a lot of places in Frontend. If it differs from the form list response on a project page, Frontend will automatically update it to match the form list in order to reduce inconsistency. There is one case I can think of where a Project Viewer would briefly see the non-filtered count. If a Project Viewer navigates to the forms page, then between when they receive the project response and the form list response, they will see the non-filtered count.

#### URL of the page

https://staging.getodk.cloud/#/projects/90

#### Steps to reproduce the problem

- Create a new project.
- Create a form, publish it, then change its form state to closing.
- Create a form, but don't publish it or change its form state.
- Add a non-admin user to the project as a Project Viewer. Log in as that user.
- Navigate to the forms page. Only one form is shown. However, if you open the Network tab of Chrome devtools, you will see that 2 was returned for the `forms` count.
- Log back in as the first user.
- Change the non-admin user to a Data Collector. Log back in as that user.
- Navigate to the forms page. Again, only one form is shown, but the Network tab shows 2 for the `forms` count.

#### Expected behavior

The `forms` count should always be filtered.

#### Central version shown in version.txt

```
versions:
e49518adb84f88d7bc6c3626fc77584dfc935435 (v2024.1.0-6-ge49518a)
+2a291e718f2d342148f3f958691875bacadc7596 client (v2024.1.0-22-g2a291e71)
+beea5c81bf225b5e9da613c38269f07466cae613 server (v2024.1.0-21-gbeea5c81)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.