-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quick revision visibility reset button (#843)
- Loading branch information
1 parent
8844caf
commit aa91405
Showing
4 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/Controller/App/Revision/ResetRevisionVisibilityController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
tests/Unit/Controller/App/Revision/ResetRevisionVisibilityControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters