Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions migrations/Version20220506101824.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220506101824 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE project (id INT AUTO_INCREMENT NOT NULL, owner_id INT DEFAULT NULL, `key` VARCHAR(5) NOT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_2FB3D0EE7E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EE7E3C61F9 FOREIGN KEY (owner_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE task ADD project_id INT DEFAULT NULL, CHANGE is_completed is_completed TINYINT(1) DEFAULT 0 NOT NULL');
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_527EDB25166D1F9C FOREIGN KEY (project_id) REFERENCES project (id)');
$this->addSql('CREATE INDEX IDX_527EDB25166D1F9C ON task (project_id)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_527EDB25166D1F9C');
$this->addSql('DROP TABLE project');
$this->addSql('DROP INDEX IDX_527EDB25166D1F9C ON task');
$this->addSql('ALTER TABLE task DROP project_id, CHANGE is_completed is_completed TINYINT(1) DEFAULT NULL');
}
}
33 changes: 33 additions & 0 deletions migrations/Version20220506111051.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220506111051 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE project CHANGE `key` `key` VARCHAR(255) NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_2FB3D0EE8A90ABA9 ON project (`key`)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_2FB3D0EE8A90ABA9 ON project');
$this->addSql('ALTER TABLE project CHANGE `key` `key` VARCHAR(5) NOT NULL');
}
}
35 changes: 35 additions & 0 deletions migrations/Version20220506132158.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220506132158 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_2FB3D0EE8A90ABA9 ON project');
$this->addSql('ALTER TABLE project CHANGE `key` project_key VARCHAR(255) NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_2FB3D0EE18EB714A ON project (project_key)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_2FB3D0EE18EB714A ON project');
$this->addSql('ALTER TABLE project CHANGE project_key `key` VARCHAR(255) NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_2FB3D0EE8A90ABA9 ON project (`key`)');
}
}
142 changes: 142 additions & 0 deletions src/Controller/ProjectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

namespace App\Controller;

use App\Entity\Project;
use App\Entity\Task;
use App\Type\ProjectType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use const http\Client\Curl\PROXY_HTTP;
use Symfony\Component\Routing\Annotation\Route;

class ProjectController extends AbstractController
{

/**
* @Route("/projects", name="project_list")
* @return Response
*/

public function list(Request $request): Response
{
$user = $this->getUser();
$projectRepository = $this->getDoctrine() -> getManager() -> getRepository(Project::class);

$projects = $projectRepository->findByUserRole($user->getId());

return $this -> render("projects/list.html.twig", [
"projects" => $projects,
]);
}

/**
* @Route("/projects/create", name="project_create")
* @param Request $request
* @return Response
*/
public function create(Request $request): Response
{
$project = new Project();
$form = $this -> createForm(ProjectType::class, $project);

$form -> handleRequest($request);

if ($form -> isSubmitted() && $form -> isValid()) {

$project -> setOwner($this -> getUser());

$this -> getDoctrine() -> getManager() -> persist($project);
$this -> getDoctrine() -> getManager() -> flush();

return $this -> redirectToRoute("project_list");
}

return $this -> render("projects/create.html.twig", [
"form" => $form -> createView(),
"action" => "create"
]);
}

/**
* @Route("/projects/{slug}", name="project_show")
* @return Response
*/
public function show($slug, Request $request): Response
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Нет проверки что проект доступен пользователю.
Нужно добавить, реализовать через Voter

https://symfony.com/doc/4.4/security/voters.html

{
$project = $this->getDoctrine()->getRepository(Project::class)->findOneBy(["projectKey" => $slug]);
// dd($project);

$this->denyAccessUnlessGranted('view', $project);

if ($project === null) {
throw $this->createNotFoundException(sprintf("Project with key %s not found", $slug));
}

$tasks = $project -> getTasks();

return $this->render('task/project_tasks.html.twig', [
'tasks' => $tasks,
"project_name" => $project -> getName(),
]);
}

/**
* @Route("/projects/{slug}/edit", name="project_edit")
* @param $slug
* @param Request $request
* @return Response
*/
public function edit($slug, Request $request): Response
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Также нет проверки на доступность

{
$project = $this->getDoctrine()->getRepository(Project::class) -> findOneBy(["projectKey" => $slug]);

$this->denyAccessUnlessGranted('edit', $project);

if ($project === null) {
throw $this->createNotFoundException(sprintf("Project with key %s not found", $slug));
}

$form = $this->createForm(ProjectType::class, $project);

$form -> handleRequest($request);

if ($form -> isSubmitted() && $form -> isValid()) {
$this -> getDoctrine() -> getManager() -> persist($project);
$this -> getDoctrine() -> getManager() -> flush();

return $this -> redirectToRoute("project_list");
}

return $this->render("projects/create.html.twig", [
"form" => $form->createView(),
"action" => "edit",
"slug" => $slug
]);
}

/**
* @Route("/projects/{slug}/delete", name="project_delete")
* @param $slug
* @param Request $request
* @return Response
*/
public function delete($slug, Request $request): Response
{
$em = $this->getDoctrine()->getManager();
$project = $this->getDoctrine()->getRepository(
Project::class) -> findOneBy(["projectKey" => $slug]);

$this->denyAccessUnlessGranted('delete', $project);

if ($project === null) {
throw $this->createNotFoundException(sprintf("Project with key %s not found", $slug));
}

$em -> remove($project);
$em -> flush();

return $this->redirectToRoute("project_list");
}
}
Loading