Skip to content
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

SLEEP-1439 Add permission for offline setup zip download #1569

Merged
merged 3 commits into from
Aug 27, 2024
Merged

Conversation

bramj
Copy link
Contributor

@bramj bramj commented Aug 21, 2024

Also: Enable task api in case of access to offline setup file.

Without this, the user will see an error when the frontend tries to render the progress bar.

Related JIRA tickets : SLEEP-1439 (already in Trypelim)

Print screen / video

2024-08-21_10-27

How to test

  • There should be a new permission "Télécharger l'installation hors ligne de l'application mobile" visible in the user management screen
  • When you have this new permission, you see this icon appear as a new user action, allowing you to download a mobile app setup-zip as this user:
    2024-08-21_14-35
  • If you don't have the permission, you don't see the action on the users

@bramj bramj requested a review from hakifran August 21, 2024 08:34
@beygorghor
Copy link
Collaborator

@hakifran we need a review here i think please !

@hakifran
Copy link
Contributor

@hakifran we need a review here i think please !

I'm reviewing it

@@ -92,7 +92,10 @@ export const usersTableColumns = ({
}
/>
)}
{currentUser.is_superuser && (
{userHasPermission(
Permission.MOBILE_APP_OFFLINE_SETUP,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be achieved by using
<DisplayIfUserHasPerm permissions={[Permission.MOBILE_APP_OFFLINE_SETUP]} > <ExportMobileAppSetupDialog selectedUser={settings.row.original} titleMessage={MESSAGES.exportMobileAppTitle} params={params} onCreateExport={exportMobileSetup} /> </DisplayIfUserHasPerm>
import { DisplayIfUserHasPerm } from '../../components/DisplayIfUserHasPerm.tsx';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 adapted

@@ -72,7 +72,7 @@ class TaskSourceViewSet(ModelViewSet):
PATCH /api/tasks/<id>
"""

permission_classes = [permissions.IsAuthenticated, HasPermission(permission.DATA_TASKS)] # type: ignore
permission_classes = [permissions.IsAuthenticated, HasPermission(permission.DATA_TASKS, permission.MOBILE_APP_OFFLINE_SETUP)] # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bramj I don't understand why this permission is checked here in TaskSourceVIewSet as this is about:
"""Task API

GET /api/tasks/
GET /api/tasks/<id>
PATCH /api/tasks/<id>
"""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was needed to enable me to display a progress bar on the zip creation (which polled the GET /api/tasks/:id that was just created).

However, you're right that it is not clear, and too permissive, so I've changed the behavior of only the GET /api/tasks/<id> endpoint.

Basically: keep the tasks endpoint permissions as is, but allow a user to query the state of a task launched by themselves, even if they don't have the DATA_TASKS permission.

IMO it makes sense to allow this, but only on the retrieve endpoint and only for tasks created by the user themself.

@hakifran what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bramj I do think that the user who launch the task should have the DATA_TASKS, if not don't let him launch the mobile app offline setup. Because on my point of view this can lead to a confusion about permissions. @beygorghor or @madewulf can give their point of view on this. thank you

@beygorghor beygorghor added the release Should be released in production at next deploy label Aug 23, 2024
bramj added 3 commits August 26, 2024 16:03
Also: Enable task api in case of access to offline setup file.

Without this, the user will see an error when the frontend tries to
render the progress bar.
such as for the generation of the mobile app setup zip.

Basically: keep the tasks endpoint permissions as is, but allow a user
to query the state of a task launched by themselves, even if they don't
have the "DATA_TASKS" permission.

E.g. For the download of the mobile app setup zip, we display a progress
bar. To display this, we fetch the task that was just created. But if
the user doesn't have the DATA_TASKS permission, this doesn't work.
It makes sense to allow this, but only on the `retrieve` endpoint and
only for tasks created by the user themself.
@bramj bramj merged commit 8b1cc14 into main Aug 27, 2024
4 of 5 checks passed
@bramj bramj deleted the SLEEP-1439 branch August 27, 2024 08:48
@kemar kemar removed the release Should be released in production at next deploy label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants