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

Add ContentDownloadRequest viewset and connect with 'My Downloads' #10379

Closed
bjester opened this issue Apr 4, 2023 · 0 comments · Fixed by #10574
Closed

Add ContentDownloadRequest viewset and connect with 'My Downloads' #10379

bjester opened this issue Apr 4, 2023 · 0 comments · Fixed by #10574
Assignees
Labels
APP: Learn Re: Learn App (content, quizzes, lessons, etc.) DEV: backend Python, databases, networking, filesystem... DEV: frontend P0 - critical Priority: Release blocker or regression TAG: new feature New user-facing feature

Comments

@bjester
Copy link
Member

bjester commented Apr 4, 2023

Depends on: #10365

Background

In order to provide the backend for the 'My Downloads' page, we need a new API viewset that will return a list of users downloads.

Deliverables

The ContentDownloadRequestViewSet

a) It should inherit ValuesViewset
b) It should operate upon the model ContentDownloadRequest

The ContentDownloadRequestViewSet: list response

c) It should always filter the queryset for the request user. For example:

.filter(
  source_model=FacilityUser.morango_model_name,
  source_id=request.user.id,
)

d) It should filter out any download requests that have a corresponding removal. For example:

.annotate(
  has_removal=Exists(
    ContentRemovalRequest.objects.filter(
      source_model=OuterRef("source_model"),
      source_id=OuterRef("source_id"),
      contentnode_id=OuterRef("contentnode_id"),
      requested_at__gte=OuterRef("requested_at")
    )
  )
  .filter(has_removal=False)
)

e) It should map the model field source_id to the response field user_id
f) It should annotate ContentNode metadata for each request, either returning from stored within ContentDownloadRequest.metadata or preferably ContentNode if the metadata has already been imported

  • It should return title, kind, learning_activities, and total_size of necessary files

g) It should paginate the list response in groups of 25

The ContentDownloadRequestViewSet: request creation

There are two cases to handle for request creation:

  1. There is no ContentDownloadRequest model that matches this resource for this user - in which case the following steps should be taken:
    a) It should allow creation of a ContentDownloadRequest model for a user
    b) It should create the model with the appropriate fields. See ContentRequest.build_for_user
    c) It should accept metadata to store in ContentRequest.metadata for rendering until metadata has been imported

This should be robust to the request already existing, and not error.

  1. There is a ContentRemovalRequest model that matches this resource for this user, in which case it should be deleted.

In normal operation only one of these cases will be true, but it is probably safer to handle both on every creation request to be sure.

The ContentDownloadRequestViewSet: request deletion

a) It should create a ContentRemovalRequest model for a user
b) It should create the model with the appropriate fields. See ContentRequest.build_for_user

This should be robust to the removal already existing and not error.

The composable useDownloadRequests

a) It should be updated to query the new API viewset added above
Note: there are slight differences in the fields wrt what has been implemented on the frontend

The Vue component DownloadsList

a) It should be updated with changes to the useDownloadRequests composable
b) It should be updated to handle the API response fields

Acceptance criteria

The 'My Downloads' page should become functional as designed in the Figma spec https://www.figma.com/file/MpCG7r5PULOCJsEvnTSti8/Android-Designs-2022?node-id=194-2922

References

#10137

@bjester bjester added TAG: new feature New user-facing feature P0 - critical Priority: Release blocker or regression DEV: backend Python, databases, networking, filesystem... APP: Learn Re: Learn App (content, quizzes, lessons, etc.) DEV: frontend labels Apr 4, 2023
@marcellamaki marcellamaki self-assigned this Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APP: Learn Re: Learn App (content, quizzes, lessons, etc.) DEV: backend Python, databases, networking, filesystem... DEV: frontend P0 - critical Priority: Release blocker or regression TAG: new feature New user-facing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants