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

EZP-30427: Added support to paginate a list of drafts #2753

Merged
merged 6 commits into from
Sep 27, 2019
Merged

Conversation

mikadamczyk
Copy link
Contributor

@mikadamczyk mikadamczyk commented Aug 28, 2019

Question Answer
JIRA issue EZP-30427
Bug/Improvement yes
New feature no
Target version 7.5
BC breaks no
Tests pass yes
Doc needed yes

Added support to paginate a list of drafts. Added additional arguments ($limit and $offset) to ContentService::loadContentDrafts
Added new method ContentService::countContentDrafts to allow paginate content drafts list. This method returns the number of all drafts for the user, including those to which the user has no access.

Instead of adding additional parameters to existing ContentService::loadContentDrafts this PR adds new ContentService::loadContentDraftList to allow paginate and filter content drafts list. New method return ContentDraftList object. It can contain objects which implements ContentDraftListItemInterface. Those can be UnauthorizedContentDraftListItem or ContentDraftListItem

Related PR: ezsystems/ezplatform-admin-ui#1071

TODO:

  • Implement feature / fix a bug.
  • Implement tests.
  • Fix new code according to Coding Standards ($ composer fix-cs).
  • Ask for Code Review.

eZ/Publish/Core/Repository/ContentService.php Outdated Show resolved Hide resolved
eZ/Publish/Core/Repository/ContentService.php Outdated Show resolved Hide resolved
eZ/Publish/Core/Repository/ContentService.php Outdated Show resolved Hide resolved
eZ/Publish/Core/Repository/ContentService.php Outdated Show resolved Hide resolved
*
* @return \eZ\Publish\API\Repository\Values\Content\VersionInfo the drafts ({@link VersionInfo}) owned by the given user
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException

eZ/Publish/API/Repository/ContentService.php Outdated Show resolved Hide resolved
Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

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

Overall looks good.

I would do some API namespace cleanup, because eZ/Publish/API/Repository/Values/Content/ gets too crowded. Please change the API-related file and corresponding namespace structure as agreed during internal sync.

Other remarks:

eZ/Publish/API/Repository/ContentService.php Show resolved Hide resolved
eZ/Publish/API/Repository/ContentService.php Outdated Show resolved Hide resolved
eZ/Publish/API/Repository/ContentService.php Outdated Show resolved Hide resolved
eZ/Publish/Core/SignalSlot/ContentService.php Outdated Show resolved Hide resolved
eZ/Publish/Core/SignalSlot/ContentService.php Outdated Show resolved Hide resolved
eZ/Publish/Core/Repository/ContentService.php Outdated Show resolved Hide resolved
eZ/Publish/Core/Repository/ContentService.php Outdated Show resolved Hide resolved
eZ/Publish/Core/Persistence/Legacy/Content/Handler.php Outdated Show resolved Hide resolved
@mikadamczyk mikadamczyk force-pushed the EZP-30427 branch 2 times, most recently from 6c786c3 to 3713898 Compare September 9, 2019 09:16
@mikadamczyk
Copy link
Contributor Author

ping @alongosz @ViniTou

class ContentDraftListItem implements ContentDraftListItemInterface
{
/**
* @var \eZ\Publish\API\Repository\Values\Content\VersionInfo
Copy link
Member

Choose a reason for hiding this comment

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

I thought you wanted one line class member docs... :trollface:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not about what I want :)

Co-Authored-By: Adam Wójs <adam.wojs@ez.no>
/**
* Item of content drafts list which represents draft to which user has no access for.
*/
class UnauthorizedContentDraftListItem implements ContentDraftListItemInterface
Copy link
Contributor

@andrerom andrerom Sep 18, 2019

Choose a reason for hiding this comment

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

Why do we need to push this logic to API consumer?

As in:

  1. Drafts are personal so at least in the past you usually had access to YOUR drafts.
  2. Even if there are cases where permissions won't let you, then I would expect it to behave like other API methods, aka filter out what you don't have access to. Otherwise paging in UI will have gaps, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ad 1 - You can pass user as an argument to loadContentDrafts(User $user = null) so we have a case with a user's drafts which not belongs to you.
Ad 2 - To create "classic" pagination we need a total number of items. We can not use the search query to get it, because we have zeta components. This is a 3rd line issue and we do not have time to get rid of them. Also, it would be a BC break I think. This is why I used UnauthorizedContentDraftListItem here and then in Admin UI.

Copy link
Contributor

@andrerom andrerom Sep 21, 2019

Choose a reason for hiding this comment

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

Also, it would be a BC break I think

This is for a new new API method, so there is no BC on it before it's released, that is when it will become harder to change all this ;)

Copy link
Contributor

@andrerom andrerom Sep 21, 2019

Choose a reason for hiding this comment

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

You can pass user as an argument to loadContentDrafts(User $user = null) so we have a case with a user's drafts which not belongs to you.

Good point 👍

But........ 😏 Then maybe you just made a very good argument for dropping this argument on the new API method in the first place. If people want to get drafts for other users they can either still use the old one or set current user to the user they want to get drafts for.

Dropping that argument seems like it will avoid a lot of the complexity introduced here.
And it will greatly improve DX for the primary use case: Getting drafts of current user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The goal was to keep all functionalities including the possibility to fetch drafts of another user even if it is a big number of them. Also, it will still be the issue when a user loses access to some of their drafts. I am against developing a feature which is buggy by design, even if it looks like a corner case.

We have a similar problem in content reverse relations where it is a common situation when a user has no access to some contents. And we have the plan to solve this issue in the same way (return the list with two kinds of items)

public $totalCount = 0;

/**
* @var \eZ\Publish\API\Repository\Values\Content\DraftList\ContentDraftListItemInterface[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Depending on the other question this can directly be VersionInfo instead perhaps.

*
* @return \Doctrine\DBAL\Query\QueryBuilder
*/
private function createVersionInfoFindQueryBuilder(): DoctrineQueryBuilder
Copy link
Contributor

@andrerom andrerom Sep 18, 2019

Choose a reason for hiding this comment

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

You can (by now) instead reuse ->queryBuilder-> createVersionInfoQueryBuilder() which was just added as part of #2739

Copy link
Contributor

Choose a reason for hiding this comment

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

EDIT: Partly ignore this, unless we refactor it to work for your use case it won't atm (it expects to give current version or a provided version number only atm, and this one instead uses version table in from which is better in this case)

@micszo micszo self-assigned this Sep 25, 2019
Copy link
Member

@micszo micszo left a comment

Choose a reason for hiding this comment

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

QA Approved with 6k drafts on eZ Platform EE v2.5.5 with both branches.
For the record, on Versions tab effect is not as amazingly smooth as on the Dashboard but also significant.
User does not have access message OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

7 participants