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

Feature: Media Library configure the view #14700

Merged
merged 24 commits into from Dec 19, 2022
Merged

Conversation

jhoward1994
Copy link
Contributor

@jhoward1994 jhoward1994 commented Oct 21, 2022

What does it do?

Adds configure the view to the media library

Why is it needed?

In order to set the default page size and sort order for the Media Library across an entire Strapi project

How to test it?

  1. BE - Through the new routes added in packages/core/upload/server/routes/view-configuration.js
  2. API - Through the E2E tests added in packages/core/upload/tests/admin/configure-view.test.e2e.js
  3. FE - Through the test modifications in packages/core/upload/admin/src/pages/App
  4. Admin - Through the new "Configure the view" button in the Media Library

image

image

Related issue(s)/PR(s)

Frontend changes will be merged into this branch from #14697

@jhoward1994 jhoward1994 added source: core:upload Source is core/upload package pr: feature This PR adds a new feature labels Oct 21, 2022
@jhoward1994 jhoward1994 self-assigned this Oct 21, 2022
@jhoward1994 jhoward1994 marked this pull request as draft October 21, 2022 14:34
@codecov
Copy link

codecov bot commented Oct 21, 2022

Codecov Report

Base: 60.22% // Head: 60.32% // Increases project coverage by +0.10% 🎉

Coverage data is based on head (d2abb08) compared to base (3b57648).
Patch coverage: 95.79% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14700      +/-   ##
==========================================
+ Coverage   60.22%   60.32%   +0.10%     
==========================================
  Files        1355     1368      +13     
  Lines       33048    33282     +234     
  Branches     6324     6357      +33     
==========================================
+ Hits        19903    20079     +176     
- Misses      11297    11356      +59     
+ Partials     1848     1847       -1     
Flag Coverage Δ
back 50.37% <60.00%> (-0.01%) ⬇️
front 64.78% <97.61%> (+0.11%) ⬆️
unit_back 50.37% <60.00%> (-0.01%) ⬇️
unit_front 64.78% <97.61%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/core/admin/server/services/role.js 96.71% <ø> (ø)
packages/core/upload/admin/src/permissions.js 100.00% <ø> (ø)
packages/core/upload/server/services/upload.js 28.01% <0.00%> (-0.56%) ⬇️
...n/src/pages/App/MediaLibrary/components/Filters.js 78.26% <78.26%> (ø)
packages/core/upload/server/bootstrap.js 88.88% <80.00%> (-11.12%) ⬇️
...es/App/MediaLibrary/components/BulkDeleteButton.js 94.44% <94.44%> (ø)
packages/core/upload/admin/src/pages/App/index.js 96.29% <95.23%> (+96.29%) ⬆️
...re/upload/admin/src/components/SortPicker/index.js 100.00% <100.00%> (ø)
packages/core/upload/admin/src/hooks/useConfig.js 100.00% <100.00%> (ø)
...core/upload/admin/src/hooks/useModalQueryParams.js 100.00% <100.00%> (ø)
... and 18 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jhoward1994 jhoward1994 force-pushed the feature/media-library-ctv branch 3 times, most recently from 7091f80 to 4afa486 Compare October 25, 2022 15:16
@jhoward1994 jhoward1994 marked this pull request as ready for review October 25, 2022 15:23
@jhoward1994
Copy link
Contributor Author

Hi @petersg83 @Marc-Roig @nathan-pichon

This PR contains the backend changes to the upload package, adding configure the view with a pageSize option to the ML.

I have another PR targeting this branch for the frontend changes. Once both FE and BE changes are approved I will merge everything here and use this branch for QA :)

test: e2e
chore: naming
Comment on lines 14 to 17
if (userAbility.cannot(ACTIONS.configureView, FILE_MODEL_UID)) {
return ctx.forbidden();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I was looking at the content-manager as a reference and I am seeing each plugin deals with permissions a little bit different. For instance:

  • content-manager has a permissions services, where it registers all the actions & has functions like canConfigureContentType. But in upload we have a constants file.

  • Super minor thing, we say getViewConfiguration here and findViewConfiguration in there.

The part that I understand the less is how actions are registered in the upload plugin. And if there is a "standard"way of doing it in the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review

  • Do you suggest we move to the permission checker service approach in the upload plugin? imo we use the userAbility in quite a simple way in the upload plugin so think calling .cannot directly is clear enough
  • Good point I have renamed it to findViewConfiguration
  • In terms of how the actions are registered you can see in packages/core/admin/server/services/role.js we have added the new permission plugin::upload.configure-view. L285. This is how I understand the functionality:
    • Every time strapi boots the function resetSuperAdminPermissions is run, granting super admins all permissions
    • createRolesIfNoneExist is responsible for assigning permissions to editor and author roles. This is only run on strapis first boot. Therefore the new CTV permission will not automatically be added to editors and authors but can be added through the Admin UI

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you suggest we move to the permission checker service approach in the upload plugin? imo we use the userAbility in quite a simple way in the upload plugin so think calling .cannot directly is clear enough

Agree, I think it is super clean like you have now. So I would leave it as it is!

Thanks a lot for the actions explanation 🙇

@jhoward1994
Copy link
Contributor Author

Hi @joshuaellis & @petersg83. I've addressed your feedback, let me know what you think 🙂

Comment on lines +78 to +79
requests.admin = await createAuthRequest({ strapi });
requests.restricted = await createAuthRequest({ strapi, userInfo: restrictedUser });
Copy link
Contributor

Choose a reason for hiding this comment

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

very clean way to do different auth requests 💡

test('Successfully update the ML view configuration', async () => {
const config = {
pageSize: 100,
sort: sample(ALLOWED_SORT_STRINGS),
Copy link
Contributor

Choose a reason for hiding this comment

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

minor thing, maybe you could use ALLOWED_SORT_STRINGS.slice(1) so it gets a different value from the default one.

Marc-Roig
Marc-Roig previously approved these changes Dec 13, 2022
Copy link
Contributor

@Marc-Roig Marc-Roig left a comment

Choose a reason for hiding this comment

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

LGTM, I left a minor comment in a test file.
When I change the entries per page and click the <- Back button it is correctly changed, but if I use the browser back button I see the previous value and I have to refresh (maybe because the entries per page are stored in the URL params)

joshuaellis
joshuaellis previously approved these changes Dec 13, 2022
@jhoward1994 jhoward1994 added the flag: documentation This PR requires a documentation update label Dec 13, 2022
petersg83
petersg83 previously approved these changes Dec 16, 2022
Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

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

LGTM :) Thanks for the modifications!

@jhoward1994 jhoward1994 removed the flag: documentation This PR requires a documentation update label Dec 19, 2022
@jhoward1994 jhoward1994 merged commit e380a66 into main Dec 19, 2022
@jhoward1994 jhoward1994 deleted the feature/media-library-ctv branch December 19, 2022 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: feature This PR adds a new feature source: core:upload Source is core/upload package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants