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-30139: As an editor I want to hide and reveal a content item #865

Merged
merged 8 commits into from
Mar 4, 2019

Conversation

pawbuj
Copy link
Contributor

@pawbuj pawbuj commented Feb 28, 2019

Question Answer
Tickets EZP-30139
Bug fix? no
New feature? yes
BC breaks? no
Tests pass? yes
Doc needed? yes
License GPL-2.0

Admin UI for hide/reveal content

Checklist:

  • Coding standards ($ composer fix-cs)
  • Ready for Code Review

@lserwatka
Copy link
Member

@pawbuj rebase is needed.

@dew326
Copy link
Member

dew326 commented Mar 1, 2019

You don't have to compile AlloyEditor.

@pawbuj
Copy link
Contributor Author

pawbuj commented Mar 1, 2019

@dew326 done

@pawbuj
Copy link
Contributor Author

pawbuj commented Mar 1, 2019

@lserwatka done

src/bundle/Resources/public/scss/_icons.scss Outdated Show resolved Hide resolved
src/bundle/Resources/public/scss/_icons.scss Outdated Show resolved Hide resolved
src/bundle/Resources/public/scss/_mixins.scss Outdated Show resolved Hide resolved
src/bundle/Resources/public/scss/_mixins.scss Outdated Show resolved Hide resolved
src/bundle/Resources/public/scss/_mixins.scss Outdated Show resolved Hide resolved
src/bundle/Resources/public/scss/_mixins.scss Outdated Show resolved Hide resolved
src/bundle/Resources/views/content/locationview.html.twig Outdated Show resolved Hide resolved
$contentInfo = $contentData->getContentInfo();
$location = $contentData->getLocation();

if ($contentInfo->isHidden) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this not be handled inside data object?

$form = $this->createForm(ContentType::class);
$form->handleRequest($request);

if (!$form->isSubmitted() || !$form->isValid()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

submit handler for those?

src/bundle/Controller/ContentViewController.php Outdated Show resolved Hide resolved
src/bundle/Controller/ContentViewController.php Outdated Show resolved Hide resolved
src/lib/Form/Data/Content/ContentData.php Outdated Show resolved Hide resolved
$form->handleRequest($request);

if (!$form->isSubmitted() || !$form->isValid()) {
throw new BadRequestHttpException();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we used to return information with errors

Copy link
Contributor

Choose a reason for hiding this comment

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

Because we can not find place where similar notification are displayed do not take this into account

/** @var \EzSystems\EzPlatformAdminUi\Form\Data\Content\ContentData $contentData */
$contentData = $form->getData();
$contentInfo = $contentData->getContentInfo();
$location = $contentData->getLocation();
Copy link
Contributor

Choose a reason for hiding this comment

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

in EzSystems\EzPlatformAdminUi\Form\Data\Content\ContentData getLocation() can return null and below we have redirectToLocation(). Will not it be a problem?

/**
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
*/
private function supplyContentReverseRelations(ContentView $view)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private function supplyContentReverseRelations(ContentView $view)
private function supplyContentReverseRelations(ContentView $view): void

src/bundle/Resources/public/img/ez-icons.svg Show resolved Hide resolved
<svg class="ez-icon ez-alert--icon">
<use xlink:href="/bundles/ezplatformadminui/img/ez-icons.svg#hide"></use>
</svg>
{{ 'content.hidden.message'|trans()|desc('This content item is hidden and is not publicly available') }}</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

</div> at the end should be in the new line

</table>
<table class="ez-table table">
<thead>
<tr>
Copy link
Contributor

Choose a reason for hiding this comment

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

please, fix indentation

type="checkbox"
name="updateVisibility"
{% if not can_hide[location.id] %} disabled="disabled"{% endif %}
value="{{ location.id }}">
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
value="{{ location.id }}">
value="{{ location.id }}" />

{{ location.main ? 'checked' }}
{{ not location.canEdit ? 'disabled' }}
name="updateMainLocation"
value="{{ location.id }}">
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
value="{{ location.id }}">
value="{{ location.id }}" />

private $location;

/**
* ContentData constructor.
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment is not needed

Copy link
Contributor

@webhdx webhdx left a comment

Choose a reason for hiding this comment

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

I don't think ContentType and ContentData is a good approach. First, ContentType is very confusing name in our domain. ContentData should not have getLocation() method inside. We tend to have specific Type+Data class for every action. I'd go for ContentVisibilityUpdateType and matching Data class.

$contentInfo = $view->getLocation()->getContentInfo();
$relations = $this->contentService->loadReverseRelations($contentInfo);

$view->addParameters(['contentHasReverseRelations' => (bool)count($relations)]);
Copy link
Contributor

Choose a reason for hiding this comment

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

We use underscore names in Twig. Also small nitpick: count(...) > 0 feels more logical and is easier to understand.

<div class="ez-modal-body__main">
<p>
{{ 'content.hide.modal.message1'|trans()|desc('This item is being used by other content item(s). Please remove all instance(s) to avoid a 404 error.') }}<br/>
{{ 'content.hide.modal.message2'|trans()|desc('If you wish to continue, please click on Confirm.') }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use more meaningful translation keys.

</div>
</div>
</div>
</div>
Copy link
Member

Choose a reason for hiding this comment

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

Missing line feed at the end of this file

@ezrobot
Copy link

ezrobot commented Mar 4, 2019

Tool version : PHP CS Fixer 2.7.1 Sandy Pool by Fabien Potencier and Dariusz Ruminski
Command executed php-cs-fixer --dry-run -v fix
This Pull Request does not respect PSR-2 Coding Standards, please, see the suggested diff below:

diff --git a/src/bundle/Controller/ContentController.php b/src/bundle/Controller/ContentController.php
index eea0e78..ac9fa7d 100644
--- a/src/bundle/Controller/ContentController.php
+++ b/src/bundle/Controller/ContentController.php
@@ -4,7 +4,6 @@
  * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  * @license For full copyright and license information view LICENSE file distributed with this source code.
  */
-
 namespace EzSystems\EzPlatformAdminUiBundle\Controller;
 
 use eZ\Publish\API\Repository\ContentService;
@@ -34,7 +33,6 @@ use EzSystems\EzPlatformAdminUi\Specification\ContentType\ContentTypeIsUser;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
 use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
 use Symfony\Component\Translation\Exception\InvalidArgumentException;
 use Symfony\Component\Translation\TranslatorInterface;
@@ -196,7 +194,7 @@ class ContentController extends Controller
 
                     $this->notificationHandler->success(
                         $this->translator->trans(
-                        /** @Desc("New Version Draft for '%name%' created.") */
+                            /** @Desc("New Version Draft for '%name%' created.") */
                             'content.create_draft.success',
                             ['%name%' => $contentInfo->name],
                             'content'
@@ -259,7 +257,7 @@ class ContentController extends Controller
 
                 $this->notificationHandler->success(
                     $this->translator->trans(
-                    /** @Desc("Main location for '%name%' updated.") */
+                        /** @Desc("Main location for '%name%' updated.") */
                         'content.main_location_update.success',
                         ['%name%' => $contentInfo->name],
                         'content'
@@ -357,7 +355,7 @@ class ContentController extends Controller
                 $this->contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);
                 $this->notificationHandler->success(
                     $this->translator->trans(
-                    /** @Desc("Main language for '%name%' updated.") */
+                        /** @Desc("Main language for '%name%' updated.") */
                         'content.main_language_update.success',
                         ['%name%' => $contentInfo->name],
                         'content'
@@ -398,14 +396,13 @@ class ContentController extends Controller
 
         if ($form->isSubmitted()) {
             $this->submitHandler->handle($form, function (ContentVisibilityUpdateData $data) {
-
                 $contentInfo = $data->getContentInfo();
                 $newValue = $data->getVisible();
 
                 if ($contentInfo->isHidden && $newValue === false) {
                     return $this->notificationHandler->success(
                         $this->translator->trans(
-                        /** @Desc("Content '%name%' was already hidden.") */
+                            /** @Desc("Content '%name%' was already hidden.") */
                             'content.hide.already_hidden',
                             ['%name%' => $contentInfo->name],
                             'content'
@@ -416,7 +413,7 @@ class ContentController extends Controller
                 if (!$contentInfo->isHidden && $newValue === true) {
                     return $this->notificationHandler->success(
                         $this->translator->trans(
-                        /** @Desc("Content '%name%' was already visible.") */
+                            /** @Desc("Content '%name%' was already visible.") */
                             'content.reveal.already_visible',
                             ['%name%' => $contentInfo->name],
                             'content'
@@ -426,9 +423,10 @@ class ContentController extends Controller
 
                 if ($newValue === false) {
                     $this->contentService->hideContent($contentInfo);
+
                     return $this->notificationHandler->success(
                         $this->translator->trans(
-                        /** @Desc("Content '%name%' has been hidden.") */
+                            /** @Desc("Content '%name%' has been hidden.") */
                             'content.hide.success',
                             ['%name%' => $contentInfo->name],
                             'content'
@@ -438,16 +436,16 @@ class ContentController extends Controller
 
                 if ($newValue === true) {
                     $this->contentService->revealContent($contentInfo);
+
                     return $this->noti(...)

NOTICE : Report truncated to 5Kb

@ezrobot
Copy link

ezrobot commented Mar 4, 2019

Tool version : PHP CS Fixer 2.7.1 Sandy Pool by Fabien Potencier and Dariusz Ruminski
Command executed php-cs-fixer --dry-run -v fix
This Pull Request does not respect PSR-2 Coding Standards, please, see the suggested diff below:

diff --git a/src/bundle/Controller/ContentController.php b/src/bundle/Controller/ContentController.php
index eea0e78..ac9fa7d 100644
--- a/src/bundle/Controller/ContentController.php
+++ b/src/bundle/Controller/ContentController.php
@@ -4,7 +4,6 @@
  * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  * @license For full copyright and license information view LICENSE file distributed with this source code.
  */
-
 namespace EzSystems\EzPlatformAdminUiBundle\Controller;
 
 use eZ\Publish\API\Repository\ContentService;
@@ -34,7 +33,6 @@ use EzSystems\EzPlatformAdminUi\Specification\ContentType\ContentTypeIsUser;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
 use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
 use Symfony\Component\Translation\Exception\InvalidArgumentException;
 use Symfony\Component\Translation\TranslatorInterface;
@@ -196,7 +194,7 @@ class ContentController extends Controller
 
                     $this->notificationHandler->success(
                         $this->translator->trans(
-                        /** @Desc("New Version Draft for '%name%' created.") */
+                            /** @Desc("New Version Draft for '%name%' created.") */
                             'content.create_draft.success',
                             ['%name%' => $contentInfo->name],
                             'content'
@@ -259,7 +257,7 @@ class ContentController extends Controller
 
                 $this->notificationHandler->success(
                     $this->translator->trans(
-                    /** @Desc("Main location for '%name%' updated.") */
+                        /** @Desc("Main location for '%name%' updated.") */
                         'content.main_location_update.success',
                         ['%name%' => $contentInfo->name],
                         'content'
@@ -357,7 +355,7 @@ class ContentController extends Controller
                 $this->contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);
                 $this->notificationHandler->success(
                     $this->translator->trans(
-                    /** @Desc("Main language for '%name%' updated.") */
+                        /** @Desc("Main language for '%name%' updated.") */
                         'content.main_language_update.success',
                         ['%name%' => $contentInfo->name],
                         'content'
@@ -398,14 +396,13 @@ class ContentController extends Controller
 
         if ($form->isSubmitted()) {
             $this->submitHandler->handle($form, function (ContentVisibilityUpdateData $data) {
-
                 $contentInfo = $data->getContentInfo();
                 $newValue = $data->getVisible();
 
                 if ($contentInfo->isHidden && $newValue === false) {
                     return $this->notificationHandler->success(
                         $this->translator->trans(
-                        /** @Desc("Content '%name%' was already hidden.") */
+                            /** @Desc("Content '%name%' was already hidden.") */
                             'content.hide.already_hidden',
                             ['%name%' => $contentInfo->name],
                             'content'
@@ -416,7 +413,7 @@ class ContentController extends Controller
                 if (!$contentInfo->isHidden && $newValue === true) {
                     return $this->notificationHandler->success(
                         $this->translator->trans(
-                        /** @Desc("Content '%name%' was already visible.") */
+                            /** @Desc("Content '%name%' was already visible.") */
                             'content.reveal.already_visible',
                             ['%name%' => $contentInfo->name],
                             'content'
@@ -426,9 +423,10 @@ class ContentController extends Controller
 
                 if ($newValue === false) {
                     $this->contentService->hideContent($contentInfo);
+
                     return $this->notificationHandler->success(
                         $this->translator->trans(
-                        /** @Desc("Content '%name%' has been hidden.") */
+                            /** @Desc("Content '%name%' has been hidden.") */
                             'content.hide.success',
                             ['%name%' => $contentInfo->name],
                             'content'
@@ -438,16 +436,16 @@ class ContentController extends Controller
 
                 if ($newValue === true) {
                     $this->contentService->revealContent($contentInfo);
+
                     return $this->noti(...)

NOTICE : Report truncated to 5Kb

@pawbuj pawbuj requested review from dew326 and mikadamczyk March 4, 2019 10:34
/**
* Redirects to the previous URL or to the dashboard if referer is different host.
*
* @param Request $request
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Please use FQCN (also applicable in other places).

@@ -381,4 +383,72 @@ public function updateMainTranslationAction(Request $request): Response

return $this->redirectToRoute('ezplatform.dashboard');
}

/**
* @param Request $request
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Please use FQCN.

/**
* @param Request $request
*
* @return Response
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Please use FQCN.

src/bundle/Resources/public/scss/_modals.scss Show resolved Hide resolved
@pawbuj pawbuj requested a review from adamwojs March 4, 2019 10:58
*/
public function redirectBack(Request $request): RedirectResponse
{
$referer = $request->headers->get('referer');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not convinced with this method. You don't know what's inside referrer. Even though it won't redirect you to different domain it's still not predictable.

In your case you can simply redirect user back to Content View.

/**
* Redirects to the previous URL or to the dashboard if referer is different host
*
* @param Request $request
Copy link
Contributor

Choose a reason for hiding this comment

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

FQCN

});
}

return $this->redirectBack($request);
Copy link
Contributor

@webhdx webhdx Mar 4, 2019

Choose a reason for hiding this comment

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

$contentInfo = $data->getContentInfo();
$newValue = $data->getVisible();

if ($contentInfo->isHidden && $newValue === false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could those two ifs be handled inside DataForm validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

then, the behaviour will change, I do not want to show an error to the user if everything is ok.

@pawbuj pawbuj requested review from webhdx and ViniTou and removed request for webhdx March 4, 2019 13:23
@lserwatka lserwatka merged commit b3a97e5 into master Mar 4, 2019
@lserwatka lserwatka deleted the EZP-30139 branch March 4, 2019 15:30
konradoboza pushed a commit to konradoboza/ezplatform-admin-ui that referenced this pull request May 29, 2019
…ystems#865)

* EZP-30139: As an editor I want to hide and reveal a content item

* cs fixes and refactoring

* fixes js cs

* cs fixes

* more cs fixes

* cs fixes

* fix

* fixes
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.

10 participants