Skip to content

Commit

Permalink
Merge pull request #550 from caesar-team/develop
Browse files Browse the repository at this point in the history
Fix v2.0.4
  • Loading branch information
aburov-dev authored Nov 26, 2020
2 parents 60e581a + 31c9d65 commit 6b377da
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 11 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
],
"post-update-cmd": [
"@auto-scripts"
],
"analyse": [
"@php vendor/bin/php-cs-fixer fix --config=.php_cs.dist -vv",
"@php vendor/bin/phpstan analyse --memory-limit=-1",
"@php vendor/bin/psalm --show-info=false"
]
},
"conflict": {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Api/Item/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function edit(

$editRequest = new EditItemRequest($item);
$form = $this->createForm(EditItemRequestType::class, $editRequest);
$form->submit($request->request->all());
$form->handleRequest($request);
if (!$form->isValid()) {
throw new FormInvalidRequestException($form);
}
Expand Down
11 changes: 7 additions & 4 deletions src/Controller/Api/Team/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
use App\Entity\User;
use App\Entity\UserTeam;
use App\Factory\View\Team\MemberViewFactory;
use App\Factory\View\Team\TeamViewFactory;
use App\Form\Type\Request\Team\BatchCreateMemberRequestType;
use App\Form\Type\Request\Team\CreateMemberRequestType;
use App\Form\Type\Request\Team\EditUserTeamType;
use App\Model\Query\MemberListQuery;
use App\Model\View\Team\MemberView;
use App\Model\View\Team\TeamView;
use App\Repository\UserTeamRepository;
use App\Request\Team\BatchCreateMemberRequest;
use App\Request\Team\CreateMemberRequest;
Expand Down Expand Up @@ -239,8 +241,9 @@ public function removeMember(
*
* @SWG\Tag(name="Team / Member")
* @SWG\Response(
* response=204,
* description="Leave team member"
* response=200,
* description="Leave team member",
* @Model(type=TeamView::class)
* )
*
* @Route(
Expand All @@ -249,14 +252,14 @@ public function removeMember(
* methods={"POST"}
* )
*/
public function leaveTeam(Team $team, UserTeamRepository $userTeamRepository): JsonResponse
public function leaveTeam(Team $team, TeamViewFactory $viewFactory, UserTeamRepository $userTeamRepository): TeamView
{
$this->denyAccessUnlessGranted(TeamVoter::LEAVE, $team);
$userTeam = $team->getUserTeamByUser($this->getUser());

$userTeamRepository->remove($userTeam);

return new JsonResponse([], Response::HTTP_NO_CONTENT);
return $viewFactory->createSingle($team);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Api/Team/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function update(

$editRequest = new EditTeamRequest($team);
$form = $this->createForm(EditTeamRequestType::class, $editRequest);
$form->submit($request->request->all());
$form->handleRequest($request);
if (!$form->isValid()) {
throw new FormInvalidRequestException($form);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Embedded/ItemMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ItemMeta
private int $attachmentsCount;

/**
* @ORM\Column(nullable=true)
* @ORM\Column(type="text", nullable=true)
*/
private ?string $website;

Expand Down
6 changes: 6 additions & 0 deletions src/Form/Type/Request/Item/EditItemRequestType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'method' => 'PATCH',
'data_class' => EditItemRequest::class,
'csrf_protection' => false,
]);
}

public function getBlockPrefix()
{
return '';
}
}
6 changes: 6 additions & 0 deletions src/Form/Type/Request/Team/EditTeamRequestType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'method' => 'PATCH',
'data_class' => EditTeamRequest::class,
'csrf_protection' => false,
]);
}

public function getBlockPrefix()
{
return '';
}
}
32 changes: 32 additions & 0 deletions src/Migrations/2020/11/Version20201126072730.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20201126072730 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('ALTER TABLE item ALTER meta_website TYPE TEXT');
$this->addSql('ALTER TABLE item ALTER meta_website DROP DEFAULT');
}

public function down(Schema $schema): void
{
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('ALTER TABLE item ALTER meta_website TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE item ALTER meta_website DROP DEFAULT');
}
}
1 change: 1 addition & 0 deletions src/Request/Item/ItemMetaRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class ItemMetaRequest

/**
* @Assert\NotBlank()
* @Assert\Length(max="255")
*/
private ?string $title;

Expand Down
13 changes: 12 additions & 1 deletion tests/api/Item/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,21 @@ public function editItem()
'website' => 'http://examle.com/login',
'title' => 'item title (edited)',
],
'raws' => uniqid(),
'raws' => 'some-raws-data',
]);
$I->seeResponseCodeIs(HttpCode::OK);

$I->haveHttpHeader('Content-Type', 'application/json');
$I->sendPATCH(sprintf('items/%s', $item->getId()->toString()), [
'secret' => 'secret-edit (edited)',
]);
$I->seeResponseCodeIs(HttpCode::OK);
$I->seeResponseContainsJson(['secret' => 'secret-edit (edited)', 'meta' => ['title' => 'item title (edited)']]);

$I->sendGET(sprintf('/items/%s/raws', $item->getId()->toString()));
$I->seeResponseCodeIs(HttpCode::OK);
$I->seeResponseContains('some-raws-data');

$I->sendPATCH(sprintf('/items/%s', $otherItem->getId()), [
'secret' => 'secret-edit',
'meta' => [
Expand Down
4 changes: 2 additions & 2 deletions tests/api/Team/MemberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,15 @@ public function leaveTeam()

$I->login($member);
$I->sendPOST(sprintf('teams/%s/leave', $team->getId()->toString()));
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
$I->seeResponseCodeIs(HttpCode::OK);

$I->sendPOST(sprintf('teams/%s/leave', $otherTeam->getId()->toString()));
$I->seeResponseCodeIs(HttpCode::FORBIDDEN);
$I->seeInDatabase('groups', ['id' => $team->getId()->toString()]);

$I->login($user);
$I->sendPOST(sprintf('teams/%s/leave', $otherTeam->getId()->toString()));
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
$I->seeResponseCodeIs(HttpCode::OK);
$I->dontSeeInDatabase('groups', ['id' => $otherTeam->getId()->toString()]);
}
}
2 changes: 1 addition & 1 deletion tests/api/Team/TeamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function pinnedTeam()
$I->seeResponseContainsJson(['pinned' => true]);

$I->sendPOST(sprintf('teams/%s/leave', $team->getId()->toString()));
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
$I->seeResponseCodeIs(HttpCode::OK);

$I->sendGET(sprintf('teams/%s', $team->getId()->toString()));
$I->seeResponseCodeIs(HttpCode::OK);
Expand Down

0 comments on commit 6b377da

Please sign in to comment.