Skip to content

Commit

Permalink
Add quick revision visibility reset button (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdekker authored Sep 7, 2024
1 parent 8844caf commit aa91405
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 3 deletions.
42 changes: 42 additions & 0 deletions src/Controller/App/Revision/ResetRevisionVisibilityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

namespace DR\Review\Controller\App\Revision;

use DR\Review\Controller\AbstractController;
use DR\Review\Controller\App\Review\ReviewController;
use DR\Review\Entity\Review\CodeReview;
use DR\Review\Repository\Revision\RevisionVisibilityRepository;
use DR\Review\Security\Role\Roles;
use DR\Review\Service\CodeReview\CodeReviewRevisionService;
use DR\Review\Service\Revision\RevisionVisibilityService;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

class ResetRevisionVisibilityController extends AbstractController
{
public function __construct(
private readonly RevisionVisibilityService $visibilityService,
private readonly RevisionVisibilityRepository $visibilityRepository,
private readonly CodeReviewRevisionService $revisionService
) {
}

#[Route('app/reviews/{id<\d+>}/revision-visibility/reset', name: self::class, methods: 'POST')]
#[IsGranted(Roles::ROLE_USER)]
public function __invoke(#[MapEntity] CodeReview $review): RedirectResponse
{
$revisions = $this->revisionService->getRevisions($review);
$visibilities = $this->visibilityService->getRevisionVisibilities($review, $revisions, $this->getUser());

// set all visible
foreach ($visibilities as $visibility) {
$visibility->setVisible(true);
}
$this->visibilityRepository->saveAll($visibilities, true);

return $this->refererRedirect(ReviewController::class, ['review' => $review]);
}
}
10 changes: 10 additions & 0 deletions templates/app/review/review.sidebar.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
{% endif %}
</a>
</li>
{% if reviewModel.visibleRevisionCount != reviewModel.revisions|length %}
<li class="nav-item" title="{{ 'show.all.revisions'|trans }}">
<form method="post"
action="{{ path('DR\\Review\\Controller\\App\\Revision\\ResetRevisionVisibilityController', {id: review.id}) }}">
<button type="submit" class="nav-link" {{ stimulus_controller('button') }}>
<i class="bi-eye-fill"></i> {{ 'all'|trans }}
</button>
</form>
</li>
{% endif %}
</ul>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);

namespace DR\Review\Tests\Unit\Controller\App\Revision;

use DR\Review\Controller\AbstractController;
use DR\Review\Controller\App\Review\ReviewController;
use DR\Review\Controller\App\Revision\ResetRevisionVisibilityController;
use DR\Review\Entity\Review\CodeReview;
use DR\Review\Entity\Revision\Revision;
use DR\Review\Entity\Revision\RevisionVisibility;
use DR\Review\Entity\User\User;
use DR\Review\Repository\Revision\RevisionVisibilityRepository;
use DR\Review\Service\CodeReview\CodeReviewRevisionService;
use DR\Review\Service\Revision\RevisionVisibilityService;
use DR\Review\Tests\AbstractControllerTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;

#[CoversClass(ResetRevisionVisibilityController::class)]
class ResetRevisionVisibilityControllerTest extends AbstractControllerTestCase
{
private RevisionVisibilityService&MockObject $visibilityService;
private RevisionVisibilityRepository&MockObject $visibilityRepository;
private CodeReviewRevisionService&MockObject $revisionService;

protected function setUp(): void
{
$this->visibilityService = $this->createMock(RevisionVisibilityService::class);
$this->visibilityRepository = $this->createMock(RevisionVisibilityRepository::class);
$this->revisionService = $this->createMock(CodeReviewRevisionService::class);
parent::setUp();
}

public function testInvoke(): void
{
$review = new CodeReview();
$revision = new Revision();
$visibility = (new RevisionVisibility())->setVisible(false);
$user = new User();

$this->expectGetUser($user);
$this->revisionService->expects(self::once())->method('getRevisions')->with($review)->willReturn([$revision]);
$this->visibilityService->expects(self::once())->method('getRevisionVisibilities')
->with($review, [$revision], $user)
->willReturn([$visibility]);
$this->visibilityRepository->expects(self::once())->method('saveAll')->with([$visibility], true);
$this->expectRefererRedirect(ReviewController::class, ['review' => $review]);

($this->controller)($review);
static::assertTrue($visibility->isVisible());
}

public function getController(): AbstractController
{
return new ResetRevisionVisibilityController($this->visibilityService, $this->visibilityRepository, $this->revisionService);
}
}
7 changes: 4 additions & 3 deletions translations/messages+intl-icu.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
'ignore.space.at.eol' => 'Ignore space at end-of-line',
'ignore.space.change' => 'Ignore space changes',
'ignore.whitespaces' => 'Ignore whitespaces',
'ignore.whitespaces.and.empty.lines' => 'Ignore whitespaces and empty lines',
'in.review' => 'In review',
'inactive' => 'Inactive',
'include.commits' => 'Include commits',
Expand All @@ -164,6 +165,7 @@
'login.not.successful' => 'The log in was not successful',
'login.unable.to.validate.login.attempt' => 'Unable to validate the login attempt. Please retry',
'logout' => 'Logout',
'logs' => 'Logs',
'mail.comment.resolved.subject' => '[Resolved discussion] {reviewId}: {reviewTitle}',
'mail.comment.was.resolved.on' => 'Comment was resolved by {userName} on',
'mail.configure.settings' => 'Configure notification settings.',
Expand All @@ -176,6 +178,7 @@
'mail.unsubscribe.footer' => 'If you don\'t want to receive these emails from {app_name} in the future, please unsubscribe.',
'mail.updated.comment.subject' => '[Updated discussion] {reviewId}: {reviewTitle}',
'main.branch' => 'Main branch',
'mark.all.as.read' => 'Mark all as read',
'merged' => 'merged',
'name' => 'Name',
'never' => 'Never',
Expand Down Expand Up @@ -281,6 +284,7 @@
'settings' => 'Settings',
'settings.save.successfully' => 'Settings successfully saved',
'show' => 'show',
'show.all.revisions' => 'Show all revisions',
'sign.in' => 'Sign in',
'sign.up' => 'Sign up',
'subject' => 'Subject',
Expand Down Expand Up @@ -346,7 +350,4 @@
'webhooks' => 'Webhooks',
'yes' => 'Yes',
'you' => 'You',
'logs' => 'Logs',
'mark.all.as.read' => 'Mark all as read',
'ignore.whitespaces.and.empty.lines' => 'Ignore whitespaces and empty lines',
];

0 comments on commit aa91405

Please sign in to comment.