From cac6b0a9a0161ddec073dc3071f93a7538662b79 Mon Sep 17 00:00:00 2001 From: mike1796 Date: Thu, 3 Aug 2017 17:53:36 +0200 Subject: [PATCH 1/5] Voters are incoming Migration and separation should be ok Voter too Still need to complete the EventSubscriber --- .../Version20170803143719.php | 39 +++ app/config/services.yml | 11 +- src/AppBundle/Entity/Account.php | 293 ++-------------- src/AppBundle/Entity/Profile.php | 324 ++++++++++++++++++ .../EventSubscriber/AccountChecker.php | 52 +++ src/AppBundle/Security/AccountVoter.php | 48 +++ 6 files changed, 504 insertions(+), 263 deletions(-) create mode 100644 app/DoctrineMigrations/Version20170803143719.php create mode 100644 src/AppBundle/Entity/Profile.php create mode 100644 src/AppBundle/EventSubscriber/AccountChecker.php create mode 100644 src/AppBundle/Security/AccountVoter.php diff --git a/app/DoctrineMigrations/Version20170803143719.php b/app/DoctrineMigrations/Version20170803143719.php new file mode 100644 index 0000000..5d9a5b4 --- /dev/null +++ b/app/DoctrineMigrations/Version20170803143719.php @@ -0,0 +1,39 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('ALTER TABLE profile DROP CONSTRAINT fk_8157aa0f9b6b5fba'); + $this->addSql('DROP INDEX uniq_8157aa0f9b6b5fba'); + $this->addSql('ALTER TABLE profile DROP account_id'); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE profile ADD account_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE profile ADD CONSTRAINT fk_8157aa0f9b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE UNIQUE INDEX uniq_8157aa0f9b6b5fba ON profile (account_id)'); + } +} diff --git a/app/config/services.yml b/app/config/services.yml index 9add31b..1222076 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -18,4 +18,13 @@ services: app.security.rate_limiter: class: AppBundle\Security\RateLimiter - arguments: [ "@doctrine.orm.entity_manager" ] \ No newline at end of file + arguments: [ "@doctrine.orm.entity_manager" ] + + app.security.account_voter: + class: AppBundle\Security\AccountVoter + + app.event_subscriber.account_checker: + class: AppBundle\EventSubscriber\AccountChecker + arguments: [ "@app.security.account_voter", "%security.token_storage%" ] + tags: + - { name: kernel.event_listener, event: kernel.request } diff --git a/src/AppBundle/Entity/Account.php b/src/AppBundle/Entity/Account.php index 8a71ff9..f995238 100644 --- a/src/AppBundle/Entity/Account.php +++ b/src/AppBundle/Entity/Account.php @@ -3,7 +3,6 @@ namespace AppBundle\Entity; use ApiPlatform\Core\Annotation\ApiResource; -use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Serializer\Annotation\Groups; @@ -18,27 +17,16 @@ class Account implements UserInterface { /** - * @var int The Id of the user + * @var int * + * @ORM\Column(name="id", type="integer") * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") + * @ORM\GeneratedValue(strategy="AUTO") * @Groups({"account"}) * @Assert\Type("integer") */ private $id; - /** - * @var string The username of the user - * - * @ORM\Column(type="string", unique=true) - * - * @Groups({"account"}) - * @Assert\NotBlank - * @Assert\Type("string") - */ - private $username; - /** * @var string The email of the user * @@ -51,7 +39,7 @@ class Account implements UserInterface private $email; /** - * @var string The first name of user + * @var string The salt of the user * * @ORM\Column(type="string") * @@ -59,10 +47,10 @@ class Account implements UserInterface * @Assert\NotBlank * @Assert\Type("string") */ - private $firstName; + private $salt; /** - * @var string The last name of user + * @var string password of the user * * @ORM\Column(type="string") * @@ -70,158 +58,23 @@ class Account implements UserInterface * @Assert\NotBlank * @Assert\Type("string") */ - private $lastName; - - /** - * @var ArrayCollection The list of the channels - * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Channel", mappedBy="account", cascade={"persist"}) - * @Groups({"account"}) - */ - private $channels; - - /** - * @var ArrayCollection The list of views - * - * @Groups({"account"}) - * @ORM\OneToMany(targetEntity="AppBundle\Entity\View", mappedBy="account", cascade={"persist"}) - */ - private $views; - - /** - * @var ArrayCollection - * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Forum", mappedBy="createdBy", cascade={"persist"}) - * @Groups({"account"}) - */ - private $forums; - - /** - * @var ArrayCollection - * - * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Network", mappedBy="peoples", cascade={"persist"}) - * @Groups({"account"}) - * @ORM\JoinTable(name="accounts_networks") - */ - private $networks; - - /** - * @var ArrayCollection - * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Playlist", mappedBy="account", cascade={"persist"}) - * @Groups({"account"}) - */ - private $playlists; - - /** - * @var ArrayCollection - * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Reply", mappedBy="author", cascade={"persist"}) - * @Groups({"account"}) - */ - private $replies; - - /** - * @var ArrayCollection - * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Review", mappedBy="author", cascade={"persist"}) - * @Groups({"account"}) - */ - private $reviews; - - /** - * @var ArrayCollection - * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\SustainabilityOffer", mappedBy="account", cascade={"persist"}) - * @Groups({"account"}) - */ - private $sustainabilityOffers; - - /** - * @var ArrayCollection - * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Seeder", mappedBy="account", cascade={"persist"}) - * @Groups({"account"}) - */ - private $seeders; - - /** - * @var string The salt of the user - * - * @ORM\Column(type="string") - * - * @Assert\NotBlank - * @Assert\Type("string") - */ - private $salt; + private $password; /** - * @var string password of the user + * @var Profile * - * @ORM\Column(type="string") - * - * @Assert\NotBlank - * @Assert\Type("string") + * @ORM\OneToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="account", cascade={"persist"}) */ - private $password; - - public function __construct() - { - $this->channels = new ArrayCollection(); - $this->views = new ArrayCollection(); - $this->forums = new ArrayCollection(); - $this->networks = new ArrayCollection(); - $this->playlists = new ArrayCollection(); - $this->replies = new ArrayCollection(); - $this->reviews = new ArrayCollection(); - $this->sustainabilityOffers = new ArrayCollection(); - $this->seeders = new ArrayCollection(); - } - - public function getViews() - { - return $this->views; - } - - public function setViews($views) - { - $this->views = $views; - - return this; - } - - public function getChannels() - { - return $this->channels; - } - - public function setChannels($channels) - { - $this->channels = $channels; - - return $this; - } - - public function getId(): int - { - return $this->id; - } - - public function setId($id) - { - $this->id = $id; - - return $this; - } + private $profile; public function getUsername(): string { - return $this->username; + return $this->profile->getUsername(); } public function setUsername($username) { - $this->username = $username; + $this->profile->setUsername($username); return $this; } @@ -238,143 +91,59 @@ public function setEmail($email) return $this; } - public function getFirstName(): string - { - return $this->firstName; - } - - public function setFirstName($firstName) - { - $this->firstName = $firstName; - - return $this; - } - - public function getLastName(): string - { - return $this->lastName; - } - - public function setLastName($lastName) - { - $this->lastName = $lastName; - - return $this; - } - - public function getForums() - { - return $this->forums; - } - - public function setForums($forums): Account - { - $this->forums = $forums; - - return $this; - } - - public function getNetworks() - { - return $this->networks; - } - - public function setNetworks($networks): Account - { - $this->networks = $networks; - - return $this; - } - - public function getPlaylists() - { - return $this->playlists; - } - - public function setPlaylist($playlists): Account - { - $this->playlists = $playlists; - - return $this; - } - - public function getReplies() - { - return $this->replies; - } - - public function setReplies($replies): Account - { - $this->replies = $replies; - - return $this; - } - - public function getReviews() + public function getSalt(): string { - return $this->reviews; + return $this->salt; } - public function setReviews($reviews): Account + public function setSalt(string $salt): Account { - $this->reviews = $reviews; + $this->salt = $salt; return $this; } - public function getSustainabilityOffers() + public function getRoles(): array { - return $this->sustainabilityOffers; + return ['ROLE_USER']; } - public function setSustainabilityOffers($sustainabilityOffers): Account + public function eraseCredentials() { - $this->sustainabilityOffers = $sustainabilityOffers; - - return $this; } - public function getSeeders() + public function getPassword(): string { - return $this->seeders; + return $this->password; } - public function setSeeders($seeders): Account + public function setPassword(string $password): Account { - $this->seeders = $seeders; + $this->password = $password; return $this; } - public function getSalt(): string + public function getId(): int { - return $this->salt; + return $this->id; } - public function setSalt(string $salt): Account + public function setId(int $id): Account { - $this->salt = $salt; + $this->id = $id; return $this; } - public function getRoles(): array + public function getProfile(): Account { - return ['ROLE_USER']; + return $this->profile; } - public function eraseCredentials() - { - } - - public function getPassword(): string + public function setProfile(Account $profile): Account { - return $this->password; - } - - public function setPassword(string $password): Account - { - $this->password = $password; + $this->profile = $profile; return $this; } diff --git a/src/AppBundle/Entity/Profile.php b/src/AppBundle/Entity/Profile.php new file mode 100644 index 0000000..7b21b9b --- /dev/null +++ b/src/AppBundle/Entity/Profile.php @@ -0,0 +1,324 @@ +channels = new ArrayCollection(); + $this->views = new ArrayCollection(); + $this->forums = new ArrayCollection(); + $this->networks = new ArrayCollection(); + $this->playlists = new ArrayCollection(); + $this->replies = new ArrayCollection(); + $this->reviews = new ArrayCollection(); + $this->sustainabilityOffers = new ArrayCollection(); + $this->seeders = new ArrayCollection(); + } + + public function getViews() + { + return $this->views; + } + + public function setViews($views) + { + $this->views = $views; + + return this; + } + + public function getChannels() + { + return $this->channels; + } + + public function setChannels($channels) + { + $this->channels = $channels; + + return $this; + } + + public function getId(): int + { + return $this->id; + } + + public function setId($id) + { + $this->id = $id; + + return $this; + } + + public function getUsername(): string + { + return $this->username; + } + + public function setUsername($username) + { + $this->username = $username; + + return $this; + } + + public function getFirstName(): string + { + return $this->firstName; + } + + public function setFirstName($firstName) + { + $this->firstName = $firstName; + + return $this; + } + + public function getLastName(): string + { + return $this->lastName; + } + + public function setLastName($lastName) + { + $this->lastName = $lastName; + + return $this; + } + + public function getForums() + { + return $this->forums; + } + + public function setForums($forums): Account + { + $this->forums = $forums; + + return $this; + } + + public function getNetworks() + { + return $this->networks; + } + + public function setNetworks($networks): Account + { + $this->networks = $networks; + + return $this; + } + + public function getPlaylists() + { + return $this->playlists; + } + + public function setPlaylist($playlists): Account + { + $this->playlists = $playlists; + + return $this; + } + + public function getReplies() + { + return $this->replies; + } + + public function setReplies($replies): Account + { + $this->replies = $replies; + + return $this; + } + + public function getReviews() + { + return $this->reviews; + } + + public function setReviews($reviews): Account + { + $this->reviews = $reviews; + + return $this; + } + + public function getSustainabilityOffers() + { + return $this->sustainabilityOffers; + } + + public function setSustainabilityOffers($sustainabilityOffers): Account + { + $this->sustainabilityOffers = $sustainabilityOffers; + + return $this; + } + + public function getSeeders() + { + return $this->seeders; + } + + public function setSeeders($seeders): Account + { + $this->seeders = $seeders; + + return $this; + } + + public function getAccount(): Account + { + return $this->account; + } + + public function setAccount(Account $account): Profile + { + $this->account = $account; + + return $this; + } + +} \ No newline at end of file diff --git a/src/AppBundle/EventSubscriber/AccountChecker.php b/src/AppBundle/EventSubscriber/AccountChecker.php new file mode 100644 index 0000000..70ad2dc --- /dev/null +++ b/src/AppBundle/EventSubscriber/AccountChecker.php @@ -0,0 +1,52 @@ +accountVoter = $accountVoter; + $this->tokenStorage = $tokenStorage; + } + + public static function getSubscribedEvents() + { + return [ + KernelEvents::REQUEST => [['checkAccountAccess', EventPriorities::POST_DESERIALIZE]], + ]; + } + + public function checkAccountAccess(GetResponseForControllerResultEvent $event) + { + $profile = $event->getControllerResult(); + $method = $event->getRequest()->getMethod(); + + if (!$profile instanceof Profile || Request::METHOD_POST !== $method) { + return; + } + + if (!correctValue($profile)) { + $response = new Response('You don\'t have access to this account', Response::); + $event->setResponse($response); + } + } + + private function correctValue(Profile $profile) + { + $this->accountVoter->vote($this->tokenStorage, $profile, $profile->getAccount()) === VoterInterface::ACCESS_GRANTED; + } + +} \ No newline at end of file diff --git a/src/AppBundle/Security/AccountVoter.php b/src/AppBundle/Security/AccountVoter.php new file mode 100644 index 0000000..2a40dbb --- /dev/null +++ b/src/AppBundle/Security/AccountVoter.php @@ -0,0 +1,48 @@ +getUser(); + + if (!$user instanceof Profile) { + return false; + } + + $profile = $subject; + + if ($attribute === self::ACCESS) { + return $this->canAccess($profile, $user); + } + + throw new \LogicException('This code should not be reached!'); + } + + private function canAccess(Account $account, Profile $user) + { + return $user->getAccount()->getId() === $account->getId(); + } +} \ No newline at end of file From b0851b60949fd9c0bf70a945755404adfd810114 Mon Sep 17 00:00:00 2001 From: mike1796 Date: Thu, 3 Aug 2017 20:38:40 +0200 Subject: [PATCH 2/5] Set with profile should be ok --- .../Version20170803143719.php | 39 ------ .../Version20170803183821.php | 130 ++++++++++++++++++ app/config/services.yml | 2 +- composer.json | 2 +- composer.lock | 102 +++++++------- features/bootstrap/AccountHelper.php | 8 +- features/bootstrap/ChannelHelper.php | 10 +- features/bootstrap/CommentHelper.php | 12 +- features/bootstrap/FeatureContext.php | 17 +-- features/bootstrap/ForumHelper.php | 8 +- features/bootstrap/NetworkHelper.php | 4 +- features/bootstrap/PlaylistHelper.php | 10 +- features/bootstrap/ProfileHelper.php | 31 +++++ features/bootstrap/ReplyHelper.php | 16 +-- features/bootstrap/ReviewHelper.php | 16 +-- features/bootstrap/SeederHelper.php | 12 +- .../bootstrap/SustainabilityOfferHelper.php | 2 +- features/bootstrap/ViewHelper.php | 12 +- .../DataFixtures/ORM/Fixtures/AccountData.php | 14 +- src/AppBundle/Entity/Account.php | 10 +- src/AppBundle/Entity/Annotation.php | 2 +- src/AppBundle/Entity/Channel.php | 14 +- src/AppBundle/Entity/Comment.php | 8 +- src/AppBundle/Entity/Forum.php | 8 +- src/AppBundle/Entity/Network.php | 4 +- src/AppBundle/Entity/Playlist.php | 14 +- src/AppBundle/Entity/Profile.php | 36 ++--- src/AppBundle/Entity/Reply.php | 8 +- src/AppBundle/Entity/Review.php | 8 +- src/AppBundle/Entity/Seeder.php | 14 +- src/AppBundle/Entity/Subtitles.php | 4 +- src/AppBundle/Entity/SustainabilityOffer.php | 16 +-- src/AppBundle/Entity/Video.php | 6 +- src/AppBundle/Entity/View.php | 14 +- .../EventSubscriber/AccountChecker.php | 22 ++- .../Repository/AccountRepository.php | 11 -- .../Repository/ProfileRepository.php | 19 +++ src/AppBundle/Security/AccountProvider.php | 5 +- src/AppBundle/Security/AccountVoter.php | 5 +- 39 files changed, 403 insertions(+), 272 deletions(-) delete mode 100644 app/DoctrineMigrations/Version20170803143719.php create mode 100644 app/DoctrineMigrations/Version20170803183821.php create mode 100644 features/bootstrap/ProfileHelper.php create mode 100644 src/AppBundle/Repository/ProfileRepository.php diff --git a/app/DoctrineMigrations/Version20170803143719.php b/app/DoctrineMigrations/Version20170803143719.php deleted file mode 100644 index 5d9a5b4..0000000 --- a/app/DoctrineMigrations/Version20170803143719.php +++ /dev/null @@ -1,39 +0,0 @@ -abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('ALTER TABLE profile DROP CONSTRAINT fk_8157aa0f9b6b5fba'); - $this->addSql('DROP INDEX uniq_8157aa0f9b6b5fba'); - $this->addSql('ALTER TABLE profile DROP account_id'); - } - - /** - * @param Schema $schema - */ - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE profile ADD account_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE profile ADD CONSTRAINT fk_8157aa0f9b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE UNIQUE INDEX uniq_8157aa0f9b6b5fba ON profile (account_id)'); - } -} diff --git a/app/DoctrineMigrations/Version20170803183821.php b/app/DoctrineMigrations/Version20170803183821.php new file mode 100644 index 0000000..515e17e --- /dev/null +++ b/app/DoctrineMigrations/Version20170803183821.php @@ -0,0 +1,130 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('CREATE SEQUENCE profile_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE profile (id INT NOT NULL, username VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_8157AA0FF85E0677 ON profile (username)'); + $this->addSql('CREATE TABLE network_profile (network_id INT NOT NULL, profile_id INT NOT NULL, PRIMARY KEY(network_id, profile_id))'); + $this->addSql('CREATE INDEX IDX_25E47D6534128B91 ON network_profile (network_id)'); + $this->addSql('CREATE INDEX IDX_25E47D65CCFA12B8 ON network_profile (profile_id)'); + $this->addSql('ALTER TABLE network_profile ADD CONSTRAINT FK_25E47D6534128B91 FOREIGN KEY (network_id) REFERENCES network (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE network_profile ADD CONSTRAINT FK_25E47D65CCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('DROP TABLE network_account'); + $this->addSql('ALTER TABLE view DROP CONSTRAINT fk_fefdab8e9b6b5fba'); + $this->addSql('DROP INDEX idx_fefdab8e9b6b5fba'); + $this->addSql('ALTER TABLE view RENAME COLUMN account_id TO profile_id'); + $this->addSql('ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8ECCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_FEFDAB8ECCFA12B8 ON view (profile_id)'); + $this->addSql('ALTER TABLE forum DROP CONSTRAINT FK_852BBECDB03A8386'); + $this->addSql('ALTER TABLE forum ADD CONSTRAINT FK_852BBECDB03A8386 FOREIGN KEY (created_by_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE comment DROP CONSTRAINT FK_9474526CF675F31B'); + $this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526CF675F31B FOREIGN KEY (author_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('DROP INDEX uniq_7d3656a4f85e0677'); + $this->addSql('ALTER TABLE account ADD profile_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE account DROP username'); + $this->addSql('ALTER TABLE account DROP first_name'); + $this->addSql('ALTER TABLE account DROP last_name'); + $this->addSql('ALTER TABLE account ADD CONSTRAINT FK_7D3656A4CCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_7D3656A4CCFA12B8 ON account (profile_id)'); + $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D9B6B5FBA'); + $this->addSql('ALTER TABLE playlist ADD CONSTRAINT FK_D782112D9B6B5FBA FOREIGN KEY (account_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE reply DROP CONSTRAINT FK_FDA8C6E0F675F31B'); + $this->addSql('ALTER TABLE reply ADD CONSTRAINT FK_FDA8C6E0F675F31B FOREIGN KEY (author_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE review DROP CONSTRAINT FK_794381C6F675F31B'); + $this->addSql('ALTER TABLE review ADD CONSTRAINT FK_794381C6F675F31B FOREIGN KEY (author_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE sustainability_offer DROP CONSTRAINT fk_bdc3df359b6b5fba'); + $this->addSql('DROP INDEX idx_bdc3df359b6b5fba'); + $this->addSql('ALTER TABLE sustainability_offer RENAME COLUMN account_id TO profile_id'); + $this->addSql('ALTER TABLE sustainability_offer ADD CONSTRAINT FK_BDC3DF35CCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_BDC3DF35CCFA12B8 ON sustainability_offer (profile_id)'); + $this->addSql('ALTER TABLE seeder DROP CONSTRAINT fk_8801cdce9b6b5fba'); + $this->addSql('DROP INDEX idx_8801cdce9b6b5fba'); + $this->addSql('ALTER TABLE seeder RENAME COLUMN account_id TO profile_id'); + $this->addSql('ALTER TABLE seeder ADD CONSTRAINT FK_8801CDCECCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_8801CDCECCFA12B8 ON seeder (profile_id)'); + $this->addSql('ALTER TABLE channel DROP CONSTRAINT fk_a2f98e479b6b5fba'); + $this->addSql('DROP INDEX idx_a2f98e479b6b5fba'); + $this->addSql('ALTER TABLE channel RENAME COLUMN account_id TO profile_id'); + $this->addSql('ALTER TABLE channel ADD CONSTRAINT FK_A2F98E47CCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_A2F98E47CCFA12B8 ON channel (profile_id)'); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE view DROP CONSTRAINT FK_FEFDAB8ECCFA12B8'); + $this->addSql('ALTER TABLE forum DROP CONSTRAINT FK_852BBECDB03A8386'); + $this->addSql('ALTER TABLE comment DROP CONSTRAINT FK_9474526CF675F31B'); + $this->addSql('ALTER TABLE account DROP CONSTRAINT FK_7D3656A4CCFA12B8'); + $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D9B6B5FBA'); + $this->addSql('ALTER TABLE reply DROP CONSTRAINT FK_FDA8C6E0F675F31B'); + $this->addSql('ALTER TABLE review DROP CONSTRAINT FK_794381C6F675F31B'); + $this->addSql('ALTER TABLE sustainability_offer DROP CONSTRAINT FK_BDC3DF35CCFA12B8'); + $this->addSql('ALTER TABLE seeder DROP CONSTRAINT FK_8801CDCECCFA12B8'); + $this->addSql('ALTER TABLE network_profile DROP CONSTRAINT FK_25E47D65CCFA12B8'); + $this->addSql('ALTER TABLE channel DROP CONSTRAINT FK_A2F98E47CCFA12B8'); + $this->addSql('DROP SEQUENCE profile_id_seq CASCADE'); + $this->addSql('CREATE TABLE network_account (network_id INT NOT NULL, account_id INT NOT NULL, PRIMARY KEY(network_id, account_id))'); + $this->addSql('CREATE INDEX idx_d98581ce9b6b5fba ON network_account (account_id)'); + $this->addSql('CREATE INDEX idx_d98581ce34128b91 ON network_account (network_id)'); + $this->addSql('ALTER TABLE network_account ADD CONSTRAINT fk_d98581ce34128b91 FOREIGN KEY (network_id) REFERENCES network (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE network_account ADD CONSTRAINT fk_d98581ce9b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('DROP TABLE profile'); + $this->addSql('DROP TABLE network_profile'); + $this->addSql('DROP INDEX IDX_FEFDAB8ECCFA12B8'); + $this->addSql('ALTER TABLE view RENAME COLUMN profile_id TO account_id'); + $this->addSql('ALTER TABLE view ADD CONSTRAINT fk_fefdab8e9b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX idx_fefdab8e9b6b5fba ON view (account_id)'); + $this->addSql('DROP INDEX IDX_8801CDCECCFA12B8'); + $this->addSql('ALTER TABLE seeder RENAME COLUMN profile_id TO account_id'); + $this->addSql('ALTER TABLE seeder ADD CONSTRAINT fk_8801cdce9b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX idx_8801cdce9b6b5fba ON seeder (account_id)'); + $this->addSql('DROP INDEX IDX_BDC3DF35CCFA12B8'); + $this->addSql('ALTER TABLE sustainability_offer RENAME COLUMN profile_id TO account_id'); + $this->addSql('ALTER TABLE sustainability_offer ADD CONSTRAINT fk_bdc3df359b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX idx_bdc3df359b6b5fba ON sustainability_offer (account_id)'); + $this->addSql('ALTER TABLE forum DROP CONSTRAINT fk_852bbecdb03a8386'); + $this->addSql('ALTER TABLE forum ADD CONSTRAINT fk_852bbecdb03a8386 FOREIGN KEY (created_by_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE review DROP CONSTRAINT fk_794381c6f675f31b'); + $this->addSql('ALTER TABLE review ADD CONSTRAINT fk_794381c6f675f31b FOREIGN KEY (author_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE reply DROP CONSTRAINT fk_fda8c6e0f675f31b'); + $this->addSql('ALTER TABLE reply ADD CONSTRAINT fk_fda8c6e0f675f31b FOREIGN KEY (author_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('DROP INDEX IDX_A2F98E47CCFA12B8'); + $this->addSql('ALTER TABLE channel RENAME COLUMN profile_id TO account_id'); + $this->addSql('ALTER TABLE channel ADD CONSTRAINT fk_a2f98e479b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX idx_a2f98e479b6b5fba ON channel (account_id)'); + $this->addSql('DROP INDEX UNIQ_7D3656A4CCFA12B8'); + $this->addSql('ALTER TABLE account ADD username VARCHAR(255) NOT NULL'); + $this->addSql('ALTER TABLE account ADD first_name VARCHAR(255) NOT NULL'); + $this->addSql('ALTER TABLE account ADD last_name VARCHAR(255) NOT NULL'); + $this->addSql('ALTER TABLE account DROP profile_id'); + $this->addSql('CREATE UNIQUE INDEX uniq_7d3656a4f85e0677 ON account (username)'); + $this->addSql('ALTER TABLE playlist DROP CONSTRAINT fk_d782112d9b6b5fba'); + $this->addSql('ALTER TABLE playlist ADD CONSTRAINT fk_d782112d9b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE comment DROP CONSTRAINT fk_9474526cf675f31b'); + $this->addSql('ALTER TABLE comment ADD CONSTRAINT fk_9474526cf675f31b FOREIGN KEY (author_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } +} diff --git a/app/config/services.yml b/app/config/services.yml index 1222076..1000916 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -25,6 +25,6 @@ services: app.event_subscriber.account_checker: class: AppBundle\EventSubscriber\AccountChecker - arguments: [ "@app.security.account_voter", "%security.token_storage%" ] + arguments: [ "@security.authorization_checker" ] tags: - { name: kernel.event_listener, event: kernel.request } diff --git a/composer.json b/composer.json index 63600fa..6276c1a 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require": { "php": ">=7.1", - "symfony/symfony": "3.2.*", + "symfony/symfony": "3.2.13", "api-platform/core": "^2.0", "doctrine/orm": "^2.5", "doctrine/doctrine-bundle": "^1.6", diff --git a/composer.lock b/composer.lock index bfbaa17..45e3c67 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "7f35313adad30b64f206de7ba367d4cf", - "content-hash": "a009eb7e516230886035b87e2b76ec66", + "hash": "1efd91ec4514217e15a88b7d83e43198", + "content-hash": "94ddca3b92bbfa6c16aa86e0552d5f8c", "packages": [ { "name": "api-platform/core", @@ -2029,16 +2029,16 @@ }, { "name": "sensiolabs/security-checker", - "version": "v4.0.5", + "version": "v4.1.3", "source": { "type": "git", "url": "https://github.com/sensiolabs/security-checker.git", - "reference": "6a3b0c3b42e41c777b1ad75032d8177863fdc5e1" + "reference": "7d60f01b9a56dfd152796877d009b1a0578d6ef4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/6a3b0c3b42e41c777b1ad75032d8177863fdc5e1", - "reference": "6a3b0c3b42e41c777b1ad75032d8177863fdc5e1", + "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/7d60f01b9a56dfd152796877d009b1a0578d6ef4", + "reference": "7d60f01b9a56dfd152796877d009b1a0578d6ef4", "shasum": "" }, "require": { @@ -2051,7 +2051,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -2070,7 +2070,7 @@ } ], "description": "A security checker for your composer.lock", - "time": "2017-07-24 11:42:56" + "time": "2017-08-03 12:24:05" }, { "name": "swiftmailer/swiftmailer", @@ -2531,16 +2531,16 @@ }, { "name": "symfony/symfony", - "version": "v3.2.12", + "version": "v3.2.13", "source": { "type": "git", "url": "https://github.com/symfony/symfony.git", - "reference": "d65d8fad37fdbb599b13f0aade2407ae88465a58" + "reference": "e1aabd6f50fb4586b330f9ac54b4bcdf7352a0f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/symfony/zipball/d65d8fad37fdbb599b13f0aade2407ae88465a58", - "reference": "d65d8fad37fdbb599b13f0aade2407ae88465a58", + "url": "https://api.github.com/repos/symfony/symfony/zipball/e1aabd6f50fb4586b330f9ac54b4bcdf7352a0f8", + "reference": "e1aabd6f50fb4586b330f9ac54b4bcdf7352a0f8", "shasum": "" }, "require": { @@ -2671,7 +2671,7 @@ "keywords": [ "framework" ], - "time": "2017-07-17 18:15:19" + "time": "2017-08-01 09:40:44" }, { "name": "twig/twig", @@ -4283,28 +4283,28 @@ }, { "name": "phpunit/php-code-coverage", - "version": "5.2.1", + "version": "5.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "dc421f9ca5082a0c0cb04afb171c765f79add85b" + "reference": "8ed1902a57849e117b5651fc1a5c48110946c06b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/dc421f9ca5082a0c0cb04afb171c765f79add85b", - "reference": "dc421f9ca5082a0c0cb04afb171c765f79add85b", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/8ed1902a57849e117b5651fc1a5c48110946c06b", + "reference": "8ed1902a57849e117b5651fc1a5c48110946c06b", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", "php": "^7.0", - "phpunit/php-file-iterator": "^1.3", - "phpunit/php-text-template": "^1.2", + "phpunit/php-file-iterator": "^1.4.2", + "phpunit/php-text-template": "^1.2.1", "phpunit/php-token-stream": "^1.4.11 || ^2.0", - "sebastian/code-unit-reverse-lookup": "^1.0", + "sebastian/code-unit-reverse-lookup": "^1.0.1", "sebastian/environment": "^3.0", - "sebastian/version": "^2.0", + "sebastian/version": "^2.0.1", "theseer/tokenizer": "^1.1" }, "require-dev": { @@ -4312,7 +4312,7 @@ "phpunit/phpunit": "^6.0" }, "suggest": { - "ext-xdebug": "^2.5.3" + "ext-xdebug": "^2.5.5" }, "type": "library", "extra": { @@ -4343,7 +4343,7 @@ "testing", "xunit" ], - "time": "2017-04-21 08:03:57" + "time": "2017-08-03 12:40:43" }, { "name": "phpunit/php-file-iterator", @@ -4484,29 +4484,29 @@ }, { "name": "phpunit/php-token-stream", - "version": "1.4.11", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" + "reference": "ecb0b2cdaa0add708fe6f329ef65ae0c5225130b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", - "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/ecb0b2cdaa0add708fe6f329ef65ae0c5225130b", + "reference": "ecb0b2cdaa0add708fe6f329ef65ae0c5225130b", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": ">=5.3.3" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^6.2.4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -4529,20 +4529,20 @@ "keywords": [ "tokenizer" ], - "time": "2017-02-27 10:12:30" + "time": "2017-08-03 14:17:41" }, { "name": "phpunit/phpunit", - "version": "6.2.3", + "version": "6.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "fa5711d0559fc4b64deba0702be52d41434cbcb7" + "reference": "ff3a76a58ac293657808aefd58c8aaf05945f4d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fa5711d0559fc4b64deba0702be52d41434cbcb7", - "reference": "fa5711d0559fc4b64deba0702be52d41434cbcb7", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ff3a76a58ac293657808aefd58c8aaf05945f4d9", + "reference": "ff3a76a58ac293657808aefd58c8aaf05945f4d9", "shasum": "" }, "require": { @@ -4562,7 +4562,7 @@ "phpunit/php-timer": "^1.0.6", "phpunit/phpunit-mock-objects": "^4.0", "sebastian/comparator": "^2.0", - "sebastian/diff": "^1.4.3 || ^2.0", + "sebastian/diff": "^1.4.3", "sebastian/environment": "^3.0.2", "sebastian/exporter": "^3.1", "sebastian/global-state": "^1.1 || ^2.0", @@ -4613,26 +4613,26 @@ "testing", "xunit" ], - "time": "2017-07-03 15:54:24" + "time": "2017-08-03 13:59:28" }, { "name": "phpunit/phpunit-mock-objects", - "version": "4.0.2", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "d8833b396dce9162bb2eb5d59aee5a3ab3cfa5b4" + "reference": "2f789b59ab89669015ad984afa350c4ec577ade0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/d8833b396dce9162bb2eb5d59aee5a3ab3cfa5b4", - "reference": "d8833b396dce9162bb2eb5d59aee5a3ab3cfa5b4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/2f789b59ab89669015ad984afa350c4ec577ade0", + "reference": "2f789b59ab89669015ad984afa350c4ec577ade0", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.0.2", + "doctrine/instantiator": "^1.0.5", "php": "^7.0", - "phpunit/php-text-template": "^1.2", + "phpunit/php-text-template": "^1.2.1", "sebastian/exporter": "^3.0" }, "conflict": { @@ -4672,7 +4672,7 @@ "mock", "xunit" ], - "time": "2017-06-30 08:15:21" + "time": "2017-08-03 14:08:16" }, { "name": "psr/container", @@ -5054,21 +5054,21 @@ }, { "name": "sebastian/object-enumerator", - "version": "3.0.2", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "31dd3379d16446c5d86dec32ab1ad1f378581ad8" + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/31dd3379d16446c5d86dec32ab1ad1f378581ad8", - "reference": "31dd3379d16446c5d86dec32ab1ad1f378581ad8", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", "shasum": "" }, "require": { "php": "^7.0", - "sebastian/object-reflector": "^1.0", + "sebastian/object-reflector": "^1.1.1", "sebastian/recursion-context": "^3.0" }, "require-dev": { @@ -5097,7 +5097,7 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-03-12 15:17:29" + "time": "2017-08-03 12:35:26" }, { "name": "sebastian/object-reflector", @@ -5338,7 +5338,7 @@ }, { "name": "symfony/phpunit-bridge", - "version": "v3.3.5", + "version": "v3.3.6", "source": { "type": "git", "url": "https://github.com/symfony/phpunit-bridge.git", diff --git a/features/bootstrap/AccountHelper.php b/features/bootstrap/AccountHelper.php index 0d6bb84..89092e3 100644 --- a/features/bootstrap/AccountHelper.php +++ b/features/bootstrap/AccountHelper.php @@ -1,7 +1,6 @@ setUsername($username)->setEmail($email)->setFirstName('string') - ->setLastName('string')->setPassword('string')->setSalt('string'); + $account->setEmail($email)->setPassword('string')->setSalt('string'); ++self::$numberAccount; return $account; } -} + +} \ No newline at end of file diff --git a/features/bootstrap/ChannelHelper.php b/features/bootstrap/ChannelHelper.php index dc10fc3..cd71034 100644 --- a/features/bootstrap/ChannelHelper.php +++ b/features/bootstrap/ChannelHelper.php @@ -7,22 +7,22 @@ class ChannelHelper extends ResourceHelper { private static $numberChannel = 0; - private $accountHelper; + private $profileHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper) + public function __construct(EntityManager $em, ProfileHelper $profileHelper) { parent::__construct($em); - $this->accountHelper = $accountHelper; + $this->profileHelper = $profileHelper; } public function createResource() { - $account = $this->accountHelper->persistResource(); + $profile = $this->profileHelper->persistResource(); $name = 'string'.self::$numberChannel; $channel = new Channel(); - $channel->setAccount($account)->setName($name)->setTags(['string']); + $channel->setProfile($profile)->setName($name)->setTags(['string']); ++self::$numberChannel; diff --git a/features/bootstrap/CommentHelper.php b/features/bootstrap/CommentHelper.php index 205d5ad..eba5f19 100644 --- a/features/bootstrap/CommentHelper.php +++ b/features/bootstrap/CommentHelper.php @@ -6,31 +6,31 @@ class CommentHelper extends ResourceHelper { /** - * @var AccountHelper + * @var ProfileHelper */ - private $accountHelper; + private $profileHelper; /** * @var VideoHelper */ private $videoHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, ProfileHelper $profileHelper, VideoHelper $videoHelper) { parent::__construct($em); - $this->accountHelper = $accountHelper; + $this->profileHelper = $profileHelper; $this->videoHelper = $videoHelper; } public function createResource() { - $account = $this->accountHelper->persistResource(); + $profile = $this->profileHelper->persistResource(); $video = $this->videoHelper->persistResource(); $comment = new Comment(); $comment->setContent('string')->setDateComment(new DateTime('1879-03-14')) - ->setVideo($video)->setAuthor($account); + ->setVideo($video)->setAuthor($profile); return $comment; } diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index f6ad030..bb470df 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -68,20 +68,21 @@ public function __construct(Request $request, ManagerRegistry $doctrine, Kernel $this->classes = $this->manager->getMetadataFactory()->getAllMetadata(); $this->helpers['Account'] = new AccountHelper($this->manager); - $this->helpers['Channel'] = new ChannelHelper($this->manager, $this->helpers['Account']); - $this->helpers['Playlist'] = new PlaylistHelper($this->manager, $this->helpers['Account']); + $this->helpers['Profile'] = new ProfileHelper($this->manager, $this->helpers['Account']); + $this->helpers['Channel'] = new ChannelHelper($this->manager, $this->helpers['Profile']); + $this->helpers['Playlist'] = new PlaylistHelper($this->manager, $this->helpers['Profile']); $this->helpers['Video'] = new VideoHelper($this->manager, $this->helpers['Channel']); $this->helpers['SustainabilityOffer'] = new SustainabilityOfferHelper($this->manager, $this->helpers['Channel']); $this->helpers['Category'] = new CategoryHelper($this->manager); $this->helpers['Network'] = new NetworkHelper($this->manager); - $this->helpers['View'] = new ViewHelper($this->manager, $this->helpers['Account'], $this->helpers['Video']); - $this->helpers['Forum'] = new ForumHelper($this->manager, $this->helpers['Account'], $this->helpers['Video']); - $this->helpers['Review'] = new ReviewHelper($this->manager, $this->helpers['Account'], $this->helpers['Video']); - $this->helpers['Reply'] = new ReplyHelper($this->manager, $this->helpers['Account'], $this->helpers['Review']); - $this->helpers['Seeder'] = new SeederHelper($this->manager, $this->helpers['Account'], $this->helpers['Video']); + $this->helpers['View'] = new ViewHelper($this->manager, $this->helpers['Profile'], $this->helpers['Video']); + $this->helpers['Forum'] = new ForumHelper($this->manager, $this->helpers['Profile'], $this->helpers['Video']); + $this->helpers['Review'] = new ReviewHelper($this->manager, $this->helpers['Profile'], $this->helpers['Video']); + $this->helpers['Reply'] = new ReplyHelper($this->manager, $this->helpers['Profile'], $this->helpers['Review']); + $this->helpers['Seeder'] = new SeederHelper($this->manager, $this->helpers['Profile'], $this->helpers['Video']); $this->helpers['Subtitles'] = new SubtitlesHelper($this->manager, $this->helpers['Video']); $this->helpers['Annotation'] = new AnnotationHelper($this->manager, $this->helpers['Video']); - $this->helpers['Comment'] = new CommentHelper($this->manager, $this->helpers['Account'], $this->helpers['Video']); + $this->helpers['Comment'] = new CommentHelper($this->manager, $this->helpers['Profile'], $this->helpers['Video']); } /** diff --git a/features/bootstrap/ForumHelper.php b/features/bootstrap/ForumHelper.php index 4973007..46477c1 100644 --- a/features/bootstrap/ForumHelper.php +++ b/features/bootstrap/ForumHelper.php @@ -6,7 +6,7 @@ class ForumHelper extends ResourceHelper { /** - * @var AccountHelper + * @var ProfileHelper */ private $accountHelper; @@ -15,7 +15,7 @@ class ForumHelper extends ResourceHelper */ private $videoHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, ProfileHelper $accountHelper, VideoHelper $videoHelper) { parent::__construct($em); $this->accountHelper = $accountHelper; @@ -35,7 +35,7 @@ public function createResource() public function createRelationWith($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Account') { + if ($nameResource2 == 'Profile') { return parent::createRelationWith($resource, 'CreatedBy', $resource2); } @@ -44,7 +44,7 @@ public function createRelationWith($resource, string $nameResource2, $resource2) public function relationExists($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Account') { + if ($nameResource2 == 'Profile') { return parent::relationExists($resource, 'CreatedBy', $resource2); } diff --git a/features/bootstrap/NetworkHelper.php b/features/bootstrap/NetworkHelper.php index 47b4147..5fdf9af 100644 --- a/features/bootstrap/NetworkHelper.php +++ b/features/bootstrap/NetworkHelper.php @@ -20,7 +20,7 @@ public function createResource() public function createRelationWith($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Account') { + if ($nameResource2 == 'Profile') { return parent::createRelationWith($resource, 'Peoples', $resource2); } @@ -29,7 +29,7 @@ public function createRelationWith($resource, string $nameResource2, $resource2) public function relationExists($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Account') { + if ($nameResource2 == 'Profile') { return parent::relationExists($resource, 'Peoples', $resource2); } diff --git a/features/bootstrap/PlaylistHelper.php b/features/bootstrap/PlaylistHelper.php index ad55ab1..8c5695a 100644 --- a/features/bootstrap/PlaylistHelper.php +++ b/features/bootstrap/PlaylistHelper.php @@ -8,20 +8,20 @@ class PlaylistHelper extends ResourceHelper /** * @var ChannelHelper */ - private $accountHelper; + private $profileHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper) + public function __construct(EntityManager $em, ProfileHelper $profileHelper) { parent::__construct($em); - $this->accountHelper = $accountHelper; + $this->accountHelper = $profileHelper; } public function createResource() { - $account = $this->accountHelper->persistResource(); + $profileHelper = $this->profileHelper->persistResource(); $playlist = new Playlist(); - $playlist->setAccount($account)->setName('string'); + $playlist->setProfile($profileHelper)->setName('string'); return $playlist; } diff --git a/features/bootstrap/ProfileHelper.php b/features/bootstrap/ProfileHelper.php new file mode 100644 index 0000000..ca77da6 --- /dev/null +++ b/features/bootstrap/ProfileHelper.php @@ -0,0 +1,31 @@ +accountHelper = $accountHelper; + } + + public function createResource() + { + $account = $this->accountHelper->createResource(); + + $username = 'string'.self::$numberAccount; + + $profile = new Profile(); + $profile->setUsername($username)->setFirstName('string') + ->setLastName('string')->setAccount($account); + + ++self::$numberAccount; + + return $profile; + } +} diff --git a/features/bootstrap/ReplyHelper.php b/features/bootstrap/ReplyHelper.php index ddbca19..e5548a9 100644 --- a/features/bootstrap/ReplyHelper.php +++ b/features/bootstrap/ReplyHelper.php @@ -6,36 +6,36 @@ class ReplyHelper extends ResourceHelper { /** - * @var AccountHelper + * @var ProfileHelper */ - private $accountHelper; + private $profileHelper; /** * @var ReviewHelper */ private $reviewHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, ReviewHelper $reviewHelper) + public function __construct(EntityManager $em, ProfileHelper $profileHelper, ReviewHelper $reviewHelper) { parent::__construct($em); - $this->accountHelper = $accountHelper; + $this->profileHelper = $profileHelper; $this->reviewHelper = $reviewHelper; } public function createResource() { - $account = $this->accountHelper->persistResource(); + $profile = $this->profileHelper->persistResource(); $review = $this->reviewHelper->persistResource(); $reply = new Reply(); - $reply->setReview($review)->setAuthor($account)->setContent('string')->setDateReply(new \DateTime()); + $reply->setReview($review)->setAuthor($profile)->setContent('string')->setDateReply(new \DateTime()); return $reply; } public function createRelationWith($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Account') { + if ($nameResource2 == 'Profile') { return parent::createRelationWith($resource, 'Author', $resource2); } @@ -44,7 +44,7 @@ public function createRelationWith($resource, string $nameResource2, $resource2) public function relationExists($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Account') { + if ($nameResource2 == 'Profile') { return parent::relationExists($resource, 'Author', $resource2); } diff --git a/features/bootstrap/ReviewHelper.php b/features/bootstrap/ReviewHelper.php index 5e39a4c..e9c53e0 100644 --- a/features/bootstrap/ReviewHelper.php +++ b/features/bootstrap/ReviewHelper.php @@ -6,36 +6,36 @@ class ReviewHelper extends ResourceHelper { /** - * @var AccountHelper + * @var ProfileHelper */ - private $accountHelper; + private $profileHelper; /** * @var VideoHelper */ private $videoHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, ProfileHelper $profileHelper, VideoHelper $videoHelper) { parent::__construct($em); - $this->accountHelper = $accountHelper; + $this->profileHelper = $profileHelper; $this->videoHelper = $videoHelper; } public function createResource() { - $account = $this->accountHelper->persistResource(); + $profile = $this->profileHelper->persistResource(); $video = $this->videoHelper->persistResource(); $review = new Review(); - $review->setVideo($video)->setAuthor($account)->setContent('string')->setDateReview(new \DateTime('1879-03-14T00:00:00+00:09')); + $review->setVideo($video)->setAuthor($profile)->setContent('string')->setDateReview(new \DateTime('1879-03-14T00:00:00+00:09')); return $review; } public function createRelationWith($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Account') { + if ($nameResource2 == 'Profile') { return parent::createRelationWith($resource, 'Author', $resource2); } @@ -44,7 +44,7 @@ public function createRelationWith($resource, string $nameResource2, $resource2) public function relationExists($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Account') { + if ($nameResource2 == 'Profile') { return parent::relationExists($resource, 'Author', $resource2); } diff --git a/features/bootstrap/SeederHelper.php b/features/bootstrap/SeederHelper.php index 04af2f2..75dc475 100644 --- a/features/bootstrap/SeederHelper.php +++ b/features/bootstrap/SeederHelper.php @@ -6,29 +6,29 @@ class SeederHelper extends ResourceHelper { /** - * @var AccountHelper + * @var ProfileHelper */ - private $accountHelper; + private $profileHelper; /** * @var VideoHelper */ private $videoHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, ProfileHelper $profileHelper, VideoHelper $videoHelper) { parent::__construct($em); - $this->accountHelper = $accountHelper; + $this->profileHelper = $profileHelper; $this->videoHelper = $videoHelper; } public function createResource() { - $account = $this->accountHelper->persistResource(); + $profile = $this->profileHelper->persistResource(); $video = $this->videoHelper->persistResource(); $seeder = new Seeder(); - $seeder->setPlatform('string')->setIp('127.0.0.1')->setAccount($account)->setVideo($video); + $seeder->setPlatform('string')->setIp('127.0.0.1')->setAccount($profile)->setVideo($video); return $seeder; } diff --git a/features/bootstrap/SustainabilityOfferHelper.php b/features/bootstrap/SustainabilityOfferHelper.php index 9eef9cf..1eb0a51 100644 --- a/features/bootstrap/SustainabilityOfferHelper.php +++ b/features/bootstrap/SustainabilityOfferHelper.php @@ -22,7 +22,7 @@ public function createResource() $sustainabilityOffer = new SustainabilityOffer(); $sustainabilityOffer->setName('string')->setDuration(0) - ->setAccount($channel->getAccount())->setChannel($channel); + ->setProfile($channel->getProfile())->setChannel($channel); return $sustainabilityOffer; } diff --git a/features/bootstrap/ViewHelper.php b/features/bootstrap/ViewHelper.php index 1cddcff..7d5cdba 100644 --- a/features/bootstrap/ViewHelper.php +++ b/features/bootstrap/ViewHelper.php @@ -6,29 +6,29 @@ class ViewHelper extends ResourceHelper { /** - * @var AccountHelper + * @var ProfileHelper */ - private $accountHelper; + private $profileHelper; /** * @var VideoHelper */ private $videoHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, ProfileHelper $profileHelper, VideoHelper $videoHelper) { parent::__construct($em); - $this->accountHelper = $accountHelper; + $this->profileHelper = $profileHelper; $this->videoHelper = $videoHelper; } public function createResource() { - $account = $this->accountHelper->persistResource(); + $profile = $this->profileHelper>persistResource(); $video = $this->videoHelper->persistResource(); $view = new View(); - $view->setVideo($video)->setAccount($account); + $view->setVideo($video)->setProfile($profile); return $view; } diff --git a/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php b/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php index 70bc88e..192a8d8 100644 --- a/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php +++ b/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php @@ -3,6 +3,7 @@ namespace AppBundle\DataFixtures\ORM\Fixtures; use AppBundle\Entity\Account; +use AppBundle\Entity\Profile; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use Symfony\Bridge\Doctrine\Tests\Fixtures\ContainerAwareFixture; @@ -11,14 +12,19 @@ class AccountData extends ContainerAwareFixture implements OrderedFixtureInterfa { public function load(ObjectManager $manager) { - $account = new Account(); + $privateData = new Account(); + $privateData->setEmail('denis@denis.fr') + ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) + ->setPassword($this->container->get('security.password_encoder')->encodePassword($privateData, 'password')); + $manager->persist($privateData); + + $account = new Profile(); $account ->setFirstName('denis') ->setLastName('denis') ->setUsername('denis') - ->setEmail('denis@denis.fr') - ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) - ->setPassword($this->container->get('security.password_encoder')->encodePassword($account, 'password')) + ->setAccount($privateData) + ; $manager->persist($account); $manager->flush(); diff --git a/src/AppBundle/Entity/Account.php b/src/AppBundle/Entity/Account.php index f995238..66ce400 100644 --- a/src/AppBundle/Entity/Account.php +++ b/src/AppBundle/Entity/Account.php @@ -12,7 +12,7 @@ * User's account. * * @ORM\Entity(repositoryClass="AppBundle\Repository\AccountRepository") - * @ApiResource(attributes={"filters" = {"account.search"}, "normalization_context" = {"groups" = {"account"}}}) + * @ApiResource */ class Account implements UserInterface { @@ -72,7 +72,7 @@ public function getUsername(): string return $this->profile->getUsername(); } - public function setUsername($username) + public function setUsername(string $username): Account { $this->profile->setUsername($username); @@ -84,7 +84,7 @@ public function getEmail(): string return $this->email; } - public function setEmail($email) + public function setEmail($email): Account { $this->email = $email; @@ -136,12 +136,12 @@ public function setId(int $id): Account return $this; } - public function getProfile(): Account + public function getProfile(): Profile { return $this->profile; } - public function setProfile(Account $profile): Account + public function setProfile(Profile $profile): Account { $this->profile = $profile; diff --git a/src/AppBundle/Entity/Annotation.php b/src/AppBundle/Entity/Annotation.php index 4f548da..18b5a1f 100644 --- a/src/AppBundle/Entity/Annotation.php +++ b/src/AppBundle/Entity/Annotation.php @@ -111,7 +111,7 @@ public function getVideo(): Video return $this->video; } - public function setVideo($video): Annotation + public function setVideo(Video $video): Annotation { $this->video = $video; diff --git a/src/AppBundle/Entity/Channel.php b/src/AppBundle/Entity/Channel.php index 5a1b4d9..2370b34 100644 --- a/src/AppBundle/Entity/Channel.php +++ b/src/AppBundle/Entity/Channel.php @@ -43,11 +43,11 @@ class Channel private $tags; /** - * @var Account The owner's account + * @var Profile The owner's account * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="channels", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="channels", cascade={"persist"}) */ - private $account; + private $profile; /** * @var Video @@ -87,14 +87,14 @@ public function __construct() $this->sustainabilityOffers = new ArrayCollection(); } - public function getAccount(): Account + public function getProfile(): Profile { - return $this->account; + return $this->profile; } - public function setAccount(Account $account) + public function setProfile(Profile $profile): Channel { - $this->account = $account; + $this->profile = $profile; return $this; } diff --git a/src/AppBundle/Entity/Comment.php b/src/AppBundle/Entity/Comment.php index 4e9c3c6..702dc85 100644 --- a/src/AppBundle/Entity/Comment.php +++ b/src/AppBundle/Entity/Comment.php @@ -41,9 +41,9 @@ class Comment private $video; /** - * @var Account Author of the comment + * @var Profile Author of the comment * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account") + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile") */ private $author; @@ -104,12 +104,12 @@ public function setVideo(Video $video): Comment return $this; } - public function getAuthor(): Account + public function getAuthor(): Profile { return $this->author; } - public function setAuthor(Account $author): Comment + public function setAuthor(Profile $author): Comment { $this->author = $author; diff --git a/src/AppBundle/Entity/Forum.php b/src/AppBundle/Entity/Forum.php index 3fc4d2b..e860522 100644 --- a/src/AppBundle/Entity/Forum.php +++ b/src/AppBundle/Entity/Forum.php @@ -42,9 +42,9 @@ class Forum private $video; /** - * @var Account + * @var Profile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="forums", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="forums", cascade={"persist"}) */ private $createdBy; @@ -77,7 +77,7 @@ public function getVideo() return $this->video; } - public function setVideo($video) + public function setVideo(Video $video): Forum { $this->video = $video; @@ -89,7 +89,7 @@ public function getCreatedBy() return $this->createdBy; } - public function setCreatedBy($createdBy): Forum + public function setCreatedBy(Profile $createdBy): Forum { $this->createdBy = $createdBy; diff --git a/src/AppBundle/Entity/Network.php b/src/AppBundle/Entity/Network.php index 46bed43..4359105 100644 --- a/src/AppBundle/Entity/Network.php +++ b/src/AppBundle/Entity/Network.php @@ -37,7 +37,7 @@ class Network /** * @var ArrayCollection * - * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Account", inversedBy="networks", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Profile", inversedBy="networks", cascade={"persist"}) */ private $peoples; @@ -78,7 +78,7 @@ public function getChannels() return $this->channels; } - public function setChannels($channels) + public function setChannels($channels): Network { $this->channels = $channels; diff --git a/src/AppBundle/Entity/Playlist.php b/src/AppBundle/Entity/Playlist.php index 949df68..83ccee7 100644 --- a/src/AppBundle/Entity/Playlist.php +++ b/src/AppBundle/Entity/Playlist.php @@ -52,12 +52,12 @@ class Playlist private $network; /** - * @var Account + * @var Profile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="playlists", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="playlists", cascade={"persist"}) * @ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=true) */ - private $account; + private $profile; public function getId(): int { @@ -107,14 +107,14 @@ public function setNetwork(Network $network): Playlist return $this; } - public function getAccount() + public function getProfile() { - return $this->account; + return $this->profile; } - public function setAccount(Account $account): Playlist + public function setProfile(Profile $profile): Playlist { - $this->account = $account; + $this->profile = $profile; return $this; } diff --git a/src/AppBundle/Entity/Profile.php b/src/AppBundle/Entity/Profile.php index 7b21b9b..8288fc7 100644 --- a/src/AppBundle/Entity/Profile.php +++ b/src/AppBundle/Entity/Profile.php @@ -41,7 +41,7 @@ class Profile /** * @var ArrayCollection The list of the channels * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Channel", mappedBy="account", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\Channel", mappedBy="profile", cascade={"persist"}) * @Groups({"account"}) */ private $channels; @@ -50,7 +50,7 @@ class Profile * @var ArrayCollection The list of views * * @Groups({"account"}) - * @ORM\OneToMany(targetEntity="AppBundle\Entity\View", mappedBy="account", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\View", mappedBy="profile", cascade={"persist"}) */ private $views; @@ -74,7 +74,7 @@ class Profile /** * @var ArrayCollection * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Playlist", mappedBy="account", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\Playlist", mappedBy="profile", cascade={"persist"}) * @Groups({"account"}) */ private $playlists; @@ -98,7 +98,7 @@ class Profile /** * @var ArrayCollection * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\SustainabilityOffer", mappedBy="account", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\SustainabilityOffer", mappedBy="profile", cascade={"persist"}) * @Groups({"account"}) */ private $sustainabilityOffers; @@ -106,7 +106,7 @@ class Profile /** * @var ArrayCollection * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Seeder", mappedBy="account", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\Seeder", mappedBy="profile", cascade={"persist"}) * @Groups({"account"}) */ private $seeders; @@ -158,7 +158,7 @@ public function getViews() return $this->views; } - public function setViews($views) + public function setViews($views): Profile { $this->views = $views; @@ -170,7 +170,7 @@ public function getChannels() return $this->channels; } - public function setChannels($channels) + public function setChannels($channels): Profile { $this->channels = $channels; @@ -182,7 +182,7 @@ public function getId(): int return $this->id; } - public function setId($id) + public function setId($id): Profile { $this->id = $id; @@ -194,7 +194,7 @@ public function getUsername(): string return $this->username; } - public function setUsername($username) + public function setUsername(string $username): Profile { $this->username = $username; @@ -206,7 +206,7 @@ public function getFirstName(): string return $this->firstName; } - public function setFirstName($firstName) + public function setFirstName(string $firstName): Profile { $this->firstName = $firstName; @@ -218,7 +218,7 @@ public function getLastName(): string return $this->lastName; } - public function setLastName($lastName) + public function setLastName(string $lastName): Profile { $this->lastName = $lastName; @@ -230,7 +230,7 @@ public function getForums() return $this->forums; } - public function setForums($forums): Account + public function setForums($forums): Profile { $this->forums = $forums; @@ -242,7 +242,7 @@ public function getNetworks() return $this->networks; } - public function setNetworks($networks): Account + public function setNetworks($networks): Profile { $this->networks = $networks; @@ -254,7 +254,7 @@ public function getPlaylists() return $this->playlists; } - public function setPlaylist($playlists): Account + public function setPlaylist($playlists): Profile { $this->playlists = $playlists; @@ -266,7 +266,7 @@ public function getReplies() return $this->replies; } - public function setReplies($replies): Account + public function setReplies($replies): Profile { $this->replies = $replies; @@ -278,7 +278,7 @@ public function getReviews() return $this->reviews; } - public function setReviews($reviews): Account + public function setReviews($reviews): Profile { $this->reviews = $reviews; @@ -290,7 +290,7 @@ public function getSustainabilityOffers() return $this->sustainabilityOffers; } - public function setSustainabilityOffers($sustainabilityOffers): Account + public function setSustainabilityOffers($sustainabilityOffers): Profile { $this->sustainabilityOffers = $sustainabilityOffers; @@ -302,7 +302,7 @@ public function getSeeders() return $this->seeders; } - public function setSeeders($seeders): Account + public function setSeeders($seeders): Profile { $this->seeders = $seeders; diff --git a/src/AppBundle/Entity/Reply.php b/src/AppBundle/Entity/Reply.php index 0c97e78..3124b87 100644 --- a/src/AppBundle/Entity/Reply.php +++ b/src/AppBundle/Entity/Reply.php @@ -41,9 +41,9 @@ class Reply private $review; /** - * @var Account + * @var Profile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="replies") + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="replies") */ private $author; @@ -92,12 +92,12 @@ public function setReview(Review $review): Reply return $this; } - public function getAuthor(): Account + public function getAuthor(): Profile { return $this->author; } - public function setAuthor($author): Reply + public function setAuthor(Profile $author): Reply { $this->author = $author; diff --git a/src/AppBundle/Entity/Review.php b/src/AppBundle/Entity/Review.php index e4e70bd..7c0876c 100644 --- a/src/AppBundle/Entity/Review.php +++ b/src/AppBundle/Entity/Review.php @@ -42,9 +42,9 @@ class Review private $video; /** - * @var Account + * @var Profile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="reviews") + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="reviews") */ private $author; @@ -128,12 +128,12 @@ public function setReplies($replies): Review return $this; } - public function getAuthor(): Account + public function getAuthor(): Profile { return $this->author; } - public function setAuthor(Account $author): Review + public function setAuthor(Profile $author): Review { $this->author = $author; diff --git a/src/AppBundle/Entity/Seeder.php b/src/AppBundle/Entity/Seeder.php index 6c17471..b480030 100644 --- a/src/AppBundle/Entity/Seeder.php +++ b/src/AppBundle/Entity/Seeder.php @@ -41,11 +41,11 @@ class Seeder private $ip; /** - * @var Account + * @var Profile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="seeders", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="seeders", cascade={"persist"}) */ - private $account; + private $profile; /** * @var Video @@ -78,14 +78,14 @@ public function setPlatform(string $platform): Seeder return $this; } - public function getAccount(): Account + public function getProfile(): Profile { - return $this->account; + return $this->profile; } - public function setAccount(Account $account): Seeder + public function setProfile(Profile $profile): Seeder { - $this->account = $account; + $this->profile = $profile; return $this; } diff --git a/src/AppBundle/Entity/Subtitles.php b/src/AppBundle/Entity/Subtitles.php index 9452c89..df4d07a 100644 --- a/src/AppBundle/Entity/Subtitles.php +++ b/src/AppBundle/Entity/Subtitles.php @@ -89,12 +89,12 @@ public function setEnd(\DateTime $end) return $this; } - public function getPath() + public function getPath(): string { return $this->path; } - public function setPath($path) + public function setPath(string $path) { $this->path = $path; diff --git a/src/AppBundle/Entity/SustainabilityOffer.php b/src/AppBundle/Entity/SustainabilityOffer.php index 1421328..c32ad05 100644 --- a/src/AppBundle/Entity/SustainabilityOffer.php +++ b/src/AppBundle/Entity/SustainabilityOffer.php @@ -43,11 +43,11 @@ class SustainabilityOffer private $duration; /** - * @var Account + * @var Profile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="sustainabilityOffers", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="sustainabilityOffers", cascade={"persist"}) */ - private $account; + private $profile; /** * @var Channel @@ -92,14 +92,14 @@ public function setDuration(int $duration): SustainabilityOffer return $this; } - public function getAccount(): Account + public function getProfile(): Profile { - return $this->account; + return $this->profile; } - public function setAccount($account): SustainabilityOffer + public function setProfile(Profile $profile): SustainabilityOffer { - $this->account = $account; + $this->profile = $profile; return $this; } @@ -109,7 +109,7 @@ public function getChannel(): Channel return $this->channel; } - public function setChannel($channel): SustainabilityOffer + public function setChannel(Channel $channel): SustainabilityOffer { $this->channel = $channel; diff --git a/src/AppBundle/Entity/Video.php b/src/AppBundle/Entity/Video.php index abe5e90..2f1e004 100644 --- a/src/AppBundle/Entity/Video.php +++ b/src/AppBundle/Entity/Video.php @@ -187,7 +187,7 @@ public function getId() return $this->id; } - public function setTitle($title) + public function setTitle(string $title): Video { $this->title = $title; @@ -235,12 +235,12 @@ public function setAnnotations($annotations): Video return $this; } - public function getChannel() + public function getChannel(): Channel { return $this->channel; } - public function setChannel($channel): Video + public function setChannel(Channel $channel): Video { $this->channel = $channel; diff --git a/src/AppBundle/Entity/View.php b/src/AppBundle/Entity/View.php index cd6da15..5f3ca70 100644 --- a/src/AppBundle/Entity/View.php +++ b/src/AppBundle/Entity/View.php @@ -23,11 +23,11 @@ class View private $id; /** - * @var Account + * @var Profile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="views", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="views", cascade={"persist"}) */ - private $account; + private $profile; /** * @var Video @@ -46,14 +46,14 @@ public function setId(int $id) $this->id = $id; } - public function getAccount(): Account + public function getProfile(): Profile { - return $this->account; + return $this->profile; } - public function setAccount(Account $account) + public function setProfile(Profile $profile) { - $this->account = $account; + $this->profile = $profile; return $this; } diff --git a/src/AppBundle/EventSubscriber/AccountChecker.php b/src/AppBundle/EventSubscriber/AccountChecker.php index 70ad2dc..536f661 100644 --- a/src/AppBundle/EventSubscriber/AccountChecker.php +++ b/src/AppBundle/EventSubscriber/AccountChecker.php @@ -2,24 +2,24 @@ namespace AppBundle\EventSubscriber; +use ApiPlatform\Core\EventListener\EventPriorities; use AppBundle\Entity\Profile; use AppBundle\Security\AccountVoter; -use Symfony\Component\BrowserKit\Response; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; class AccountChecker implements EventSubscriberInterface { - private $accountVoter; - private $tokenStorage; + private $authorizationChecker; - public function __construct(AccountVoter $accountVoter, TokenInterface $tokenStorage) + public function __construct(AuthorizationCheckerInterface $authorizationChecker) { - $this->accountVoter = $accountVoter; - $this->tokenStorage = $tokenStorage; + $this->authorizationChecker = $authorizationChecker; } public static function getSubscribedEvents() @@ -38,15 +38,9 @@ public function checkAccountAccess(GetResponseForControllerResultEvent $event) return; } - if (!correctValue($profile)) { - $response = new Response('You don\'t have access to this account', Response::); + if (!$this->authorizationChecker->isGranted('access', $profile)) { + $response = new Response('You don\'t have access to this account', Response::HTTP_FORBIDDEN); $event->setResponse($response); } } - - private function correctValue(Profile $profile) - { - $this->accountVoter->vote($this->tokenStorage, $profile, $profile->getAccount()) === VoterInterface::ACCESS_GRANTED; - } - } \ No newline at end of file diff --git a/src/AppBundle/Repository/AccountRepository.php b/src/AppBundle/Repository/AccountRepository.php index 5af92be..e54c819 100644 --- a/src/AppBundle/Repository/AccountRepository.php +++ b/src/AppBundle/Repository/AccountRepository.php @@ -6,17 +6,6 @@ class AccountRepository extends EntityRepository { - public function findOneByEmail(string $email) - { - return $this->createQueryBuilder('a') - ->select('a') - ->where('a.email = :email') - ->setParameter('email', $email) - ->getQuery() - ->getOneOrNullResult() - ; - } - public function findOneByUsername(string $username) { return $this->createQueryBuilder('a') diff --git a/src/AppBundle/Repository/ProfileRepository.php b/src/AppBundle/Repository/ProfileRepository.php new file mode 100644 index 0000000..4eef4df --- /dev/null +++ b/src/AppBundle/Repository/ProfileRepository.php @@ -0,0 +1,19 @@ +createQueryBuilder('a') + ->select('a') + ->where('a.email = :email') + ->setParameter('email', $email) + ->getQuery() + ->getOneOrNullResult() + ; + } +} \ No newline at end of file diff --git a/src/AppBundle/Security/AccountProvider.php b/src/AppBundle/Security/AccountProvider.php index 7f5c094..35552d4 100644 --- a/src/AppBundle/Security/AccountProvider.php +++ b/src/AppBundle/Security/AccountProvider.php @@ -3,6 +3,7 @@ namespace AppBundle\Security; use AppBundle\Entity\Account; +use AppBundle\Entity\Profile; use Doctrine\ORM\EntityManager; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; @@ -15,7 +16,7 @@ class AccountProvider implements UserProviderInterface public function __construct(EntityManager $em) { - $this->repository = $em->getRepository('AppBundle:Account'); + $this->repository = $em->getRepository('AppBundle:Profile'); } public function loadUserByUsername($username) @@ -31,7 +32,7 @@ public function loadUserByUsername($username) public function refreshUser(UserInterface $user) { - if (!$user instanceof Account) { + if (!$user instanceof Profile) { throw new UnsupportedUserException( sprintf('Instances of "%s" are not supported.', get_class($user)) ); diff --git a/src/AppBundle/Security/AccountVoter.php b/src/AppBundle/Security/AccountVoter.php index 2a40dbb..518b804 100644 --- a/src/AppBundle/Security/AccountVoter.php +++ b/src/AppBundle/Security/AccountVoter.php @@ -4,6 +4,7 @@ use AppBundle\Entity\Account; use AppBundle\Entity\Profile; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\Voter\Voter; @@ -41,8 +42,8 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token) throw new \LogicException('This code should not be reached!'); } - private function canAccess(Account $account, Profile $user) + private function canAccess(Profile $profile, Account $account) { - return $user->getAccount()->getId() === $account->getId(); + return $profile->getAccount()->getId() === $account->getId(); } } \ No newline at end of file From 83a2cc6faa23f28e583c40e9bfe36fd4de1ee318 Mon Sep 17 00:00:00 2001 From: mike1796 Date: Thu, 3 Aug 2017 22:41:12 +0200 Subject: [PATCH 3/5] Adding of everything but test does not pass Adding of password encryption --- app/config/services.yml | 7 +- features/Profile.feature | 667 ++++++++++++++++++ features/bootstrap/AccountHelper.php | 1 + .../DataFixtures/ORM/Fixtures/AccountData.php | 9 +- src/AppBundle/DataFixtures/ORM/fixtures.yml | 38 +- .../EventSubscriber/AccountChecker.php | 3 +- .../EventSubscriber/PasswordEncryption.php | 41 ++ src/AppBundle/Listener/ResponseListener.php | 4 +- src/AppBundle/Security/RateLimiter.php | 11 +- .../Listener/ResponseListenerTest.php | 7 + tests/AppBundle/Security/RateLimiterTest.php | 2 +- 11 files changed, 763 insertions(+), 27 deletions(-) create mode 100644 features/Profile.feature create mode 100644 src/AppBundle/EventSubscriber/PasswordEncryption.php diff --git a/app/config/services.yml b/app/config/services.yml index 1000916..16757e9 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -27,4 +27,9 @@ services: class: AppBundle\EventSubscriber\AccountChecker arguments: [ "@security.authorization_checker" ] tags: - - { name: kernel.event_listener, event: kernel.request } + - { name: kernel.event_listener, event: kernel.view } + + app.event_subscriber.password_encryption: + class: AppBundle\EventSubscriber\PasswordEncryption + tags: + - { name: kernel.event_listener, event: kernel.view } diff --git a/features/Profile.feature b/features/Profile.feature new file mode 100644 index 0000000..aba1209 --- /dev/null +++ b/features/Profile.feature @@ -0,0 +1,667 @@ +# features/Profile.feature +Feature: Manage Profile + In order to manage Profile + As a client software developer + I need to be able to retrieve, create, update and delete them trough the API. + + Background: + Given I am connected as "denis" with password "password" + + @refreshSchema + @requiresOAuth + Scenario: Create a profile + When I add "Content-Type" header equal to "application/ld+json" + And I add "Accept" header equal to "application/ld+json" + And I send a "POST" request to "/profiles" with body: + """ + { + "username": "string", + "firstName": "string", + "lastName": "string" + } + """ + Then the response status code should be 401 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/json" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Account", + "@id": "/accounts/2", + "@type": "Account", + "id": 2, + "username": "string", + "email": "string@string.fr", + "firstName": "string", + "lastName": "string", + "channels": [], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [] + } + """ + +# Scenario: Retrieve the account list +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts", +# "@type": "hydra:Collection", +# "hydra:member": [ +# { +# "@id": "/accounts/1", +# "@type": "Account", +# "id": 1, +# "username": "denis", +# "email": "denis@denis.fr", +# "firstName": "denis", +# "lastName": "denis", +# "channels": [], +# "views": [], +# "forums": [], +# "networks": [], +# "playlists": [], +# "replies": [], +# "reviews": [], +# "sustainabilityOffers": [], +# "seeders": [] +# }, +# { +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "string", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [], +# "views": [], +# "forums": [], +# "networks": [], +# "playlists": [], +# "replies": [], +# "reviews": [], +# "sustainabilityOffers": [], +# "seeders": [] +# } +# ], +# "hydra:totalItems": 2, +# "hydra:search": { +# "@type": "hydra:IriTemplate", +# "hydra:template": "/accounts{?id,id[],username,email,firstName}", +# "hydra:variableRepresentation": "BasicRepresentation", +# "hydra:mapping": [ +# { +# "@type": "IriTemplateMapping", +# "variable": "id", +# "property": "id", +# "required": false +# }, +# { +# "@type": "IriTemplateMapping", +# "variable": "id[]", +# "property": "id", +# "required": false +# }, +# { +# "@type": "IriTemplateMapping", +# "variable": "username", +# "property": "username", +# "required": false +# }, +# { +# "@type": "IriTemplateMapping", +# "variable": "email", +# "property": "email", +# "required": false +# }, +# { +# "@type": "IriTemplateMapping", +# "variable": "firstName", +# "property": "firstName", +# "required": false +# } +# ] +# } +# } +# """ +# +# Scenario: Throw errors when there is only bad properties +# When I add "Content-Type" header equal to "application/ld+json" +# And I add "Accept" header equal to "application/ld+json" +# And I send a "POST" request to "/accounts" with body: +# """ +# { +# "email": "string" +# } +# """ +# Then the response status code should be 400 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/ConstraintViolationList", +# "@type": "ConstraintViolationList", +# "hydra:title": "An error occurred", +# "hydra:description": "username: This value should not be blank.\nemail: This value is not a valid email address.\nfirstName: This value should not be blank.\nlastName: This value should not be blank.\nsalt: This value should not be blank.\npassword: This value should not be blank.", +# "violations": [ +# { +# "propertyPath": "username", +# "message": "This value should not be blank." +# }, +# { +# "propertyPath": "email", +# "message": "This value is not a valid email address." +# }, +# { +# "propertyPath": "firstName", +# "message": "This value should not be blank." +# }, +# { +# "propertyPath": "lastName", +# "message": "This value should not be blank." +# }, +# { +# "propertyPath": "salt", +# "message": "This value should not be blank." +# }, +# { +# "propertyPath": "password", +# "message": "This value should not be blank." +# } +# ] +# } +# """ +# +# Scenario: Update an account +# When I add "Content-Type" header equal to "application/ld+json" +# And I add "Accept" header equal to "application/ld+json" +# And I send a "PUT" request to "/accounts/2" with body: +# """ +# { +# "username": "stringUpdated" +# } +# """ +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [], +# "views": [], +# "forums": [], +# "networks": [], +# "playlists": [], +# "replies": [], +# "reviews": [], +# "sustainabilityOffers": [], +# "seeders": [] +# } +# """ +# +# Scenario: Get a specific account +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts/2" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [], +# "views": [], +# "forums": [], +# "networks": [], +# "playlists": [], +# "replies": [], +# "reviews": [], +# "sustainabilityOffers": [], +# "seeders": [] +# } +# """ +# +# Scenario: See channel in account +# Given There are "channel" "/channels/1,/channels/2" which have "account" "/accounts/2" +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts/2" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [ +# "/channels/1", +# "/channels/2" +# ], +# "views": [], +# "forums": [], +# "networks": [], +# "playlists": [], +# "replies": [], +# "reviews": [], +# "sustainabilityOffers": [], +# "seeders": [] +# } +# """ +# +# Scenario: See view in account +# Given There are "view" "/views/1,/views/2" which have "account" "/accounts/2" +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts/2" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [ +# "/channels/1", +# "/channels/2" +# ], +# "views": [ +# "/views/1", +# "/views/2" +# ], +# "forums": [], +# "networks": [], +# "playlists": [], +# "replies": [], +# "reviews": [], +# "sustainabilityOffers": [], +# "seeders": [] +# } +# """ +# +# Scenario: See forum in account +# Given There are "forum" "/forums/1,/forums/2" which have "account" "/accounts/2" +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts/2" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [ +# "/channels/1", +# "/channels/2" +# ], +# "views": [ +# "/views/1", +# "/views/2" +# ], +# "forums": [ +# "/forums/1", +# "/forums/2" +# ], +# "networks": [], +# "playlists": [], +# "replies": [], +# "reviews": [], +# "sustainabilityOffers": [], +# "seeders": [] +# } +# """ +# +# Scenario: See network in account +# Given There are "network" "/networks/1,/networks/2" which have "account" "/accounts/2" +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts/2" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [ +# "/channels/1", +# "/channels/2" +# ], +# "views": [ +# "/views/1", +# "/views/2" +# ], +# "forums": [ +# "/forums/1", +# "/forums/2" +# ], +# "networks": [ +# "/networks/1", +# "/networks/2" +# ], +# "playlists": [], +# "replies": [], +# "reviews": [], +# "sustainabilityOffers": [], +# "seeders": [] +# } +# """ +# +# Scenario: See review in account +# Given There are "review" "/reviews/1,/reviews/2" which have "account" "/accounts/2" +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts/2" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [ +# "/channels/1", +# "/channels/2" +# ], +# "views": [ +# "/views/1", +# "/views/2" +# ], +# "forums": [ +# "/forums/1", +# "/forums/2" +# ], +# "networks": [ +# "/networks/1", +# "/networks/2" +# ], +# "playlists": [], +# "replies": [], +# "reviews": [ +# "/reviews/1", +# "/reviews/2" +# ], +# "sustainabilityOffers": [], +# "seeders": [] +# } +# """ +# +# Scenario: See reply in account +# Given There are "reply" "/replies/1,/replies/2" which have "account" "/accounts/1,/accounts/2" +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts/2" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [ +# "/channels/1", +# "/channels/2" +# ], +# "views": [ +# "/views/1", +# "/views/2" +# ], +# "forums": [ +# "/forums/1", +# "/forums/2" +# ], +# "networks": [ +# "/networks/1", +# "/networks/2" +# ], +# "playlists": [], +# "replies": [ +# "/replies/1", +# "/replies/2" +# ], +# "reviews": [ +# "/reviews/1", +# "/reviews/2" +# ], +# "sustainabilityOffers": [], +# "seeders": [] +# } +# """ +# +# Scenario: See Sustainability Offers in account +# Given There are "sustainability offer" "/sustainability_offers/1,/sustainability_offers/2" which have "account" "/accounts/2" +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts/2" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [ +# "/channels/1", +# "/channels/2" +# ], +# "views": [ +# "/views/1", +# "/views/2" +# ], +# "forums": [ +# "/forums/1", +# "/forums/2" +# ], +# "networks": [ +# "/networks/1", +# "/networks/2" +# ], +# "playlists": [], +# "replies": [ +# "/replies/1", +# "/replies/2" +# ], +# "reviews": [ +# "/reviews/1", +# "/reviews/2" +# ], +# "sustainabilityOffers": [ +# "/sustainability_offers/1", +# "/sustainability_offers/2" +# ], +# "seeders": [] +# } +# """ +# +# Scenario: See seeder in account +# Given There are "seeder" "/seeders/1,/seeders/2" which have "account" "/accounts/2" +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts/2" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [ +# "/channels/1", +# "/channels/2" +# ], +# "views": [ +# "/views/1", +# "/views/2" +# ], +# "forums": [ +# "/forums/1", +# "/forums/2" +# ], +# "networks": [ +# "/networks/1", +# "/networks/2" +# ], +# "playlists": [], +# "replies": [ +# "/replies/1", +# "/replies/2" +# ], +# "reviews": [ +# "/reviews/1", +# "/reviews/2" +# ], +# "sustainabilityOffers": [ +# "/sustainability_offers/1", +# "/sustainability_offers/2" +# ], +# "seeders": [ +# "/seeders/1", +# "/seeders/2" +# ] +# } +# """ +# +# Scenario: See playlist in account +# Given There are "playlist" "/playlists/1,/playlist/2" which have "account" "/accounts/2" +# When I add "Accept" header equal to "application/ld+json" +# And I send a "GET" request to "/accounts/2" +# Then the response status code should be 200 +# And the response should be in JSON +# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" +# And the JSON should be equal to: +# """ +# { +# "@context": "/contexts/Account", +# "@id": "/accounts/2", +# "@type": "Account", +# "id": 2, +# "username": "stringUpdated", +# "email": "string@string.fr", +# "firstName": "string", +# "lastName": "string", +# "channels": [ +# "/channels/1", +# "/channels/2" +# ], +# "views": [ +# "/views/1", +# "/views/2" +# ], +# "forums": [ +# "/forums/1", +# "/forums/2" +# ], +# "networks": [ +# "/networks/1", +# "/networks/2" +# ], +# "playlists": [ +# "/playlists/1", +# "/playlists/2" +# ], +# "replies": [ +# "/replies/1", +# "/replies/2" +# ], +# "reviews": [ +# "/reviews/1", +# "/reviews/2" +# ], +# "sustainabilityOffers": [ +# "/sustainability_offers/1", +# "/sustainability_offers/2" +# ], +# "seeders": [ +# "/seeders/1", +# "/seeders/2" +# ] +# } +# """ +# +# Scenario: Delete an account +# When I add "Content-Type" header equal to "application/ld+json" +# And I add "Accept" header equal to "application/ld+json" +# And I send a "DELETE" request to "/accounts/2" +# Then the response status code should be 204 +# +# Scenario: Delete an account +# When I add "Content-Type" header equal to "application/ld+json" +# And I add "Accept" header equal to "application/ld+json" +# And I send a "DELETE" request to "/accounts/2" +# Then the response status code should be 404 diff --git a/features/bootstrap/AccountHelper.php b/features/bootstrap/AccountHelper.php index 89092e3..f088f9f 100644 --- a/features/bootstrap/AccountHelper.php +++ b/features/bootstrap/AccountHelper.php @@ -1,6 +1,7 @@ setEmail('denis@denis.fr') - ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) - ->setPassword($this->container->get('security.password_encoder')->encodePassword($privateData, 'password')); + $privateData + ->setEmail('denis@denis.fr') + ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) + ->setPassword($this->container->get('security.password_encoder')->encodePassword($privateData, 'password')) + ; $manager->persist($privateData); $account = new Profile(); @@ -24,7 +26,6 @@ public function load(ObjectManager $manager) ->setLastName('denis') ->setUsername('denis') ->setAccount($privateData) - ; $manager->persist($account); $manager->flush(); diff --git a/src/AppBundle/DataFixtures/ORM/fixtures.yml b/src/AppBundle/DataFixtures/ORM/fixtures.yml index 492171a..5c57791 100644 --- a/src/AppBundle/DataFixtures/ORM/fixtures.yml +++ b/src/AppBundle/DataFixtures/ORM/fixtures.yml @@ -1,23 +1,29 @@ +AppBundle\Entity\Profile: + profile_{1..10}: + username: + firstName: + lastName: + profile_michel: + username: michel + firstName: Michel + lastName: Michel + AppBundle\Entity\Account: account_{1..10}: - username: email: - firstName: - lastName: password: /ZPeKADSrd8e3wUM7f6DpK/0ukgbztjkSkasUz0Znugln//yx4zXtZTCUckmi/MsRkCCGaZQsTcSX2MTuXfwmw== salt: 12xiixme87nk4cs4sgws400ko + profile: '@profile_' account_michel: - username: michel email: michel@yopmail.fr - firstName: Michel - lastName: Michel password: /ZPeKADSrd8e3wUM7f6DpK/0ukgbztjkSkasUz0Znugln//yx4zXtZTCUckmi/MsRkCCGaZQsTcSX2MTuXfwmw== salt: 12xiixme87nk4cs4sgws400ko + profile: '@profile_michel' AppBundle\Entity\Channel: channel_michel: name: - account: '@account_michel' + profile: '@profile_michel' AppBundle\Entity\Category: category_michel: @@ -75,18 +81,18 @@ AppBundle\Entity\Comment: content: dateComment: video: '@video_michel' - author: '@account_michel' + author: '@profile_michel' AppBundle\Entity\Forum: forum_{1..5}: name: video: '@video_michel' - createdBy: '@account_michel' + createdBy: '@profile_michel' AppBundle\Entity\Network: network_1: name: - peoples: [ '@account_michel' ] + peoples: [ '@profile_michel' ] channels: [ '@channel_michel' ] AppBundle\Entity\Review: @@ -94,20 +100,20 @@ AppBundle\Entity\Review: content: dateReview: video: '@video_michel' - author: '@account_michel' + author: '@profile_michel' AppBundle\Entity\Reply: reply_{1..5}: content: dateReply: - author: '@account_michel' + author: '@profile_michel' review: '@review_1' AppBundle\Entity\Seeder: seeder_{1..5}: platform: ip: - account: '@account_michel' + profile: '@profile_michel' video: '@video_michel' AppBundle\Entity\Subtitles: @@ -121,15 +127,15 @@ AppBundle\Entity\SustainabilityOffer: sustainability_offer_{1..5}: name: duration: 0 - account: '@account_michel' + profile: '@profile_michel' channel: '@channel_michel' AppBundle\Entity\View: view_{1..5}: - account: '@account_michel' + profile: '@profile_michel' video: '@video_michel' AppBundle\Entity\Playlist: playlist_{1..5}: name: - account: '@account_michel' + profile: '@profile_michel' diff --git a/src/AppBundle/EventSubscriber/AccountChecker.php b/src/AppBundle/EventSubscriber/AccountChecker.php index 536f661..4cb5861 100644 --- a/src/AppBundle/EventSubscriber/AccountChecker.php +++ b/src/AppBundle/EventSubscriber/AccountChecker.php @@ -7,6 +7,7 @@ use AppBundle\Security\AccountVoter; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -25,7 +26,7 @@ public function __construct(AuthorizationCheckerInterface $authorizationChecker) public static function getSubscribedEvents() { return [ - KernelEvents::REQUEST => [['checkAccountAccess', EventPriorities::POST_DESERIALIZE]], + KernelEvents::VIEW => [['checkAccountAccess', EventPriorities::POST_VALIDATE]], ]; } diff --git a/src/AppBundle/EventSubscriber/PasswordEncryption.php b/src/AppBundle/EventSubscriber/PasswordEncryption.php new file mode 100644 index 0000000..50ee232 --- /dev/null +++ b/src/AppBundle/EventSubscriber/PasswordEncryption.php @@ -0,0 +1,41 @@ + [['encryptPassword', EventPriorities::PRE_WRITE]], + ]; + } + + public function encryptPassword(GetResponseForControllerResultEvent $event) + { + $profile = $event->getControllerResult(); + $method = $event->getRequest()->getMethod(); + + if (!$profile instanceof Profile || Request::METHOD_POST !== $method) { + return; + } + + $profile->getAccount() + ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) + ->setPassword($this->container->get('security.password_encoder') + ->encodePassword($profile->getAccount(), 'password')) + ; + } +} \ No newline at end of file diff --git a/src/AppBundle/Listener/ResponseListener.php b/src/AppBundle/Listener/ResponseListener.php index 624a908..5c4a957 100644 --- a/src/AppBundle/Listener/ResponseListener.php +++ b/src/AppBundle/Listener/ResponseListener.php @@ -22,6 +22,8 @@ public function onKernelResponse(FilterResponseEvent $event) return; } - $event->getResponse()->headers->add($this->rateLimiter->getResponseHeaders()); + $ip = $event->getRequest()->getClientIp(); + + $event->getResponse()->headers->add($this->rateLimiter->getResponseHeaders($ip)); } } diff --git a/src/AppBundle/Security/RateLimiter.php b/src/AppBundle/Security/RateLimiter.php index 0ce8289..731edb6 100644 --- a/src/AppBundle/Security/RateLimiter.php +++ b/src/AppBundle/Security/RateLimiter.php @@ -25,9 +25,14 @@ public function getIpRequest(string $ip) return $this->updateAttempts($this->ipRequest); } - private function getRateLimitRemaining(): int + private function getRateLimitRemaining(string $ip): int { + if ($this->ipRequest === null) { + $this->getIpRequest($ip); + } + $rateLimitRemaining = static::MAX_ATTEMPTS - $this->ipRequest->countAccesses(); + if ($rateLimitRemaining < 0) { $rateLimitRemaining = 0; } @@ -48,11 +53,11 @@ private function getRateLimitReset(): int return $rateLimitReset; } - public function getResponseHeaders(): array + public function getResponseHeaders(string $ip): array { return [ 'X-RateLimit-Limit' => static::MAX_ATTEMPTS, - 'X-RateLimit-Remaining' => $this->getRateLimitRemaining(), + 'X-RateLimit-Remaining' => $this->getRateLimitRemaining($ip), 'X-RateLimit-Reset' => $this->getRateLimitReset(), ]; } diff --git a/tests/AppBundle/Listener/ResponseListenerTest.php b/tests/AppBundle/Listener/ResponseListenerTest.php index 2245c82..89070d0 100644 --- a/tests/AppBundle/Listener/ResponseListenerTest.php +++ b/tests/AppBundle/Listener/ResponseListenerTest.php @@ -11,6 +11,7 @@ use AppBundle\Listener\ResponseListener; use AppBundle\Security\RateLimiter; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; @@ -18,12 +19,18 @@ class ResponseListenerTest extends KernelTestCase { private function getEvent() { + $request = Request::create( + '/videos', + 'GET' + ); + $response = new Response(json_encode( ['data' => '123'] )); $event = $this->createMock(FilterResponseEvent::class); $event->expects($this->any())->method('getResponse')->willReturn($response); + $event->expects($this->any())->method('getRequest')->willReturn($request); $event->expects($this->once())->method('isMasterRequest')->willReturn(true); return $event; diff --git a/tests/AppBundle/Security/RateLimiterTest.php b/tests/AppBundle/Security/RateLimiterTest.php index d074a94..5e62b29 100644 --- a/tests/AppBundle/Security/RateLimiterTest.php +++ b/tests/AppBundle/Security/RateLimiterTest.php @@ -47,7 +47,7 @@ public function testGetHeader() $rateLimiter = new RateLimiter($this->em); $ipRequest = $rateLimiter->getIpRequest('127.0.0.1'); - $header = $rateLimiter->getResponseHeaders(); + $header = $rateLimiter->getResponseHeaders('127.0.0.1'); $this->assertEquals($header['X-RateLimit-Limit'], RateLimiter::MAX_ATTEMPTS); $this->assertEquals($header['X-RateLimit-Remaining'], RateLimiter::MAX_ATTEMPTS - $ipRequest->countAccesses()); From 1375479e7b9c1180a4adbc8da22a98f8475c6a92 Mon Sep 17 00:00:00 2001 From: mike1796 Date: Fri, 4 Aug 2017 15:31:02 +0200 Subject: [PATCH 4/5] Weird bug where Profile exists --- .../Version20170328203048.php | 73 - .../Version20170408125136.php | 39 - .../Version20170409141530.php | 35 - .../Version20170501132641.php | 41 - .../Version20170514145353.php | 35 - .../Version20170803183821.php | 130 -- ...25155608.php => Version20170804131111.php} | 284 ++-- app/config/security.yml | 4 +- app/config/services.yml | 6 +- features/Account.feature | 600 +------- features/Annotation.feature | 2 +- features/Category.feature | 2 +- features/Channel.feature | 42 +- features/Comment.feature | 10 +- features/Forum.feature | 10 +- features/Metadata.feature | 2 +- features/Network.feature | 20 +- features/Playlist.feature | 18 +- features/Profile.feature | 1248 ++++++++--------- features/Reply.feature | 10 +- features/Review.feature | 10 +- features/Seeder.feature | 10 +- features/Subtitles.feature | 2 +- features/SustainabilityOffer.feature | 10 +- features/Video.feature | 2 +- features/View.feature | 8 +- features/bootstrap/AccountHelper.php | 27 - features/bootstrap/ChannelHelper.php | 2 +- features/bootstrap/CommentHelper.php | 4 +- features/bootstrap/FeatureContext.php | 20 +- features/bootstrap/ForumHelper.php | 8 +- features/bootstrap/NetworkHelper.php | 4 +- features/bootstrap/PlaylistHelper.php | 9 +- features/bootstrap/ProfileHelper.php | 31 - features/bootstrap/ReplyHelper.php | 8 +- features/bootstrap/ReviewHelper.php | 8 +- features/bootstrap/SeederHelper.php | 6 +- features/bootstrap/UserAccountHelper.php | 31 + features/bootstrap/UserProfileHelper.php | 27 + features/bootstrap/ViewHelper.php | 6 +- .../DataFixtures/ORM/Fixtures/AccountData.php | 23 +- src/AppBundle/Entity/Channel.php | 8 +- src/AppBundle/Entity/Comment.php | 8 +- src/AppBundle/Entity/Forum.php | 6 +- src/AppBundle/Entity/Network.php | 2 +- src/AppBundle/Entity/OAuth/AccessToken.php | 2 +- src/AppBundle/Entity/OAuth/AuthCode.php | 2 +- src/AppBundle/Entity/OAuth/RefreshToken.php | 2 +- src/AppBundle/Entity/Playlist.php | 6 +- src/AppBundle/Entity/Reply.php | 8 +- src/AppBundle/Entity/Review.php | 8 +- src/AppBundle/Entity/Seeder.php | 8 +- src/AppBundle/Entity/SustainabilityOffer.php | 8 +- .../Entity/{Account.php => UserAccount.php} | 27 +- .../Entity/{Profile.php => UserProfile.php} | 37 +- src/AppBundle/Entity/View.php | 8 +- .../EventSubscriber/AccountChecker.php | 13 +- .../EventSubscriber/PasswordEncryption.php | 12 +- .../Repository/AccountRepository.php | 11 + .../Repository/ProfileRepository.php | 19 - src/AppBundle/Security/AccountProvider.php | 12 +- src/AppBundle/Security/AccountVoter.php | 17 +- .../Constraints/PlaylistClassValidator.php | 2 +- var/cache/.gitkeep | 0 64 files changed, 1116 insertions(+), 1977 deletions(-) delete mode 100644 app/DoctrineMigrations/Version20170328203048.php delete mode 100644 app/DoctrineMigrations/Version20170408125136.php delete mode 100644 app/DoctrineMigrations/Version20170409141530.php delete mode 100644 app/DoctrineMigrations/Version20170501132641.php delete mode 100644 app/DoctrineMigrations/Version20170514145353.php delete mode 100644 app/DoctrineMigrations/Version20170803183821.php rename app/DoctrineMigrations/{Version20170325155608.php => Version20170804131111.php} (61%) delete mode 100644 features/bootstrap/AccountHelper.php delete mode 100644 features/bootstrap/ProfileHelper.php create mode 100644 features/bootstrap/UserAccountHelper.php create mode 100644 features/bootstrap/UserProfileHelper.php rename src/AppBundle/Entity/{Account.php => UserAccount.php} (76%) rename src/AppBundle/Entity/{Profile.php => UserProfile.php} (85%) delete mode 100644 src/AppBundle/Repository/ProfileRepository.php delete mode 100644 var/cache/.gitkeep diff --git a/app/DoctrineMigrations/Version20170328203048.php b/app/DoctrineMigrations/Version20170328203048.php deleted file mode 100644 index 9ba74f6..0000000 --- a/app/DoctrineMigrations/Version20170328203048.php +++ /dev/null @@ -1,73 +0,0 @@ -abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('CREATE SEQUENCE refresh_token_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE client_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE access_token_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE auth_code_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE refresh_token (id INT NOT NULL, client_id INT NOT NULL, user_id INT DEFAULT NULL, token VARCHAR(255) NOT NULL, expires_at INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_C74F21955F37A13B ON refresh_token (token)'); - $this->addSql('CREATE INDEX IDX_C74F219519EB6921 ON refresh_token (client_id)'); - $this->addSql('CREATE INDEX IDX_C74F2195A76ED395 ON refresh_token (user_id)'); - $this->addSql('CREATE TABLE client (id INT NOT NULL, random_id VARCHAR(255) NOT NULL, redirect_uris TEXT NOT NULL, secret VARCHAR(255) NOT NULL, allowed_grant_types TEXT NOT NULL, PRIMARY KEY(id))'); - $this->addSql('COMMENT ON COLUMN client.redirect_uris IS \'(DC2Type:array)\''); - $this->addSql('COMMENT ON COLUMN client.allowed_grant_types IS \'(DC2Type:array)\''); - $this->addSql('CREATE TABLE access_token (id INT NOT NULL, client_id INT NOT NULL, user_id INT DEFAULT NULL, token VARCHAR(255) NOT NULL, expires_at INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_B6A2DD685F37A13B ON access_token (token)'); - $this->addSql('CREATE INDEX IDX_B6A2DD6819EB6921 ON access_token (client_id)'); - $this->addSql('CREATE INDEX IDX_B6A2DD68A76ED395 ON access_token (user_id)'); - $this->addSql('CREATE TABLE auth_code (id INT NOT NULL, client_id INT NOT NULL, user_id INT DEFAULT NULL, token VARCHAR(255) NOT NULL, redirect_uri TEXT NOT NULL, expires_at INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_5933D02C5F37A13B ON auth_code (token)'); - $this->addSql('CREATE INDEX IDX_5933D02C19EB6921 ON auth_code (client_id)'); - $this->addSql('CREATE INDEX IDX_5933D02CA76ED395 ON auth_code (user_id)'); - $this->addSql('ALTER TABLE refresh_token ADD CONSTRAINT FK_C74F219519EB6921 FOREIGN KEY (client_id) REFERENCES client (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE refresh_token ADD CONSTRAINT FK_C74F2195A76ED395 FOREIGN KEY (user_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE access_token ADD CONSTRAINT FK_B6A2DD6819EB6921 FOREIGN KEY (client_id) REFERENCES client (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE access_token ADD CONSTRAINT FK_B6A2DD68A76ED395 FOREIGN KEY (user_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE auth_code ADD CONSTRAINT FK_5933D02C19EB6921 FOREIGN KEY (client_id) REFERENCES client (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE auth_code ADD CONSTRAINT FK_5933D02CA76ED395 FOREIGN KEY (user_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE account ADD salt VARCHAR(255) NOT NULL'); - $this->addSql('ALTER TABLE account ADD password VARCHAR(255) NOT NULL'); - } - - /** - * @param Schema $schema - */ - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE refresh_token DROP CONSTRAINT FK_C74F219519EB6921'); - $this->addSql('ALTER TABLE access_token DROP CONSTRAINT FK_B6A2DD6819EB6921'); - $this->addSql('ALTER TABLE auth_code DROP CONSTRAINT FK_5933D02C19EB6921'); - $this->addSql('DROP SEQUENCE refresh_token_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE client_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE access_token_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE auth_code_id_seq CASCADE'); - $this->addSql('DROP TABLE refresh_token'); - $this->addSql('DROP TABLE client'); - $this->addSql('DROP TABLE access_token'); - $this->addSql('DROP TABLE auth_code'); - $this->addSql('ALTER TABLE account DROP salt'); - $this->addSql('ALTER TABLE account DROP password'); - } -} diff --git a/app/DoctrineMigrations/Version20170408125136.php b/app/DoctrineMigrations/Version20170408125136.php deleted file mode 100644 index 78b3c8d..0000000 --- a/app/DoctrineMigrations/Version20170408125136.php +++ /dev/null @@ -1,39 +0,0 @@ -abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('ALTER TABLE metadata DROP hash'); - $this->addSql('ALTER TABLE video ADD hash VARCHAR(255) NOT NULL'); - $this->addSql('ALTER TABLE video ADD magnet VARCHAR(255) NOT NULL'); - } - - /** - * @param Schema $schema - */ - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE metadata ADD hash VARCHAR(255) NOT NULL'); - $this->addSql('ALTER TABLE video DROP hash'); - $this->addSql('ALTER TABLE video DROP magnet'); - } -} diff --git a/app/DoctrineMigrations/Version20170409141530.php b/app/DoctrineMigrations/Version20170409141530.php deleted file mode 100644 index d6529c2..0000000 --- a/app/DoctrineMigrations/Version20170409141530.php +++ /dev/null @@ -1,35 +0,0 @@ -abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('ALTER TABLE ip_request RENAME COLUMN count TO accesses'); - } - - /** - * @param Schema $schema - */ - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE ip_request RENAME COLUMN accesses TO count'); - } -} diff --git a/app/DoctrineMigrations/Version20170501132641.php b/app/DoctrineMigrations/Version20170501132641.php deleted file mode 100644 index c67668f..0000000 --- a/app/DoctrineMigrations/Version20170501132641.php +++ /dev/null @@ -1,41 +0,0 @@ -abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('ALTER TABLE annotation ALTER begin_time TYPE INTEGER USING (to_char(begin_time, \'d\')::integer)'); - $this->addSql('ALTER TABLE annotation ALTER begin_time DROP DEFAULT'); - $this->addSql('ALTER TABLE annotation ALTER end_time TYPE integer USING (to_char(end_time, \'d\')::integer)'); - $this->addSql('ALTER TABLE annotation ALTER end_time DROP DEFAULT'); - } - - /** - * @param Schema $schema - */ - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE annotation ALTER begin_time TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); - $this->addSql('ALTER TABLE annotation ALTER begin_time DROP DEFAULT'); - $this->addSql('ALTER TABLE annotation ALTER end_time TYPE TIMESTAMP(0) WITHOUT TIME ZONE'); - $this->addSql('ALTER TABLE annotation ALTER end_time DROP DEFAULT'); - } -} diff --git a/app/DoctrineMigrations/Version20170514145353.php b/app/DoctrineMigrations/Version20170514145353.php deleted file mode 100644 index 544dd44..0000000 --- a/app/DoctrineMigrations/Version20170514145353.php +++ /dev/null @@ -1,35 +0,0 @@ -abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('ALTER TABLE ip_request RENAME COLUMN name TO ip'); - } - - /** - * @param Schema $schema - */ - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE ip_request RENAME COLUMN ip TO name'); - } -} diff --git a/app/DoctrineMigrations/Version20170803183821.php b/app/DoctrineMigrations/Version20170803183821.php deleted file mode 100644 index 515e17e..0000000 --- a/app/DoctrineMigrations/Version20170803183821.php +++ /dev/null @@ -1,130 +0,0 @@ -abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('CREATE SEQUENCE profile_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE profile (id INT NOT NULL, username VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_8157AA0FF85E0677 ON profile (username)'); - $this->addSql('CREATE TABLE network_profile (network_id INT NOT NULL, profile_id INT NOT NULL, PRIMARY KEY(network_id, profile_id))'); - $this->addSql('CREATE INDEX IDX_25E47D6534128B91 ON network_profile (network_id)'); - $this->addSql('CREATE INDEX IDX_25E47D65CCFA12B8 ON network_profile (profile_id)'); - $this->addSql('ALTER TABLE network_profile ADD CONSTRAINT FK_25E47D6534128B91 FOREIGN KEY (network_id) REFERENCES network (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE network_profile ADD CONSTRAINT FK_25E47D65CCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('DROP TABLE network_account'); - $this->addSql('ALTER TABLE view DROP CONSTRAINT fk_fefdab8e9b6b5fba'); - $this->addSql('DROP INDEX idx_fefdab8e9b6b5fba'); - $this->addSql('ALTER TABLE view RENAME COLUMN account_id TO profile_id'); - $this->addSql('ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8ECCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_FEFDAB8ECCFA12B8 ON view (profile_id)'); - $this->addSql('ALTER TABLE forum DROP CONSTRAINT FK_852BBECDB03A8386'); - $this->addSql('ALTER TABLE forum ADD CONSTRAINT FK_852BBECDB03A8386 FOREIGN KEY (created_by_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE comment DROP CONSTRAINT FK_9474526CF675F31B'); - $this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526CF675F31B FOREIGN KEY (author_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('DROP INDEX uniq_7d3656a4f85e0677'); - $this->addSql('ALTER TABLE account ADD profile_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE account DROP username'); - $this->addSql('ALTER TABLE account DROP first_name'); - $this->addSql('ALTER TABLE account DROP last_name'); - $this->addSql('ALTER TABLE account ADD CONSTRAINT FK_7D3656A4CCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_7D3656A4CCFA12B8 ON account (profile_id)'); - $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D9B6B5FBA'); - $this->addSql('ALTER TABLE playlist ADD CONSTRAINT FK_D782112D9B6B5FBA FOREIGN KEY (account_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE reply DROP CONSTRAINT FK_FDA8C6E0F675F31B'); - $this->addSql('ALTER TABLE reply ADD CONSTRAINT FK_FDA8C6E0F675F31B FOREIGN KEY (author_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE review DROP CONSTRAINT FK_794381C6F675F31B'); - $this->addSql('ALTER TABLE review ADD CONSTRAINT FK_794381C6F675F31B FOREIGN KEY (author_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE sustainability_offer DROP CONSTRAINT fk_bdc3df359b6b5fba'); - $this->addSql('DROP INDEX idx_bdc3df359b6b5fba'); - $this->addSql('ALTER TABLE sustainability_offer RENAME COLUMN account_id TO profile_id'); - $this->addSql('ALTER TABLE sustainability_offer ADD CONSTRAINT FK_BDC3DF35CCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_BDC3DF35CCFA12B8 ON sustainability_offer (profile_id)'); - $this->addSql('ALTER TABLE seeder DROP CONSTRAINT fk_8801cdce9b6b5fba'); - $this->addSql('DROP INDEX idx_8801cdce9b6b5fba'); - $this->addSql('ALTER TABLE seeder RENAME COLUMN account_id TO profile_id'); - $this->addSql('ALTER TABLE seeder ADD CONSTRAINT FK_8801CDCECCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_8801CDCECCFA12B8 ON seeder (profile_id)'); - $this->addSql('ALTER TABLE channel DROP CONSTRAINT fk_a2f98e479b6b5fba'); - $this->addSql('DROP INDEX idx_a2f98e479b6b5fba'); - $this->addSql('ALTER TABLE channel RENAME COLUMN account_id TO profile_id'); - $this->addSql('ALTER TABLE channel ADD CONSTRAINT FK_A2F98E47CCFA12B8 FOREIGN KEY (profile_id) REFERENCES profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_A2F98E47CCFA12B8 ON channel (profile_id)'); - } - - /** - * @param Schema $schema - */ - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE view DROP CONSTRAINT FK_FEFDAB8ECCFA12B8'); - $this->addSql('ALTER TABLE forum DROP CONSTRAINT FK_852BBECDB03A8386'); - $this->addSql('ALTER TABLE comment DROP CONSTRAINT FK_9474526CF675F31B'); - $this->addSql('ALTER TABLE account DROP CONSTRAINT FK_7D3656A4CCFA12B8'); - $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D9B6B5FBA'); - $this->addSql('ALTER TABLE reply DROP CONSTRAINT FK_FDA8C6E0F675F31B'); - $this->addSql('ALTER TABLE review DROP CONSTRAINT FK_794381C6F675F31B'); - $this->addSql('ALTER TABLE sustainability_offer DROP CONSTRAINT FK_BDC3DF35CCFA12B8'); - $this->addSql('ALTER TABLE seeder DROP CONSTRAINT FK_8801CDCECCFA12B8'); - $this->addSql('ALTER TABLE network_profile DROP CONSTRAINT FK_25E47D65CCFA12B8'); - $this->addSql('ALTER TABLE channel DROP CONSTRAINT FK_A2F98E47CCFA12B8'); - $this->addSql('DROP SEQUENCE profile_id_seq CASCADE'); - $this->addSql('CREATE TABLE network_account (network_id INT NOT NULL, account_id INT NOT NULL, PRIMARY KEY(network_id, account_id))'); - $this->addSql('CREATE INDEX idx_d98581ce9b6b5fba ON network_account (account_id)'); - $this->addSql('CREATE INDEX idx_d98581ce34128b91 ON network_account (network_id)'); - $this->addSql('ALTER TABLE network_account ADD CONSTRAINT fk_d98581ce34128b91 FOREIGN KEY (network_id) REFERENCES network (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE network_account ADD CONSTRAINT fk_d98581ce9b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('DROP TABLE profile'); - $this->addSql('DROP TABLE network_profile'); - $this->addSql('DROP INDEX IDX_FEFDAB8ECCFA12B8'); - $this->addSql('ALTER TABLE view RENAME COLUMN profile_id TO account_id'); - $this->addSql('ALTER TABLE view ADD CONSTRAINT fk_fefdab8e9b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX idx_fefdab8e9b6b5fba ON view (account_id)'); - $this->addSql('DROP INDEX IDX_8801CDCECCFA12B8'); - $this->addSql('ALTER TABLE seeder RENAME COLUMN profile_id TO account_id'); - $this->addSql('ALTER TABLE seeder ADD CONSTRAINT fk_8801cdce9b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX idx_8801cdce9b6b5fba ON seeder (account_id)'); - $this->addSql('DROP INDEX IDX_BDC3DF35CCFA12B8'); - $this->addSql('ALTER TABLE sustainability_offer RENAME COLUMN profile_id TO account_id'); - $this->addSql('ALTER TABLE sustainability_offer ADD CONSTRAINT fk_bdc3df359b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX idx_bdc3df359b6b5fba ON sustainability_offer (account_id)'); - $this->addSql('ALTER TABLE forum DROP CONSTRAINT fk_852bbecdb03a8386'); - $this->addSql('ALTER TABLE forum ADD CONSTRAINT fk_852bbecdb03a8386 FOREIGN KEY (created_by_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE review DROP CONSTRAINT fk_794381c6f675f31b'); - $this->addSql('ALTER TABLE review ADD CONSTRAINT fk_794381c6f675f31b FOREIGN KEY (author_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE reply DROP CONSTRAINT fk_fda8c6e0f675f31b'); - $this->addSql('ALTER TABLE reply ADD CONSTRAINT fk_fda8c6e0f675f31b FOREIGN KEY (author_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('DROP INDEX IDX_A2F98E47CCFA12B8'); - $this->addSql('ALTER TABLE channel RENAME COLUMN profile_id TO account_id'); - $this->addSql('ALTER TABLE channel ADD CONSTRAINT fk_a2f98e479b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX idx_a2f98e479b6b5fba ON channel (account_id)'); - $this->addSql('DROP INDEX UNIQ_7D3656A4CCFA12B8'); - $this->addSql('ALTER TABLE account ADD username VARCHAR(255) NOT NULL'); - $this->addSql('ALTER TABLE account ADD first_name VARCHAR(255) NOT NULL'); - $this->addSql('ALTER TABLE account ADD last_name VARCHAR(255) NOT NULL'); - $this->addSql('ALTER TABLE account DROP profile_id'); - $this->addSql('CREATE UNIQUE INDEX uniq_7d3656a4f85e0677 ON account (username)'); - $this->addSql('ALTER TABLE playlist DROP CONSTRAINT fk_d782112d9b6b5fba'); - $this->addSql('ALTER TABLE playlist ADD CONSTRAINT fk_d782112d9b6b5fba FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE comment DROP CONSTRAINT fk_9474526cf675f31b'); - $this->addSql('ALTER TABLE comment ADD CONSTRAINT fk_9474526cf675f31b FOREIGN KEY (author_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - } -} diff --git a/app/DoctrineMigrations/Version20170325155608.php b/app/DoctrineMigrations/Version20170804131111.php similarity index 61% rename from app/DoctrineMigrations/Version20170325155608.php rename to app/DoctrineMigrations/Version20170804131111.php index a43c84c..e6578b2 100644 --- a/app/DoctrineMigrations/Version20170325155608.php +++ b/app/DoctrineMigrations/Version20170804131111.php @@ -8,7 +8,7 @@ /** * Auto-generated Migration: Please modify to your needs! */ -class Version20170325155608 extends AbstractMigration +class Version20170804131111 extends AbstractMigration { /** * @param Schema $schema @@ -18,103 +18,132 @@ public function up(Schema $schema) // this up() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - $this->addSql('CREATE SEQUENCE account_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE network_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE view_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE seeder_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE metadata_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE forum_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE comment_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE playlist_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE reply_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE review_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE user_profile_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE sustainability_offer_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE subtitles_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE video_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE review_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE forum_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE user_account_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE seeder_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE annotation_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE network_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE auth_code_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE refresh_token_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE access_token_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE client_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE channel_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE subtitles_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE metadata_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE ip_request_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE reply_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE category_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE annotation_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE playlist_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE comment_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE account (id INT NOT NULL, username VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_7D3656A4F85E0677 ON account (username)'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_7D3656A4E7927C74 ON account (email)'); - $this->addSql('CREATE TABLE network (id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE TABLE network_account (network_id INT NOT NULL, account_id INT NOT NULL, PRIMARY KEY(network_id, account_id))'); - $this->addSql('CREATE INDEX IDX_D98581CE34128B91 ON network_account (network_id)'); - $this->addSql('CREATE INDEX IDX_D98581CE9B6B5FBA ON network_account (account_id)'); - $this->addSql('CREATE TABLE network_channel (network_id INT NOT NULL, channel_id INT NOT NULL, PRIMARY KEY(network_id, channel_id))'); - $this->addSql('CREATE INDEX IDX_64A592D34128B91 ON network_channel (network_id)'); - $this->addSql('CREATE INDEX IDX_64A592D72F5A1AA ON network_channel (channel_id)'); - $this->addSql('CREATE TABLE view (id INT NOT NULL, account_id INT DEFAULT NULL, video_id INT DEFAULT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_FEFDAB8E9B6B5FBA ON view (account_id)'); + $this->addSql('CREATE TABLE view (id INT NOT NULL, profile_id INT DEFAULT NULL, video_id INT DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_FEFDAB8ECCFA12B8 ON view (profile_id)'); $this->addSql('CREATE INDEX IDX_FEFDAB8E29C1004E ON view (video_id)'); - $this->addSql('CREATE TABLE seeder (id INT NOT NULL, account_id INT DEFAULT NULL, video_id INT DEFAULT NULL, platform VARCHAR(255) NOT NULL, ip VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_8801CDCE9B6B5FBA ON seeder (account_id)'); - $this->addSql('CREATE INDEX IDX_8801CDCE29C1004E ON seeder (video_id)'); - $this->addSql('CREATE TABLE metadata (id INT NOT NULL, height INT NOT NULL, width INT NOT NULL, format VARCHAR(255) NOT NULL, hash VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE TABLE sustainability_offer (id INT NOT NULL, account_id INT DEFAULT NULL, channel_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, duration INT NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_BDC3DF359B6B5FBA ON sustainability_offer (account_id)'); + $this->addSql('CREATE TABLE forum (id INT NOT NULL, video_id INT DEFAULT NULL, created_by_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_852BBECD29C1004E ON forum (video_id)'); + $this->addSql('CREATE INDEX IDX_852BBECDB03A8386 ON forum (created_by_id)'); + $this->addSql('CREATE TABLE comment (id INT NOT NULL, video_id INT DEFAULT NULL, author_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, date_comment TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_9474526C29C1004E ON comment (video_id)'); + $this->addSql('CREATE INDEX IDX_9474526CF675F31B ON comment (author_id)'); + $this->addSql('CREATE TABLE playlist (id INT NOT NULL, channel_id INT DEFAULT NULL, network_id INT DEFAULT NULL, account_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_D782112D72F5A1AA ON playlist (channel_id)'); + $this->addSql('CREATE INDEX IDX_D782112D34128B91 ON playlist (network_id)'); + $this->addSql('CREATE INDEX IDX_D782112D9B6B5FBA ON playlist (account_id)'); + $this->addSql('CREATE TABLE reply (id INT NOT NULL, review_id INT DEFAULT NULL, author_id INT DEFAULT NULL, contents VARCHAR(255) NOT NULL, date_comment TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_FDA8C6E03E2E969B ON reply (review_id)'); + $this->addSql('CREATE INDEX IDX_FDA8C6E0F675F31B ON reply (author_id)'); + $this->addSql('CREATE TABLE review (id INT NOT NULL, video_id INT DEFAULT NULL, author_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, date_comment TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_794381C629C1004E ON review (video_id)'); + $this->addSql('CREATE INDEX IDX_794381C6F675F31B ON review (author_id)'); + $this->addSql('CREATE TABLE user_profile (id INT NOT NULL, account_id INT NOT NULL, username VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_D95AB405F85E0677 ON user_profile (username)'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_D95AB4059B6B5FBA ON user_profile (account_id)'); + $this->addSql('CREATE TABLE sustainability_offer (id INT NOT NULL, profile_id INT DEFAULT NULL, channel_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, duration INT NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_BDC3DF35CCFA12B8 ON sustainability_offer (profile_id)'); $this->addSql('CREATE INDEX IDX_BDC3DF3572F5A1AA ON sustainability_offer (channel_id)'); - $this->addSql('CREATE TABLE subtitles (id INT NOT NULL, video_id INT DEFAULT NULL, begin_time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, end_time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, path VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_A739C98629C1004E ON subtitles (video_id)'); - $this->addSql('CREATE TABLE video (id INT NOT NULL, channel_id INT DEFAULT NULL, metadata_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, number_view INT DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE video (id INT NOT NULL, channel_id INT DEFAULT NULL, metadata_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, number_view INT DEFAULT NULL, hash VARCHAR(255) NOT NULL, magnet VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_7CC7DA2C72F5A1AA ON video (channel_id)'); $this->addSql('CREATE UNIQUE INDEX UNIQ_7CC7DA2CDC9EE959 ON video (metadata_id)'); $this->addSql('CREATE TABLE video_category (video_id INT NOT NULL, category_id INT NOT NULL, PRIMARY KEY(video_id, category_id))'); $this->addSql('CREATE INDEX IDX_AECE2B7D29C1004E ON video_category (video_id)'); $this->addSql('CREATE INDEX IDX_AECE2B7D12469DE2 ON video_category (category_id)'); - $this->addSql('CREATE TABLE review (id INT NOT NULL, video_id INT DEFAULT NULL, author_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, date_comment TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_794381C629C1004E ON review (video_id)'); - $this->addSql('CREATE INDEX IDX_794381C6F675F31B ON review (author_id)'); - $this->addSql('CREATE TABLE forum (id INT NOT NULL, video_id INT DEFAULT NULL, created_by_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_852BBECD29C1004E ON forum (video_id)'); - $this->addSql('CREATE INDEX IDX_852BBECDB03A8386 ON forum (created_by_id)'); - $this->addSql('CREATE TABLE channel (id INT NOT NULL, account_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, tags TEXT DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE user_account (id INT NOT NULL, email VARCHAR(255) NOT NULL, salt VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_253B48AEE7927C74 ON user_account (email)'); + $this->addSql('CREATE TABLE seeder (id INT NOT NULL, profile_id INT DEFAULT NULL, video_id INT DEFAULT NULL, platform VARCHAR(255) NOT NULL, ip VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_8801CDCECCFA12B8 ON seeder (profile_id)'); + $this->addSql('CREATE INDEX IDX_8801CDCE29C1004E ON seeder (video_id)'); + $this->addSql('CREATE TABLE annotation (id INT NOT NULL, video_id INT DEFAULT NULL, begin_time INT NOT NULL, end_time INT NOT NULL, annotation_text VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_2E443EF229C1004E ON annotation (video_id)'); + $this->addSql('CREATE TABLE network (id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE network_user_profile (network_id INT NOT NULL, user_profile_id INT NOT NULL, PRIMARY KEY(network_id, user_profile_id))'); + $this->addSql('CREATE INDEX IDX_BC28636D34128B91 ON network_user_profile (network_id)'); + $this->addSql('CREATE INDEX IDX_BC28636D6B9DD454 ON network_user_profile (user_profile_id)'); + $this->addSql('CREATE TABLE network_channel (network_id INT NOT NULL, channel_id INT NOT NULL, PRIMARY KEY(network_id, channel_id))'); + $this->addSql('CREATE INDEX IDX_64A592D34128B91 ON network_channel (network_id)'); + $this->addSql('CREATE INDEX IDX_64A592D72F5A1AA ON network_channel (channel_id)'); + $this->addSql('CREATE TABLE auth_code (id INT NOT NULL, client_id INT NOT NULL, user_id INT DEFAULT NULL, token VARCHAR(255) NOT NULL, redirect_uri TEXT NOT NULL, expires_at INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_5933D02C5F37A13B ON auth_code (token)'); + $this->addSql('CREATE INDEX IDX_5933D02C19EB6921 ON auth_code (client_id)'); + $this->addSql('CREATE INDEX IDX_5933D02CA76ED395 ON auth_code (user_id)'); + $this->addSql('CREATE TABLE refresh_token (id INT NOT NULL, client_id INT NOT NULL, user_id INT DEFAULT NULL, token VARCHAR(255) NOT NULL, expires_at INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_C74F21955F37A13B ON refresh_token (token)'); + $this->addSql('CREATE INDEX IDX_C74F219519EB6921 ON refresh_token (client_id)'); + $this->addSql('CREATE INDEX IDX_C74F2195A76ED395 ON refresh_token (user_id)'); + $this->addSql('CREATE TABLE access_token (id INT NOT NULL, client_id INT NOT NULL, user_id INT DEFAULT NULL, token VARCHAR(255) NOT NULL, expires_at INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_B6A2DD685F37A13B ON access_token (token)'); + $this->addSql('CREATE INDEX IDX_B6A2DD6819EB6921 ON access_token (client_id)'); + $this->addSql('CREATE INDEX IDX_B6A2DD68A76ED395 ON access_token (user_id)'); + $this->addSql('CREATE TABLE client (id INT NOT NULL, random_id VARCHAR(255) NOT NULL, redirect_uris TEXT NOT NULL, secret VARCHAR(255) NOT NULL, allowed_grant_types TEXT NOT NULL, PRIMARY KEY(id))'); + $this->addSql('COMMENT ON COLUMN client.redirect_uris IS \'(DC2Type:array)\''); + $this->addSql('COMMENT ON COLUMN client.allowed_grant_types IS \'(DC2Type:array)\''); + $this->addSql('CREATE TABLE channel (id INT NOT NULL, profile_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, tags TEXT DEFAULT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE UNIQUE INDEX UNIQ_A2F98E475E237E06 ON channel (name)'); - $this->addSql('CREATE INDEX IDX_A2F98E479B6B5FBA ON channel (account_id)'); + $this->addSql('CREATE INDEX IDX_A2F98E47CCFA12B8 ON channel (profile_id)'); $this->addSql('COMMENT ON COLUMN channel.tags IS \'(DC2Type:array)\''); - $this->addSql('CREATE TABLE ip_request (id INT NOT NULL, name VARCHAR(255) NOT NULL, date_request TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, count INT NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE TABLE reply (id INT NOT NULL, review_id INT DEFAULT NULL, author_id INT DEFAULT NULL, contents VARCHAR(255) NOT NULL, date_comment TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_FDA8C6E03E2E969B ON reply (review_id)'); - $this->addSql('CREATE INDEX IDX_FDA8C6E0F675F31B ON reply (author_id)'); + $this->addSql('CREATE TABLE subtitles (id INT NOT NULL, video_id INT DEFAULT NULL, begin_time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, end_time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, path VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_A739C98629C1004E ON subtitles (video_id)'); + $this->addSql('CREATE TABLE metadata (id INT NOT NULL, height INT NOT NULL, width INT NOT NULL, format VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE ip_request (id INT NOT NULL, ip VARCHAR(255) NOT NULL, date_request TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, accesses INT NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE TABLE category (id INT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE TABLE annotation (id INT NOT NULL, video_id INT DEFAULT NULL, begin_time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, end_time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, annotation_text VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_2E443EF229C1004E ON annotation (video_id)'); - $this->addSql('CREATE TABLE playlist (id INT NOT NULL, channel_id INT DEFAULT NULL, network_id INT DEFAULT NULL, account_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_D782112D72F5A1AA ON playlist (channel_id)'); - $this->addSql('CREATE INDEX IDX_D782112D34128B91 ON playlist (network_id)'); - $this->addSql('CREATE INDEX IDX_D782112D9B6B5FBA ON playlist (account_id)'); - $this->addSql('CREATE TABLE comment (id INT NOT NULL, video_id INT DEFAULT NULL, author_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, date_comment TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_9474526C29C1004E ON comment (video_id)'); - $this->addSql('CREATE INDEX IDX_9474526CF675F31B ON comment (author_id)'); - $this->addSql('ALTER TABLE network_account ADD CONSTRAINT FK_D98581CE34128B91 FOREIGN KEY (network_id) REFERENCES network (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE network_account ADD CONSTRAINT FK_D98581CE9B6B5FBA FOREIGN KEY (account_id) REFERENCES account (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE network_channel ADD CONSTRAINT FK_64A592D34128B91 FOREIGN KEY (network_id) REFERENCES network (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE network_channel ADD CONSTRAINT FK_64A592D72F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8E9B6B5FBA FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8ECCFA12B8 FOREIGN KEY (profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8E29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE seeder ADD CONSTRAINT FK_8801CDCE9B6B5FBA FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE seeder ADD CONSTRAINT FK_8801CDCE29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE sustainability_offer ADD CONSTRAINT FK_BDC3DF359B6B5FBA FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE forum ADD CONSTRAINT FK_852BBECD29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE forum ADD CONSTRAINT FK_852BBECDB03A8386 FOREIGN KEY (created_by_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526C29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526CF675F31B FOREIGN KEY (author_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE playlist ADD CONSTRAINT FK_D782112D72F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE playlist ADD CONSTRAINT FK_D782112D34128B91 FOREIGN KEY (network_id) REFERENCES network (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE playlist ADD CONSTRAINT FK_D782112D9B6B5FBA FOREIGN KEY (account_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE reply ADD CONSTRAINT FK_FDA8C6E03E2E969B FOREIGN KEY (review_id) REFERENCES review (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE reply ADD CONSTRAINT FK_FDA8C6E0F675F31B FOREIGN KEY (author_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE review ADD CONSTRAINT FK_794381C629C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE review ADD CONSTRAINT FK_794381C6F675F31B FOREIGN KEY (author_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE user_profile ADD CONSTRAINT FK_D95AB4059B6B5FBA FOREIGN KEY (account_id) REFERENCES user_account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE sustainability_offer ADD CONSTRAINT FK_BDC3DF35CCFA12B8 FOREIGN KEY (profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE sustainability_offer ADD CONSTRAINT FK_BDC3DF3572F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE subtitles ADD CONSTRAINT FK_A739C98629C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE video ADD CONSTRAINT FK_7CC7DA2C72F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE video ADD CONSTRAINT FK_7CC7DA2CDC9EE959 FOREIGN KEY (metadata_id) REFERENCES metadata (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE video_category ADD CONSTRAINT FK_AECE2B7D29C1004E FOREIGN KEY (video_id) REFERENCES video (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE video_category ADD CONSTRAINT FK_AECE2B7D12469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE review ADD CONSTRAINT FK_794381C629C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE review ADD CONSTRAINT FK_794381C6F675F31B FOREIGN KEY (author_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE forum ADD CONSTRAINT FK_852BBECD29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE forum ADD CONSTRAINT FK_852BBECDB03A8386 FOREIGN KEY (created_by_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE channel ADD CONSTRAINT FK_A2F98E479B6B5FBA FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE reply ADD CONSTRAINT FK_FDA8C6E03E2E969B FOREIGN KEY (review_id) REFERENCES review (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE reply ADD CONSTRAINT FK_FDA8C6E0F675F31B FOREIGN KEY (author_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE seeder ADD CONSTRAINT FK_8801CDCECCFA12B8 FOREIGN KEY (profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE seeder ADD CONSTRAINT FK_8801CDCE29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE annotation ADD CONSTRAINT FK_2E443EF229C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE playlist ADD CONSTRAINT FK_D782112D72F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE playlist ADD CONSTRAINT FK_D782112D34128B91 FOREIGN KEY (network_id) REFERENCES network (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE playlist ADD CONSTRAINT FK_D782112D9B6B5FBA FOREIGN KEY (account_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526C29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526CF675F31B FOREIGN KEY (author_id) REFERENCES account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE network_user_profile ADD CONSTRAINT FK_BC28636D34128B91 FOREIGN KEY (network_id) REFERENCES network (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE network_user_profile ADD CONSTRAINT FK_BC28636D6B9DD454 FOREIGN KEY (user_profile_id) REFERENCES user_profile (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE network_channel ADD CONSTRAINT FK_64A592D34128B91 FOREIGN KEY (network_id) REFERENCES network (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE network_channel ADD CONSTRAINT FK_64A592D72F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE auth_code ADD CONSTRAINT FK_5933D02C19EB6921 FOREIGN KEY (client_id) REFERENCES client (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE auth_code ADD CONSTRAINT FK_5933D02CA76ED395 FOREIGN KEY (user_id) REFERENCES user_account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE refresh_token ADD CONSTRAINT FK_C74F219519EB6921 FOREIGN KEY (client_id) REFERENCES client (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE refresh_token ADD CONSTRAINT FK_C74F2195A76ED395 FOREIGN KEY (user_id) REFERENCES user_account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE access_token ADD CONSTRAINT FK_B6A2DD6819EB6921 FOREIGN KEY (client_id) REFERENCES client (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE access_token ADD CONSTRAINT FK_B6A2DD68A76ED395 FOREIGN KEY (user_id) REFERENCES user_account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE channel ADD CONSTRAINT FK_A2F98E47CCFA12B8 FOREIGN KEY (profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE subtitles ADD CONSTRAINT FK_A739C98629C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); } /** @@ -126,70 +155,87 @@ public function down(Schema $schema) $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE network_account DROP CONSTRAINT FK_D98581CE9B6B5FBA'); - $this->addSql('ALTER TABLE view DROP CONSTRAINT FK_FEFDAB8E9B6B5FBA'); - $this->addSql('ALTER TABLE seeder DROP CONSTRAINT FK_8801CDCE9B6B5FBA'); - $this->addSql('ALTER TABLE sustainability_offer DROP CONSTRAINT FK_BDC3DF359B6B5FBA'); - $this->addSql('ALTER TABLE review DROP CONSTRAINT FK_794381C6F675F31B'); + $this->addSql('ALTER TABLE reply DROP CONSTRAINT FK_FDA8C6E03E2E969B'); + $this->addSql('ALTER TABLE view DROP CONSTRAINT FK_FEFDAB8ECCFA12B8'); $this->addSql('ALTER TABLE forum DROP CONSTRAINT FK_852BBECDB03A8386'); - $this->addSql('ALTER TABLE channel DROP CONSTRAINT FK_A2F98E479B6B5FBA'); - $this->addSql('ALTER TABLE reply DROP CONSTRAINT FK_FDA8C6E0F675F31B'); - $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D9B6B5FBA'); $this->addSql('ALTER TABLE comment DROP CONSTRAINT FK_9474526CF675F31B'); - $this->addSql('ALTER TABLE network_account DROP CONSTRAINT FK_D98581CE34128B91'); - $this->addSql('ALTER TABLE network_channel DROP CONSTRAINT FK_64A592D34128B91'); - $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D34128B91'); - $this->addSql('ALTER TABLE video DROP CONSTRAINT FK_7CC7DA2CDC9EE959'); + $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D9B6B5FBA'); + $this->addSql('ALTER TABLE reply DROP CONSTRAINT FK_FDA8C6E0F675F31B'); + $this->addSql('ALTER TABLE review DROP CONSTRAINT FK_794381C6F675F31B'); + $this->addSql('ALTER TABLE sustainability_offer DROP CONSTRAINT FK_BDC3DF35CCFA12B8'); + $this->addSql('ALTER TABLE seeder DROP CONSTRAINT FK_8801CDCECCFA12B8'); + $this->addSql('ALTER TABLE network_user_profile DROP CONSTRAINT FK_BC28636D6B9DD454'); + $this->addSql('ALTER TABLE channel DROP CONSTRAINT FK_A2F98E47CCFA12B8'); $this->addSql('ALTER TABLE view DROP CONSTRAINT FK_FEFDAB8E29C1004E'); - $this->addSql('ALTER TABLE seeder DROP CONSTRAINT FK_8801CDCE29C1004E'); - $this->addSql('ALTER TABLE subtitles DROP CONSTRAINT FK_A739C98629C1004E'); - $this->addSql('ALTER TABLE video_category DROP CONSTRAINT FK_AECE2B7D29C1004E'); - $this->addSql('ALTER TABLE review DROP CONSTRAINT FK_794381C629C1004E'); $this->addSql('ALTER TABLE forum DROP CONSTRAINT FK_852BBECD29C1004E'); - $this->addSql('ALTER TABLE annotation DROP CONSTRAINT FK_2E443EF229C1004E'); $this->addSql('ALTER TABLE comment DROP CONSTRAINT FK_9474526C29C1004E'); - $this->addSql('ALTER TABLE reply DROP CONSTRAINT FK_FDA8C6E03E2E969B'); - $this->addSql('ALTER TABLE network_channel DROP CONSTRAINT FK_64A592D72F5A1AA'); + $this->addSql('ALTER TABLE review DROP CONSTRAINT FK_794381C629C1004E'); + $this->addSql('ALTER TABLE video_category DROP CONSTRAINT FK_AECE2B7D29C1004E'); + $this->addSql('ALTER TABLE seeder DROP CONSTRAINT FK_8801CDCE29C1004E'); + $this->addSql('ALTER TABLE annotation DROP CONSTRAINT FK_2E443EF229C1004E'); + $this->addSql('ALTER TABLE subtitles DROP CONSTRAINT FK_A739C98629C1004E'); + $this->addSql('ALTER TABLE user_profile DROP CONSTRAINT FK_D95AB4059B6B5FBA'); + $this->addSql('ALTER TABLE auth_code DROP CONSTRAINT FK_5933D02CA76ED395'); + $this->addSql('ALTER TABLE refresh_token DROP CONSTRAINT FK_C74F2195A76ED395'); + $this->addSql('ALTER TABLE access_token DROP CONSTRAINT FK_B6A2DD68A76ED395'); + $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D34128B91'); + $this->addSql('ALTER TABLE network_user_profile DROP CONSTRAINT FK_BC28636D34128B91'); + $this->addSql('ALTER TABLE network_channel DROP CONSTRAINT FK_64A592D34128B91'); + $this->addSql('ALTER TABLE auth_code DROP CONSTRAINT FK_5933D02C19EB6921'); + $this->addSql('ALTER TABLE refresh_token DROP CONSTRAINT FK_C74F219519EB6921'); + $this->addSql('ALTER TABLE access_token DROP CONSTRAINT FK_B6A2DD6819EB6921'); + $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D72F5A1AA'); $this->addSql('ALTER TABLE sustainability_offer DROP CONSTRAINT FK_BDC3DF3572F5A1AA'); $this->addSql('ALTER TABLE video DROP CONSTRAINT FK_7CC7DA2C72F5A1AA'); - $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D72F5A1AA'); + $this->addSql('ALTER TABLE network_channel DROP CONSTRAINT FK_64A592D72F5A1AA'); + $this->addSql('ALTER TABLE video DROP CONSTRAINT FK_7CC7DA2CDC9EE959'); $this->addSql('ALTER TABLE video_category DROP CONSTRAINT FK_AECE2B7D12469DE2'); - $this->addSql('DROP SEQUENCE account_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE network_id_seq CASCADE'); $this->addSql('DROP SEQUENCE view_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE seeder_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE metadata_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE forum_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE comment_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE playlist_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE reply_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE review_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE user_profile_id_seq CASCADE'); $this->addSql('DROP SEQUENCE sustainability_offer_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE subtitles_id_seq CASCADE'); $this->addSql('DROP SEQUENCE video_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE review_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE forum_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE user_account_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE seeder_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE annotation_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE network_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE auth_code_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE refresh_token_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE access_token_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE client_id_seq CASCADE'); $this->addSql('DROP SEQUENCE channel_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE subtitles_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE metadata_id_seq CASCADE'); $this->addSql('DROP SEQUENCE ip_request_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE reply_id_seq CASCADE'); $this->addSql('DROP SEQUENCE category_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE annotation_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE playlist_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE comment_id_seq CASCADE'); - $this->addSql('DROP TABLE account'); - $this->addSql('DROP TABLE network'); - $this->addSql('DROP TABLE network_account'); - $this->addSql('DROP TABLE network_channel'); $this->addSql('DROP TABLE view'); - $this->addSql('DROP TABLE seeder'); - $this->addSql('DROP TABLE metadata'); + $this->addSql('DROP TABLE forum'); + $this->addSql('DROP TABLE comment'); + $this->addSql('DROP TABLE playlist'); + $this->addSql('DROP TABLE reply'); + $this->addSql('DROP TABLE review'); + $this->addSql('DROP TABLE user_profile'); $this->addSql('DROP TABLE sustainability_offer'); - $this->addSql('DROP TABLE subtitles'); $this->addSql('DROP TABLE video'); $this->addSql('DROP TABLE video_category'); - $this->addSql('DROP TABLE review'); - $this->addSql('DROP TABLE forum'); + $this->addSql('DROP TABLE user_account'); + $this->addSql('DROP TABLE seeder'); + $this->addSql('DROP TABLE annotation'); + $this->addSql('DROP TABLE network'); + $this->addSql('DROP TABLE network_user_profile'); + $this->addSql('DROP TABLE network_channel'); + $this->addSql('DROP TABLE auth_code'); + $this->addSql('DROP TABLE refresh_token'); + $this->addSql('DROP TABLE access_token'); + $this->addSql('DROP TABLE client'); $this->addSql('DROP TABLE channel'); + $this->addSql('DROP TABLE subtitles'); + $this->addSql('DROP TABLE metadata'); $this->addSql('DROP TABLE ip_request'); - $this->addSql('DROP TABLE reply'); $this->addSql('DROP TABLE category'); - $this->addSql('DROP TABLE annotation'); - $this->addSql('DROP TABLE playlist'); - $this->addSql('DROP TABLE comment'); } } diff --git a/app/config/security.yml b/app/config/security.yml index 5ba7d9c..5dea637 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -1,6 +1,6 @@ security: encoders: - AppBundle\Entity\Account: + AppBundle\Entity\UserAccount: algorithm: sha512 encode_as_base64: true iterations: 5000 @@ -8,7 +8,7 @@ security: providers: account_provider: entity: - class: AppBundle\Entity\Account + class: AppBundle\Entity\UserAccount firewalls: dev: diff --git a/app/config/services.yml b/app/config/services.yml index 16757e9..a56c112 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -21,13 +21,15 @@ services: arguments: [ "@doctrine.orm.entity_manager" ] app.security.account_voter: - class: AppBundle\Security\AccountVoter + class: AppBundle\Security\AccountVoter + tags: + - { name: security.voter, voter: access } app.event_subscriber.account_checker: class: AppBundle\EventSubscriber\AccountChecker arguments: [ "@security.authorization_checker" ] tags: - - { name: kernel.event_listener, event: kernel.view } + - { name: kernel.event_listener, event: kernel.request } app.event_subscriber.password_encryption: class: AppBundle\EventSubscriber\PasswordEncryption diff --git a/features/Account.feature b/features/Account.feature index f3949c8..0cc7bfb 100644 --- a/features/Account.feature +++ b/features/Account.feature @@ -5,7 +5,7 @@ Feature: Manage account I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" @refreshSchema @requiresOAuth @@ -15,10 +15,7 @@ Feature: Manage account And I send a "POST" request to "/accounts" with body: """ { - "username": "string", "email": "string@string.fr", - "firstName": "string", - "lastName": "string", "password": "password", "salt": "salt" } @@ -29,114 +26,18 @@ Feature: Manage account And the JSON should be equal to: """ { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "string", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [], - "views": [], - "forums": [], - "networks": [], - "playlists": [], - "replies": [], - "reviews": [], - "sustainabilityOffers": [], - "seeders": [] - } - """ - - Scenario: Retrieve the account list - When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts" - Then the response status code should be 200 - And the response should be in JSON - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON should be equal to: - """ - { - "@context": "/contexts/Account", - "@id": "/accounts", - "@type": "hydra:Collection", - "hydra:member": [ - { - "@id": "/accounts/1", - "@type": "Account", - "id": 1, - "username": "denis", - "email": "denis@denis.fr", - "firstName": "denis", - "lastName": "denis", - "channels": [], - "views": [], - "forums": [], - "networks": [], - "playlists": [], - "replies": [], - "reviews": [], - "sustainabilityOffers": [], - "seeders": [] - }, - { - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "string", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [], - "views": [], - "forums": [], - "networks": [], - "playlists": [], - "replies": [], - "reviews": [], - "sustainabilityOffers": [], - "seeders": [] - } - ], - "hydra:totalItems": 2, - "hydra:search": { - "@type": "hydra:IriTemplate", - "hydra:template": "/accounts{?id,id[],username,email,firstName}", - "hydra:variableRepresentation": "BasicRepresentation", - "hydra:mapping": [ - { - "@type": "IriTemplateMapping", - "variable": "id", - "property": "id", - "required": false - }, - { - "@type": "IriTemplateMapping", - "variable": "id[]", - "property": "id", - "required": false - }, - { - "@type": "IriTemplateMapping", - "variable": "username", - "property": "username", - "required": false - }, - { - "@type": "IriTemplateMapping", - "variable": "email", - "property": "email", - "required": false - }, - { - "@type": "IriTemplateMapping", - "variable": "firstName", - "property": "firstName", - "required": false - } - ] - } + "@context": "/contexts/Account", + "@id": "/accounts/2", + "@type": "Account", + "username": "string@string.fr", + "email": "string@string.fr", + "salt": "salt", + "roles": [ + "ROLE_USER" + ], + "password": "password", + "id": 2, + "profile": "/profiles/2" } """ @@ -146,7 +47,6 @@ Feature: Manage account And I send a "POST" request to "/accounts" with body: """ { - "email": "string" } """ Then the response status code should be 400 @@ -158,22 +58,10 @@ Feature: Manage account "@context": "/contexts/ConstraintViolationList", "@type": "ConstraintViolationList", "hydra:title": "An error occurred", - "hydra:description": "username: This value should not be blank.\nemail: This value is not a valid email address.\nfirstName: This value should not be blank.\nlastName: This value should not be blank.\nsalt: This value should not be blank.\npassword: This value should not be blank.", + "hydra:description": "email: This value should not be blank.\nsalt: This value should not be blank.\npassword: This value should not be blank.", "violations": [ - { - "propertyPath": "username", - "message": "This value should not be blank." - }, { "propertyPath": "email", - "message": "This value is not a valid email address." - }, - { - "propertyPath": "firstName", - "message": "This value should not be blank." - }, - { - "propertyPath": "lastName", "message": "This value should not be blank." }, { @@ -188,143 +76,43 @@ Feature: Manage account } """ - Scenario: Update an account - When I add "Content-Type" header equal to "application/ld+json" - And I add "Accept" header equal to "application/ld+json" - And I send a "PUT" request to "/accounts/2" with body: - """ - { - "username": "stringUpdated" - } - """ - Then the response status code should be 200 - And the response should be in JSON - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON should be equal to: - """ - { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [], - "views": [], - "forums": [], - "networks": [], - "playlists": [], - "replies": [], - "reviews": [], - "sustainabilityOffers": [], - "seeders": [] - } - """ - - Scenario: Get a specific account + Scenario: Get his own account When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/2" + And I send a "GET" request to "/accounts/1" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [], - "views": [], - "forums": [], - "networks": [], - "playlists": [], - "replies": [], - "reviews": [], - "sustainabilityOffers": [], - "seeders": [] + "@context": "/contexts/Account", + "@id": "/accounts/1", + "@type": "Account", + "username": "", + "email": "denis@denis.fr", + "salt": "salt", + "roles": [ + "ROLE_USER" + ], + "password": "password", + "id": 2, + "profile": "/profiles/1" } """ - Scenario: See channel in account - Given There are "channel" "/channels/1,/channels/2" which have "account" "/accounts/2" + Scenario: Get another account When I add "Accept" header equal to "application/ld+json" And I send a "GET" request to "/accounts/2" - Then the response status code should be 200 - And the response should be in JSON - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON should be equal to: - """ - { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [ - "/channels/1", - "/channels/2" - ], - "views": [], - "forums": [], - "networks": [], - "playlists": [], - "replies": [], - "reviews": [], - "sustainabilityOffers": [], - "seeders": [] - } - """ + Then the response status code should be 403 - Scenario: See view in account - Given There are "view" "/views/1,/views/2" which have "account" "/accounts/2" - When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/2" - Then the response status code should be 200 - And the response should be in JSON - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON should be equal to: + Scenario: Update his account + When I add "Content-Type" header equal to "application/ld+json" + And I add "Accept" header equal to "application/ld+json" + And I send a "PUT" request to "/accounts/1" with body: """ { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [ - "/channels/1", - "/channels/2" - ], - "views": [ - "/views/1", - "/views/2" - ], - "forums": [], - "networks": [], - "playlists": [], - "replies": [], - "reviews": [], - "sustainabilityOffers": [], - "seeders": [] } """ - - Scenario: See forum in account - Given There are "forum" "/forums/1,/forums/2" which have "account" "/accounts/2" - When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" @@ -339,18 +127,9 @@ Feature: Manage account "email": "string@string.fr", "firstName": "string", "lastName": "string", - "channels": [ - "/channels/1", - "/channels/2" - ], - "views": [ - "/views/1", - "/views/2" - ], - "forums": [ - "/forums/1", - "/forums/2" - ], + "channels": [], + "views": [], + "forums": [], "networks": [], "playlists": [], "replies": [], @@ -360,311 +139,20 @@ Feature: Manage account } """ - Scenario: See network in account - Given There are "network" "/networks/1,/networks/2" which have "account" "/accounts/2" - When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/2" - Then the response status code should be 200 - And the response should be in JSON - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON should be equal to: - """ - { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [ - "/channels/1", - "/channels/2" - ], - "views": [ - "/views/1", - "/views/2" - ], - "forums": [ - "/forums/1", - "/forums/2" - ], - "networks": [ - "/networks/1", - "/networks/2" - ], - "playlists": [], - "replies": [], - "reviews": [], - "sustainabilityOffers": [], - "seeders": [] - } - """ - - Scenario: See review in account - Given There are "review" "/reviews/1,/reviews/2" which have "account" "/accounts/2" - When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/2" - Then the response status code should be 200 - And the response should be in JSON - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON should be equal to: - """ - { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [ - "/channels/1", - "/channels/2" - ], - "views": [ - "/views/1", - "/views/2" - ], - "forums": [ - "/forums/1", - "/forums/2" - ], - "networks": [ - "/networks/1", - "/networks/2" - ], - "playlists": [], - "replies": [], - "reviews": [ - "/reviews/1", - "/reviews/2" - ], - "sustainabilityOffers": [], - "seeders": [] - } - """ - - Scenario: See reply in account - Given There are "reply" "/replies/1,/replies/2" which have "account" "/accounts/1,/accounts/2" - When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/2" - Then the response status code should be 200 - And the response should be in JSON - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON should be equal to: - """ - { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [ - "/channels/1", - "/channels/2" - ], - "views": [ - "/views/1", - "/views/2" - ], - "forums": [ - "/forums/1", - "/forums/2" - ], - "networks": [ - "/networks/1", - "/networks/2" - ], - "playlists": [], - "replies": [ - "/replies/1", - "/replies/2" - ], - "reviews": [ - "/reviews/1", - "/reviews/2" - ], - "sustainabilityOffers": [], - "seeders": [] - } - """ - - Scenario: See Sustainability Offers in account - Given There are "sustainability offer" "/sustainability_offers/1,/sustainability_offers/2" which have "account" "/accounts/2" - When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/2" - Then the response status code should be 200 - And the response should be in JSON - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON should be equal to: - """ - { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [ - "/channels/1", - "/channels/2" - ], - "views": [ - "/views/1", - "/views/2" - ], - "forums": [ - "/forums/1", - "/forums/2" - ], - "networks": [ - "/networks/1", - "/networks/2" - ], - "playlists": [], - "replies": [ - "/replies/1", - "/replies/2" - ], - "reviews": [ - "/reviews/1", - "/reviews/2" - ], - "sustainabilityOffers": [ - "/sustainability_offers/1", - "/sustainability_offers/2" - ], - "seeders": [] - } - """ - - Scenario: See seeder in account - Given There are "seeder" "/seeders/1,/seeders/2" which have "account" "/accounts/2" - When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/2" - Then the response status code should be 200 - And the response should be in JSON - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON should be equal to: + Scenario: Update another account + When I add "Content-Type" header equal to "application/ld+json" + And I add "Accept" header equal to "application/ld+json" + And I send a "PUT" request to "/accounts/2" with body: """ { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [ - "/channels/1", - "/channels/2" - ], - "views": [ - "/views/1", - "/views/2" - ], - "forums": [ - "/forums/1", - "/forums/2" - ], - "networks": [ - "/networks/1", - "/networks/2" - ], - "playlists": [], - "replies": [ - "/replies/1", - "/replies/2" - ], - "reviews": [ - "/reviews/1", - "/reviews/2" - ], - "sustainabilityOffers": [ - "/sustainability_offers/1", - "/sustainability_offers/2" - ], - "seeders": [ - "/seeders/1", - "/seeders/2" - ] - } - """ - - Scenario: See playlist in account - Given There are "playlist" "/playlists/1,/playlist/2" which have "account" "/accounts/2" - When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/2" - Then the response status code should be 200 - And the response should be in JSON - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" - And the JSON should be equal to: - """ - { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [ - "/channels/1", - "/channels/2" - ], - "views": [ - "/views/1", - "/views/2" - ], - "forums": [ - "/forums/1", - "/forums/2" - ], - "networks": [ - "/networks/1", - "/networks/2" - ], - "playlists": [ - "/playlists/1", - "/playlists/2" - ], - "replies": [ - "/replies/1", - "/replies/2" - ], - "reviews": [ - "/reviews/1", - "/reviews/2" - ], - "sustainabilityOffers": [ - "/sustainability_offers/1", - "/sustainability_offers/2" - ], - "seeders": [ - "/seeders/1", - "/seeders/2" - ] + "username": "stringUpdated" } """ + Then the response status code should be 403 - Scenario: Delete an account - When I add "Content-Type" header equal to "application/ld+json" - And I add "Accept" header equal to "application/ld+json" - And I send a "DELETE" request to "/accounts/2" - Then the response status code should be 204 Scenario: Delete an account When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" And I send a "DELETE" request to "/accounts/2" - Then the response status code should be 404 + Then the response status code should be 403 diff --git a/features/Annotation.feature b/features/Annotation.feature index 6b6ecf6..ff3fed3 100644 --- a/features/Annotation.feature +++ b/features/Annotation.feature @@ -5,7 +5,7 @@ Feature: Manage annotation I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "video" "/videos/1,/videos/2" @refreshSchema diff --git a/features/Category.feature b/features/Category.feature index 1e9a99b..1ec116c 100644 --- a/features/Category.feature +++ b/features/Category.feature @@ -5,7 +5,7 @@ Feature: Manage category I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" @refreshSchema @requiresOAuth diff --git a/features/Channel.feature b/features/Channel.feature index 6c13c21..34f22b6 100644 --- a/features/Channel.feature +++ b/features/Channel.feature @@ -5,8 +5,8 @@ Feature: Manage channel I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" - And There are "account" "/accounts/2" + Given I am connected as "denis@denis.fr" with password "password" + And There are "profile" "/profiles/2" @refreshSchema @requiresOAuth @@ -16,7 +16,7 @@ Feature: Manage channel And I send a "POST" request to "/channels" with body: """ { - "account": "/accounts/2", + "profile": "/profiles/2", "name": "string", "tags": [ "string" @@ -32,7 +32,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "account": "/accounts/2", + "profile": "/profiles/2", "id": 1, "name": "string", "tags": [ @@ -88,7 +88,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "account": "/accounts/2", + "profile": "/profiles/2", "id": 1, "name": "string", "tags": [ @@ -116,7 +116,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "account": "/accounts/2", + "profile": "/profiles/2", "id": 1, "name": "string", "tags": [ @@ -147,7 +147,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "account": "/accounts/2", + "profile": "/profiles/2", "id": 1, "name": "string", "tags": [ @@ -184,7 +184,7 @@ Feature: Manage channel { "@id": "/channels/1", "@type": "Channel", - "account": "/accounts/2", + "profile": "/profiles/2", "id": 1, "name": "string", "tags": [ @@ -206,7 +206,7 @@ Feature: Manage channel { "@id": "/channels/2", "@type": "Channel", - "account": "/accounts/3", + "profile": "/profiles/3", "id": 2, "name": "string18", "tags": [ @@ -220,7 +220,7 @@ Feature: Manage channel { "@id": "/channels/3", "@type": "Channel", - "account": "/accounts/4", + "profile": "/profiles/4", "id": 3, "name": "string19", "tags": [ @@ -234,7 +234,7 @@ Feature: Manage channel { "@id": "/channels/4", "@type": "Channel", - "account": "/accounts/5", + "profile": "/profiles/5", "id": 4, "name": "string20", "tags": [ @@ -249,7 +249,7 @@ Feature: Manage channel "hydra:totalItems": 4, "hydra:search": { "@type": "hydra:IriTemplate", - "hydra:template": "/channels{?id,id[],name,account,account[]}", + "hydra:template": "/channels{?id,id[],name}", "hydra:variableRepresentation": "BasicRepresentation", "hydra:mapping": [ { @@ -269,18 +269,6 @@ Feature: Manage channel "variable": "name", "property": "name", "required": false - }, - { - "@type": "IriTemplateMapping", - "variable": "account", - "property": "account", - "required": false - }, - { - "@type": "IriTemplateMapping", - "variable": "account[]", - "property": "account", - "required": false } ] } @@ -305,7 +293,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "account": "/accounts/2", + "profile": "/profiles/2", "id": 1, "name": "stringUpdated", "tags": [ @@ -349,7 +337,7 @@ Feature: Manage channel "name": "string", "channel": "/channels/1", "network": null, - "account": null + "profile": null } """ @@ -366,7 +354,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "account": "/accounts/2", + "profile": "/profiles/2", "id": 1, "name": "stringUpdated", "tags": [ diff --git a/features/Comment.feature b/features/Comment.feature index 780c427..2a31fbd 100644 --- a/features/Comment.feature +++ b/features/Comment.feature @@ -5,7 +5,7 @@ Feature: Manage comment I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "video" "/videos/1" @refreshSchema @@ -19,7 +19,7 @@ Feature: Manage comment "content": "string", "dateComment": "2017-02-03T08:56:37.848Z", "video": "/videos/1", - "author": "/accounts/1" + "author": "/profiles/1" } """ Then the response status code should be 201 @@ -35,7 +35,7 @@ Feature: Manage comment "content": "string", "dateComment": "2017-02-03T08:56:37+00:00", "video": "/videos/1", - "author": "/accounts/1" + "author": "/profiles/1" } """ @@ -91,7 +91,7 @@ Feature: Manage comment "content": "string", "dateComment": "2017-02-03T08:56:37+01:00", "video": "/videos/1", - "author": "/accounts/1" + "author": "/profiles/1" } ], "hydra:totalItems": 1 @@ -120,7 +120,7 @@ Feature: Manage comment "content": "stringUpdated", "dateComment": "2017-02-03T08:56:37+01:00", "video": "/videos/1", - "author": "/accounts/1" + "author": "/profiles/1" } """ diff --git a/features/Forum.feature b/features/Forum.feature index 3982b30..0364f80 100644 --- a/features/Forum.feature +++ b/features/Forum.feature @@ -5,7 +5,7 @@ Feature: Manage forum I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "video" "/videos/1" @refreshSchema @@ -18,7 +18,7 @@ Feature: Manage forum { "name": "string", "video": "/videos/1", - "createdBy": "/accounts/1" + "createdBy": "/profiles/1" } """ Then the response status code should be 201 @@ -33,7 +33,7 @@ Feature: Manage forum "id": 1, "name": "string", "video": "/videos/1", - "createdBy": "/accounts/1" + "createdBy": "/profiles/1" } """ @@ -84,7 +84,7 @@ Feature: Manage forum "id": 1, "name": "string", "video": "/videos/1", - "createdBy": "/accounts/1" + "createdBy": "/profiles/1" } ], "hydra:totalItems": 1 @@ -112,7 +112,7 @@ Feature: Manage forum "id": 1, "name": "stringUpdated", "video": "/videos/1", - "createdBy": "/accounts/1" + "createdBy": "/profiles/1" } """ diff --git a/features/Metadata.feature b/features/Metadata.feature index 946a44c..6bff9e2 100644 --- a/features/Metadata.feature +++ b/features/Metadata.feature @@ -5,7 +5,7 @@ Feature: Manage metadata I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" @refreshSchema @requiresOAuth diff --git a/features/Network.feature b/features/Network.feature index c54ec2a..5a0fee3 100644 --- a/features/Network.feature +++ b/features/Network.feature @@ -5,7 +5,7 @@ Feature: Manage network I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "channel" "/channels/1" @refreshSchema @@ -38,15 +38,15 @@ Feature: Manage network """ Scenario: Put a user - Given There are "account" "/accounts/1,/accounts/2" + Given There are "profile" "/profiles/1,/profiles/2" When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" And I send a "PUT" request to "/networks/1" with body: """ { "peoples": [ - "/accounts/1", - "/accounts/2" + "/profiles/1", + "/profiles/2" ] } """ @@ -63,8 +63,8 @@ Feature: Manage network "channels": [ "/channels/1" ], "name": "string", "peoples": [ - "/accounts/1", - "/accounts/2" + "/profiles/1", + "/profiles/2" ], "playlists": [] } @@ -90,8 +90,8 @@ Feature: Manage network "channels": [ "/channels/1" ], "name": "string", "peoples": [ - "/accounts/1", - "/accounts/2" + "/profiles/1", + "/profiles/2" ], "playlists": [] } @@ -117,8 +117,8 @@ Feature: Manage network "channels": [ "/channels/1" ], "name": "string", "peoples": [ - "/accounts/1", - "/accounts/2" + "/profiles/1", + "/profiles/2" ], "playlists": [ "/playlists/1", diff --git a/features/Playlist.feature b/features/Playlist.feature index a8ebce0..8f12dd9 100644 --- a/features/Playlist.feature +++ b/features/Playlist.feature @@ -5,8 +5,8 @@ Feature: Manage playlist I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" - And There are "account" "/accounts/2" + Given I am connected as "denis@denis.fr" with password "password" + And There are "profile" "/profiles/2" @refreshSchema @requiresOAuth @@ -17,7 +17,7 @@ Feature: Manage playlist """ { "name": "string", - "account": "/accounts/1" + "profile": "/profiles/1" } """ Then the response status code should be 201 @@ -33,7 +33,7 @@ Feature: Manage playlist "name": "string", "channel": null, "network": null, - "account": "/accounts/1" + "profile": "/profiles/1" } """ @@ -57,7 +57,7 @@ Feature: Manage playlist "name": "string", "channel": null, "network": null, - "account": "/accounts/1" + "profile": "/profiles/1" } ], "hydra:totalItems": 1 @@ -86,7 +86,7 @@ Feature: Manage playlist "name": "stringUpdated", "channel": null, "network": null, - "account": "/accounts/1" + "profile": "/profiles/1" } """ @@ -114,7 +114,7 @@ Feature: Manage playlist "name": "string", "channel": "/channels/1", "network": null, - "account": null + "profile": null } """ @@ -142,7 +142,7 @@ Feature: Manage playlist "name": "string", "channel": null, "network": "/networks/1", - "account": null + "profile": null } """ @@ -153,7 +153,7 @@ Feature: Manage playlist """ { "channel": "/channels/1", - "account": "/accounts/1" + "profile": "/profiles/1" } """ Then the response status code should be 400 diff --git a/features/Profile.feature b/features/Profile.feature index aba1209..c4ff800 100644 --- a/features/Profile.feature +++ b/features/Profile.feature @@ -5,7 +5,7 @@ Feature: Manage Profile I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" @refreshSchema @requiresOAuth @@ -20,648 +20,618 @@ Feature: Manage Profile "lastName": "string" } """ - Then the response status code should be 401 + Then the response status code should be 201 And the response should be in JSON - And the header "Content-Type" should be equal to "application/json" + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "string", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [], - "views": [], - "forums": [], - "networks": [], - "playlists": [], - "replies": [], - "reviews": [], - "sustainabilityOffers": [], - "seeders": [] + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "string", + "channels": [], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" } """ -# Scenario: Retrieve the account list -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts", -# "@type": "hydra:Collection", -# "hydra:member": [ -# { -# "@id": "/accounts/1", -# "@type": "Account", -# "id": 1, -# "username": "denis", -# "email": "denis@denis.fr", -# "firstName": "denis", -# "lastName": "denis", -# "channels": [], -# "views": [], -# "forums": [], -# "networks": [], -# "playlists": [], -# "replies": [], -# "reviews": [], -# "sustainabilityOffers": [], -# "seeders": [] -# }, -# { -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "string", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [], -# "views": [], -# "forums": [], -# "networks": [], -# "playlists": [], -# "replies": [], -# "reviews": [], -# "sustainabilityOffers": [], -# "seeders": [] -# } -# ], -# "hydra:totalItems": 2, -# "hydra:search": { -# "@type": "hydra:IriTemplate", -# "hydra:template": "/accounts{?id,id[],username,email,firstName}", -# "hydra:variableRepresentation": "BasicRepresentation", -# "hydra:mapping": [ -# { -# "@type": "IriTemplateMapping", -# "variable": "id", -# "property": "id", -# "required": false -# }, -# { -# "@type": "IriTemplateMapping", -# "variable": "id[]", -# "property": "id", -# "required": false -# }, -# { -# "@type": "IriTemplateMapping", -# "variable": "username", -# "property": "username", -# "required": false -# }, -# { -# "@type": "IriTemplateMapping", -# "variable": "email", -# "property": "email", -# "required": false -# }, -# { -# "@type": "IriTemplateMapping", -# "variable": "firstName", -# "property": "firstName", -# "required": false -# } -# ] -# } -# } -# """ -# -# Scenario: Throw errors when there is only bad properties -# When I add "Content-Type" header equal to "application/ld+json" -# And I add "Accept" header equal to "application/ld+json" -# And I send a "POST" request to "/accounts" with body: -# """ -# { -# "email": "string" -# } -# """ -# Then the response status code should be 400 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/ConstraintViolationList", -# "@type": "ConstraintViolationList", -# "hydra:title": "An error occurred", -# "hydra:description": "username: This value should not be blank.\nemail: This value is not a valid email address.\nfirstName: This value should not be blank.\nlastName: This value should not be blank.\nsalt: This value should not be blank.\npassword: This value should not be blank.", -# "violations": [ -# { -# "propertyPath": "username", -# "message": "This value should not be blank." -# }, -# { -# "propertyPath": "email", -# "message": "This value is not a valid email address." -# }, -# { -# "propertyPath": "firstName", -# "message": "This value should not be blank." -# }, -# { -# "propertyPath": "lastName", -# "message": "This value should not be blank." -# }, -# { -# "propertyPath": "salt", -# "message": "This value should not be blank." -# }, -# { -# "propertyPath": "password", -# "message": "This value should not be blank." -# } -# ] -# } -# """ -# -# Scenario: Update an account -# When I add "Content-Type" header equal to "application/ld+json" -# And I add "Accept" header equal to "application/ld+json" -# And I send a "PUT" request to "/accounts/2" with body: -# """ -# { -# "username": "stringUpdated" -# } -# """ -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [], -# "views": [], -# "forums": [], -# "networks": [], -# "playlists": [], -# "replies": [], -# "reviews": [], -# "sustainabilityOffers": [], -# "seeders": [] -# } -# """ -# -# Scenario: Get a specific account -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts/2" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [], -# "views": [], -# "forums": [], -# "networks": [], -# "playlists": [], -# "replies": [], -# "reviews": [], -# "sustainabilityOffers": [], -# "seeders": [] -# } -# """ -# -# Scenario: See channel in account -# Given There are "channel" "/channels/1,/channels/2" which have "account" "/accounts/2" -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts/2" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [ -# "/channels/1", -# "/channels/2" -# ], -# "views": [], -# "forums": [], -# "networks": [], -# "playlists": [], -# "replies": [], -# "reviews": [], -# "sustainabilityOffers": [], -# "seeders": [] -# } -# """ -# -# Scenario: See view in account -# Given There are "view" "/views/1,/views/2" which have "account" "/accounts/2" -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts/2" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [ -# "/channels/1", -# "/channels/2" -# ], -# "views": [ -# "/views/1", -# "/views/2" -# ], -# "forums": [], -# "networks": [], -# "playlists": [], -# "replies": [], -# "reviews": [], -# "sustainabilityOffers": [], -# "seeders": [] -# } -# """ -# -# Scenario: See forum in account -# Given There are "forum" "/forums/1,/forums/2" which have "account" "/accounts/2" -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts/2" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [ -# "/channels/1", -# "/channels/2" -# ], -# "views": [ -# "/views/1", -# "/views/2" -# ], -# "forums": [ -# "/forums/1", -# "/forums/2" -# ], -# "networks": [], -# "playlists": [], -# "replies": [], -# "reviews": [], -# "sustainabilityOffers": [], -# "seeders": [] -# } -# """ -# -# Scenario: See network in account -# Given There are "network" "/networks/1,/networks/2" which have "account" "/accounts/2" -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts/2" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [ -# "/channels/1", -# "/channels/2" -# ], -# "views": [ -# "/views/1", -# "/views/2" -# ], -# "forums": [ -# "/forums/1", -# "/forums/2" -# ], -# "networks": [ -# "/networks/1", -# "/networks/2" -# ], -# "playlists": [], -# "replies": [], -# "reviews": [], -# "sustainabilityOffers": [], -# "seeders": [] -# } -# """ -# -# Scenario: See review in account -# Given There are "review" "/reviews/1,/reviews/2" which have "account" "/accounts/2" -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts/2" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [ -# "/channels/1", -# "/channels/2" -# ], -# "views": [ -# "/views/1", -# "/views/2" -# ], -# "forums": [ -# "/forums/1", -# "/forums/2" -# ], -# "networks": [ -# "/networks/1", -# "/networks/2" -# ], -# "playlists": [], -# "replies": [], -# "reviews": [ -# "/reviews/1", -# "/reviews/2" -# ], -# "sustainabilityOffers": [], -# "seeders": [] -# } -# """ -# -# Scenario: See reply in account -# Given There are "reply" "/replies/1,/replies/2" which have "account" "/accounts/1,/accounts/2" -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts/2" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [ -# "/channels/1", -# "/channels/2" -# ], -# "views": [ -# "/views/1", -# "/views/2" -# ], -# "forums": [ -# "/forums/1", -# "/forums/2" -# ], -# "networks": [ -# "/networks/1", -# "/networks/2" -# ], -# "playlists": [], -# "replies": [ -# "/replies/1", -# "/replies/2" -# ], -# "reviews": [ -# "/reviews/1", -# "/reviews/2" -# ], -# "sustainabilityOffers": [], -# "seeders": [] -# } -# """ -# -# Scenario: See Sustainability Offers in account -# Given There are "sustainability offer" "/sustainability_offers/1,/sustainability_offers/2" which have "account" "/accounts/2" -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts/2" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [ -# "/channels/1", -# "/channels/2" -# ], -# "views": [ -# "/views/1", -# "/views/2" -# ], -# "forums": [ -# "/forums/1", -# "/forums/2" -# ], -# "networks": [ -# "/networks/1", -# "/networks/2" -# ], -# "playlists": [], -# "replies": [ -# "/replies/1", -# "/replies/2" -# ], -# "reviews": [ -# "/reviews/1", -# "/reviews/2" -# ], -# "sustainabilityOffers": [ -# "/sustainability_offers/1", -# "/sustainability_offers/2" -# ], -# "seeders": [] -# } -# """ -# -# Scenario: See seeder in account -# Given There are "seeder" "/seeders/1,/seeders/2" which have "account" "/accounts/2" -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts/2" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [ -# "/channels/1", -# "/channels/2" -# ], -# "views": [ -# "/views/1", -# "/views/2" -# ], -# "forums": [ -# "/forums/1", -# "/forums/2" -# ], -# "networks": [ -# "/networks/1", -# "/networks/2" -# ], -# "playlists": [], -# "replies": [ -# "/replies/1", -# "/replies/2" -# ], -# "reviews": [ -# "/reviews/1", -# "/reviews/2" -# ], -# "sustainabilityOffers": [ -# "/sustainability_offers/1", -# "/sustainability_offers/2" -# ], -# "seeders": [ -# "/seeders/1", -# "/seeders/2" -# ] -# } -# """ -# -# Scenario: See playlist in account -# Given There are "playlist" "/playlists/1,/playlist/2" which have "account" "/accounts/2" -# When I add "Accept" header equal to "application/ld+json" -# And I send a "GET" request to "/accounts/2" -# Then the response status code should be 200 -# And the response should be in JSON -# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" -# And the JSON should be equal to: -# """ -# { -# "@context": "/contexts/Account", -# "@id": "/accounts/2", -# "@type": "Account", -# "id": 2, -# "username": "stringUpdated", -# "email": "string@string.fr", -# "firstName": "string", -# "lastName": "string", -# "channels": [ -# "/channels/1", -# "/channels/2" -# ], -# "views": [ -# "/views/1", -# "/views/2" -# ], -# "forums": [ -# "/forums/1", -# "/forums/2" -# ], -# "networks": [ -# "/networks/1", -# "/networks/2" -# ], -# "playlists": [ -# "/playlists/1", -# "/playlists/2" -# ], -# "replies": [ -# "/replies/1", -# "/replies/2" -# ], -# "reviews": [ -# "/reviews/1", -# "/reviews/2" -# ], -# "sustainabilityOffers": [ -# "/sustainability_offers/1", -# "/sustainability_offers/2" -# ], -# "seeders": [ -# "/seeders/1", -# "/seeders/2" -# ] -# } -# """ -# -# Scenario: Delete an account -# When I add "Content-Type" header equal to "application/ld+json" -# And I add "Accept" header equal to "application/ld+json" -# And I send a "DELETE" request to "/accounts/2" -# Then the response status code should be 204 -# -# Scenario: Delete an account -# When I add "Content-Type" header equal to "application/ld+json" -# And I add "Accept" header equal to "application/ld+json" -# And I send a "DELETE" request to "/accounts/2" -# Then the response status code should be 404 + Scenario: Retrieve the profile list + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles", + "@type": "hydra:Collection", + "hydra:member": [ + { + "@id": "/profiles/1", + "@type": "Profile", + "id": 1, + "username": "denis", + "channels": [], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "denis", + "lastName": "denis" + }, + { + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "string", + "channels": [], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + ], + "hydra:totalItems": 2, + "hydra:search": { + "@type": "hydra:IriTemplate", + "hydra:template": "/profiles{?id,id[],username,firstName}", + "hydra:variableRepresentation": "BasicRepresentation", + "hydra:mapping": [ + { + "@type": "IriTemplateMapping", + "variable": "id", + "property": "id", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "id[]", + "property": "id", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "username", + "property": "username", + "required": false + }, + { + "@type": "IriTemplateMapping", + "variable": "firstName", + "property": "firstName", + "required": false + } + ] + } + } + """ + + Scenario: Throw errors when there is only bad properties + When I add "Content-Type" header equal to "application/ld+json" + And I add "Accept" header equal to "application/ld+json" + And I send a "POST" request to "/profiles" with body: + """ + { + "username": "string", + "firstName": "string", + "lastName": "string" + } + """ + Then the response status code should be 400 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/ConstraintViolationList", + "@type": "ConstraintViolationList", + "hydra:title": "An error occurred", + "hydra:description": "username: This value should not be blank.\nfirstName: This value should not be blank.\nlastName: This value should not be blank.", + "violations": [ + { + "propertyPath": "username", + "message": "This value should not be blank." + }, + { + "propertyPath": "firstName", + "message": "This value should not be blank." + }, + { + "propertyPath": "lastName", + "message": "This value should not be blank." + } + ] + } + """ + + Scenario: Update a profile + When I add "Content-Type" header equal to "application/ld+json" + And I add "Accept" header equal to "application/ld+json" + And I send a "PUT" request to "/profiles/2" with body: + """ + { + "username": "stringUpdated" + } + """ + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: Get a specific profile + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles/2" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: See channel in profile + Given There are "channel" "/channels/1,/channels/2" which have "profile" "/profiles/2" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles/2" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [ + "/channels/1", + "/channels/2" + ], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: See view in profile + Given There are "view" "/views/1,/views/2" which have "profile" "/profiles/2" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles/2" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [ + "/channels/1", + "/channels/2" + ], + "views": [ + "/views/1", + "/views/2" + ], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: See forum in profile + Given There are "forum" "/forums/1,/forums/2" which have "profile" "/profiles/2" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles/2" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [ + "/channels/1", + "/channels/2" + ], + "views": [ + "/views/1", + "/views/2" + ], + "forums": [ + "/forums/1", + "/forums/2" + ], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: See network in profile + Given There are "network" "/networks/1,/networks/2" which have "profile" "/profiles/2" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles/2" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [ + "/channels/1", + "/channels/2" + ], + "views": [ + "/views/1", + "/views/2" + ], + "forums": [ + "/forums/1", + "/forums/2" + ], + "networks": [ + "/networks/1", + "/networks/2" + ], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: See review in profile + Given There are "review" "/reviews/1,/reviews/2" which have "profile" "/profiles/2" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles/2" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [ + "/channels/1", + "/channels/2" + ], + "views": [ + "/views/1", + "/views/2" + ], + "forums": [ + "/forums/1", + "/forums/2" + ], + "networks": [ + "/networks/1", + "/networks/2" + ], + "playlists": [], + "replies": [], + "reviews": [ + "/reviews/1", + "/reviews/2" + ], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: See reply in profile + Given There are "reply" "/replies/1,/replies/2" which have "profile" "/profiles/1,/profiles/2" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles/2" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [ + "/channels/1", + "/channels/2" + ], + "views": [ + "/views/1", + "/views/2" + ], + "forums": [ + "/forums/1", + "/forums/2" + ], + "networks": [ + "/networks/1", + "/networks/2" + ], + "playlists": [], + "replies": [ + "/replies/1", + "/replies/2" + ], + "reviews": [ + "/reviews/1", + "/reviews/2" + ], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: See Sustainability Offers in profile + Given There are "sustainability offer" "/sustainability_offers/1,/sustainability_offers/2" which have "profile" "/profiles/2" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles/2" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [ + "/channels/1", + "/channels/2" + ], + "views": [ + "/views/1", + "/views/2" + ], + "forums": [ + "/forums/1", + "/forums/2" + ], + "networks": [ + "/networks/1", + "/networks/2" + ], + "playlists": [], + "replies": [ + "/replies/1", + "/replies/2" + ], + "reviews": [ + "/reviews/1", + "/reviews/2" + ], + "sustainabilityOffers": [ + "/sustainability_offers/1", + "/sustainability_offers/2" + ], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: See seeder in profile + Given There are "seeder" "/seeders/1,/seeders/2" which have "profile" "/profiles/2" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles/2" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [ + "/channels/1", + "/channels/2" + ], + "views": [ + "/views/1", + "/views/2" + ], + "forums": [ + "/forums/1", + "/forums/2" + ], + "networks": [ + "/networks/1", + "/networks/2" + ], + "playlists": [], + "replies": [ + "/replies/1", + "/replies/2" + ], + "reviews": [ + "/reviews/1", + "/reviews/2" + ], + "sustainabilityOffers": [ + "/sustainability_offers/1", + "/sustainability_offers/2" + ], + "seeders": [ + "/seeders/1", + "/seeders/2" + ], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: See playlist in profile + Given There are "playlist" "/playlists/1,/playlist/2" which have "profile" "/profiles/2" + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/profiles/2" + Then the response status code should be 200 + And the response should be in JSON + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/Profile", + "@id": "/profiles/2", + "@type": "Profile", + "id": 2, + "username": "stringUpdated", + "channels": [ + "/channels/1", + "/channels/2" + ], + "views": [ + "/views/1", + "/views/2" + ], + "forums": [ + "/forums/1", + "/forums/2" + ], + "networks": [ + "/networks/1", + "/networks/2" + ], + "playlists": [ + "/playlists/1", + "/playlists/2" + ], + "replies": [ + "/replies/1", + "/replies/2" + ], + "reviews": [ + "/reviews/1", + "/reviews/2" + ], + "sustainabilityOffers": [ + "/sustainability_offers/1", + "/sustainability_offers/2" + ], + "seeders": [ + "/seeders/1", + "/seeders/2" + ], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: Delete an profile + When I add "Content-Type" header equal to "application/ld+json" + And I add "Accept" header equal to "application/ld+json" + And I send a "DELETE" request to "/profiles/2" + Then the response status code should be 204 + + Scenario: Delete an profile + When I add "Content-Type" header equal to "application/ld+json" + And I add "Accept" header equal to "application/ld+json" + And I send a "DELETE" request to "/profiles/2" + Then the response status code should be 404 diff --git a/features/Reply.feature b/features/Reply.feature index 2eee6fb..fdf253c 100644 --- a/features/Reply.feature +++ b/features/Reply.feature @@ -5,7 +5,7 @@ Feature: Manage reply I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "review" "/reviews/1" @refreshSchema @@ -18,7 +18,7 @@ Feature: Manage reply { "content": "string", "review": "/reviews/1", - "author": "/accounts/1", + "author": "/profiles/1", "dateReply": "2017-02-04T09:36:08.014Z" } """ @@ -34,7 +34,7 @@ Feature: Manage reply "id": 1, "content": "string", "review": "/reviews/1", - "author": "/accounts/1", + "author": "/profiles/1", "dateReply": "2017-02-04T09:36:08+00:00" } """ @@ -90,7 +90,7 @@ Feature: Manage reply "id": 1, "content": "string", "review": "/reviews/1", - "author": "/accounts/1", + "author": "/profiles/1", "dateReply": "2017-02-04T09:36:08+01:00" } ], @@ -119,7 +119,7 @@ Feature: Manage reply "id": 1, "content": "stringUpdated", "review": "/reviews/1", - "author": "/accounts/1", + "author": "/profiles/1", "dateReply": "2017-02-04T09:36:08+01:00" } """ diff --git a/features/Review.feature b/features/Review.feature index 885bbaf..1251a1f 100644 --- a/features/Review.feature +++ b/features/Review.feature @@ -5,7 +5,7 @@ Feature: Manage review I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "video" "/videos/1" @refreshSchema @@ -19,7 +19,7 @@ Feature: Manage review "content": "string", "video": "/videos/1", "dateReview": "2017-02-04T09:36:08.044Z", - "author": "/accounts/1" + "author": "/profiles/1" } """ Then the response status code should be 201 @@ -36,7 +36,7 @@ Feature: Manage review "video": "/videos/1", "dateReview": "2017-02-04T09:36:08+00:00", "replies": [], - "author": "/accounts/1" + "author": "/profiles/1" } """ @@ -61,7 +61,7 @@ Feature: Manage review "/replies/1", "/replies/2" ], - "author": "/accounts/1" + "author": "/profiles/1" } """ @@ -123,7 +123,7 @@ Feature: Manage review "/replies/1", "/replies/2" ], - "author": "/accounts/1" + "author": "/profiles/1" } """ diff --git a/features/Seeder.feature b/features/Seeder.feature index db4fdca..f6c3d03 100644 --- a/features/Seeder.feature +++ b/features/Seeder.feature @@ -5,7 +5,7 @@ Feature: Manage seeder I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "video" "/videos/1" @refreshSchema @@ -17,7 +17,7 @@ Feature: Manage seeder """ { "platform": "string", - "account": "/accounts/1", + "profile": "/profiles/1", "video": "/videos/1", "ip": "127.0.0.1" } @@ -33,7 +33,7 @@ Feature: Manage seeder "@type": "Seeder", "id": 1, "platform": "string", - "account": "/accounts/1", + "profile": "/profiles/1", "ip": "127.0.0.1", "video": "/videos/1" } @@ -89,7 +89,7 @@ Feature: Manage seeder "@type": "Seeder", "id": 1, "platform": "string", - "account": "/accounts/1", + "profile": "/profiles/1", "ip": "127.0.0.1", "video": "/videos/1" } @@ -118,7 +118,7 @@ Feature: Manage seeder "@type": "Seeder", "id": 1, "platform": "stringUpdated", - "account": "/accounts/1", + "profile": "/profiles/1", "ip": "127.0.0.1", "video": "/videos/1" } diff --git a/features/Subtitles.feature b/features/Subtitles.feature index a35e91e..83a460c 100644 --- a/features/Subtitles.feature +++ b/features/Subtitles.feature @@ -5,7 +5,7 @@ Feature: Manage subtitles I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "video" "/videos/1" @refreshSchema diff --git a/features/SustainabilityOffer.feature b/features/SustainabilityOffer.feature index 0b59a49..4c11b38 100644 --- a/features/SustainabilityOffer.feature +++ b/features/SustainabilityOffer.feature @@ -5,7 +5,7 @@ Feature: Manage substainability_offer I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "channel" "/channels/1" @refreshSchema @@ -18,7 +18,7 @@ Feature: Manage substainability_offer { "name": "string", "duration": 0, - "account": "/accounts/1", + "profile": "/profiles/1", "channel": "/channels/1" } """ @@ -34,7 +34,7 @@ Feature: Manage substainability_offer "id": 1, "name": "string", "duration": 0, - "account": "/accounts/1", + "profile": "/profiles/1", "channel": "/channels/1" } """ @@ -90,7 +90,7 @@ Feature: Manage substainability_offer "id": 1, "name": "string", "duration": 0, - "account": "/accounts/1", + "profile": "/profiles/1", "channel": "/channels/1" } ], @@ -119,7 +119,7 @@ Feature: Manage substainability_offer "id": 1, "name": "stringUpdated", "duration": 0, - "account": "/accounts/1", + "profile": "/profiles/1", "channel": "/channels/1" } """ diff --git a/features/Video.feature b/features/Video.feature index 62237d6..0a7ac00 100644 --- a/features/Video.feature +++ b/features/Video.feature @@ -5,7 +5,7 @@ Feature: Manage video I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "channel" "/channels/1" And There are "category" "/categories/1" diff --git a/features/View.feature b/features/View.feature index bef0b30..a3ca332 100644 --- a/features/View.feature +++ b/features/View.feature @@ -5,7 +5,7 @@ Feature: Manage view I need to be able to retrieve, create, update and delete them trough the API. Background: - Given I am connected as "denis" with password "password" + Given I am connected as "denis@denis.fr" with password "password" And There are "video" "/videos/1" @refreshSchema @@ -16,7 +16,7 @@ Feature: Manage view And I send a "POST" request to "/views" with body: """ { - "account": "/accounts/2", + "profile": "/profiles/2", "video": "/videos/1" } """ @@ -30,7 +30,7 @@ Feature: Manage view "@id": "/views/1", "@type": "View", "id": 1, - "account": "/accounts/2", + "profile": "/profiles/2", "video": "/videos/1" } """ @@ -52,7 +52,7 @@ Feature: Manage view "@id": "/views/1", "@type": "View", "id": 1, - "account": "/accounts/2", + "profile": "/profiles/2", "video": "/videos/1" } ], diff --git a/features/bootstrap/AccountHelper.php b/features/bootstrap/AccountHelper.php deleted file mode 100644 index f088f9f..0000000 --- a/features/bootstrap/AccountHelper.php +++ /dev/null @@ -1,27 +0,0 @@ -setEmail($email)->setPassword('string')->setSalt('string'); - - ++self::$numberAccount; - - return $account; - } - -} \ No newline at end of file diff --git a/features/bootstrap/ChannelHelper.php b/features/bootstrap/ChannelHelper.php index cd71034..5ea3d0c 100644 --- a/features/bootstrap/ChannelHelper.php +++ b/features/bootstrap/ChannelHelper.php @@ -9,7 +9,7 @@ class ChannelHelper extends ResourceHelper private $profileHelper; - public function __construct(EntityManager $em, ProfileHelper $profileHelper) + public function __construct(EntityManager $em, UserProfileHelper $profileHelper) { parent::__construct($em); $this->profileHelper = $profileHelper; diff --git a/features/bootstrap/CommentHelper.php b/features/bootstrap/CommentHelper.php index eba5f19..fccd1a0 100644 --- a/features/bootstrap/CommentHelper.php +++ b/features/bootstrap/CommentHelper.php @@ -6,7 +6,7 @@ class CommentHelper extends ResourceHelper { /** - * @var ProfileHelper + * @var UserProfileHelper */ private $profileHelper; @@ -15,7 +15,7 @@ class CommentHelper extends ResourceHelper */ private $videoHelper; - public function __construct(EntityManager $em, ProfileHelper $profileHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, UserProfileHelper $profileHelper, VideoHelper $videoHelper) { parent::__construct($em); $this->profileHelper = $profileHelper; diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index bb470df..cb6ef7d 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -67,22 +67,22 @@ public function __construct(Request $request, ManagerRegistry $doctrine, Kernel $this->schemaTool = new SchemaTool($this->manager); $this->classes = $this->manager->getMetadataFactory()->getAllMetadata(); - $this->helpers['Account'] = new AccountHelper($this->manager); - $this->helpers['Profile'] = new ProfileHelper($this->manager, $this->helpers['Account']); - $this->helpers['Channel'] = new ChannelHelper($this->manager, $this->helpers['Profile']); - $this->helpers['Playlist'] = new PlaylistHelper($this->manager, $this->helpers['Profile']); + $this->helpers['UserAccount'] = new UserAccountHelper($this->manager); + $this->helpers['UserProfile'] = new UserProfileHelper($this->manager, $this->helpers['UserAccount']); + $this->helpers['Channel'] = new ChannelHelper($this->manager, $this->helpers['UserProfile']); + $this->helpers['Playlist'] = new PlaylistHelper($this->manager, $this->helpers['UserProfile']); $this->helpers['Video'] = new VideoHelper($this->manager, $this->helpers['Channel']); $this->helpers['SustainabilityOffer'] = new SustainabilityOfferHelper($this->manager, $this->helpers['Channel']); $this->helpers['Category'] = new CategoryHelper($this->manager); $this->helpers['Network'] = new NetworkHelper($this->manager); - $this->helpers['View'] = new ViewHelper($this->manager, $this->helpers['Profile'], $this->helpers['Video']); - $this->helpers['Forum'] = new ForumHelper($this->manager, $this->helpers['Profile'], $this->helpers['Video']); - $this->helpers['Review'] = new ReviewHelper($this->manager, $this->helpers['Profile'], $this->helpers['Video']); - $this->helpers['Reply'] = new ReplyHelper($this->manager, $this->helpers['Profile'], $this->helpers['Review']); - $this->helpers['Seeder'] = new SeederHelper($this->manager, $this->helpers['Profile'], $this->helpers['Video']); + $this->helpers['View'] = new ViewHelper($this->manager, $this->helpers['UserProfile'], $this->helpers['Video']); + $this->helpers['Forum'] = new ForumHelper($this->manager, $this->helpers['UserProfile'], $this->helpers['Video']); + $this->helpers['Review'] = new ReviewHelper($this->manager, $this->helpers['UserProfile'], $this->helpers['Video']); + $this->helpers['Reply'] = new ReplyHelper($this->manager, $this->helpers['UserProfile'], $this->helpers['Review']); + $this->helpers['Seeder'] = new SeederHelper($this->manager, $this->helpers['UserProfile'], $this->helpers['Video']); $this->helpers['Subtitles'] = new SubtitlesHelper($this->manager, $this->helpers['Video']); $this->helpers['Annotation'] = new AnnotationHelper($this->manager, $this->helpers['Video']); - $this->helpers['Comment'] = new CommentHelper($this->manager, $this->helpers['Profile'], $this->helpers['Video']); + $this->helpers['Comment'] = new CommentHelper($this->manager, $this->helpers['UserProfile'], $this->helpers['Video']); } /** diff --git a/features/bootstrap/ForumHelper.php b/features/bootstrap/ForumHelper.php index 46477c1..aa021ea 100644 --- a/features/bootstrap/ForumHelper.php +++ b/features/bootstrap/ForumHelper.php @@ -6,7 +6,7 @@ class ForumHelper extends ResourceHelper { /** - * @var ProfileHelper + * @var UserProfileHelper */ private $accountHelper; @@ -15,7 +15,7 @@ class ForumHelper extends ResourceHelper */ private $videoHelper; - public function __construct(EntityManager $em, ProfileHelper $accountHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, UserProfileHelper $accountHelper, VideoHelper $videoHelper) { parent::__construct($em); $this->accountHelper = $accountHelper; @@ -35,7 +35,7 @@ public function createResource() public function createRelationWith($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Profile') { + if ($nameResource2 == 'UserProfile') { return parent::createRelationWith($resource, 'CreatedBy', $resource2); } @@ -44,7 +44,7 @@ public function createRelationWith($resource, string $nameResource2, $resource2) public function relationExists($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Profile') { + if ($nameResource2 == 'UserProfile') { return parent::relationExists($resource, 'CreatedBy', $resource2); } diff --git a/features/bootstrap/NetworkHelper.php b/features/bootstrap/NetworkHelper.php index 5fdf9af..2edc9c1 100644 --- a/features/bootstrap/NetworkHelper.php +++ b/features/bootstrap/NetworkHelper.php @@ -20,7 +20,7 @@ public function createResource() public function createRelationWith($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Profile') { + if ($nameResource2 == 'UserProfile') { return parent::createRelationWith($resource, 'Peoples', $resource2); } @@ -29,7 +29,7 @@ public function createRelationWith($resource, string $nameResource2, $resource2) public function relationExists($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Profile') { + if ($nameResource2 == 'UserProfile') { return parent::relationExists($resource, 'Peoples', $resource2); } diff --git a/features/bootstrap/PlaylistHelper.php b/features/bootstrap/PlaylistHelper.php index 8c5695a..dea5117 100644 --- a/features/bootstrap/PlaylistHelper.php +++ b/features/bootstrap/PlaylistHelper.php @@ -10,18 +10,19 @@ class PlaylistHelper extends ResourceHelper */ private $profileHelper; - public function __construct(EntityManager $em, ProfileHelper $profileHelper) + public function __construct(EntityManager $em, UserProfileHelper $profileHelper) { parent::__construct($em); - $this->accountHelper = $profileHelper; + $this->profileHelper = $profileHelper; } public function createResource() { - $profileHelper = $this->profileHelper->persistResource(); + + $profile = $this->profileHelper->persistResource(); $playlist = new Playlist(); - $playlist->setProfile($profileHelper)->setName('string'); + $playlist->setProfile($profile)->setName('string'); return $playlist; } diff --git a/features/bootstrap/ProfileHelper.php b/features/bootstrap/ProfileHelper.php deleted file mode 100644 index ca77da6..0000000 --- a/features/bootstrap/ProfileHelper.php +++ /dev/null @@ -1,31 +0,0 @@ -accountHelper = $accountHelper; - } - - public function createResource() - { - $account = $this->accountHelper->createResource(); - - $username = 'string'.self::$numberAccount; - - $profile = new Profile(); - $profile->setUsername($username)->setFirstName('string') - ->setLastName('string')->setAccount($account); - - ++self::$numberAccount; - - return $profile; - } -} diff --git a/features/bootstrap/ReplyHelper.php b/features/bootstrap/ReplyHelper.php index e5548a9..8f61e95 100644 --- a/features/bootstrap/ReplyHelper.php +++ b/features/bootstrap/ReplyHelper.php @@ -6,7 +6,7 @@ class ReplyHelper extends ResourceHelper { /** - * @var ProfileHelper + * @var UserProfileHelper */ private $profileHelper; @@ -15,7 +15,7 @@ class ReplyHelper extends ResourceHelper */ private $reviewHelper; - public function __construct(EntityManager $em, ProfileHelper $profileHelper, ReviewHelper $reviewHelper) + public function __construct(EntityManager $em, UserProfileHelper $profileHelper, ReviewHelper $reviewHelper) { parent::__construct($em); $this->profileHelper = $profileHelper; @@ -35,7 +35,7 @@ public function createResource() public function createRelationWith($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Profile') { + if ($nameResource2 == 'UserProfile') { return parent::createRelationWith($resource, 'Author', $resource2); } @@ -44,7 +44,7 @@ public function createRelationWith($resource, string $nameResource2, $resource2) public function relationExists($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Profile') { + if ($nameResource2 == 'UserProfile') { return parent::relationExists($resource, 'Author', $resource2); } diff --git a/features/bootstrap/ReviewHelper.php b/features/bootstrap/ReviewHelper.php index e9c53e0..3151337 100644 --- a/features/bootstrap/ReviewHelper.php +++ b/features/bootstrap/ReviewHelper.php @@ -6,7 +6,7 @@ class ReviewHelper extends ResourceHelper { /** - * @var ProfileHelper + * @var UserProfileHelper */ private $profileHelper; @@ -15,7 +15,7 @@ class ReviewHelper extends ResourceHelper */ private $videoHelper; - public function __construct(EntityManager $em, ProfileHelper $profileHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, UserProfileHelper $profileHelper, VideoHelper $videoHelper) { parent::__construct($em); $this->profileHelper = $profileHelper; @@ -35,7 +35,7 @@ public function createResource() public function createRelationWith($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Profile') { + if ($nameResource2 == 'UserProfile') { return parent::createRelationWith($resource, 'Author', $resource2); } @@ -44,7 +44,7 @@ public function createRelationWith($resource, string $nameResource2, $resource2) public function relationExists($resource, string $nameResource2, $resource2) { - if ($nameResource2 == 'Profile') { + if ($nameResource2 == 'UserProfile') { return parent::relationExists($resource, 'Author', $resource2); } diff --git a/features/bootstrap/SeederHelper.php b/features/bootstrap/SeederHelper.php index 75dc475..72fe50b 100644 --- a/features/bootstrap/SeederHelper.php +++ b/features/bootstrap/SeederHelper.php @@ -6,7 +6,7 @@ class SeederHelper extends ResourceHelper { /** - * @var ProfileHelper + * @var UserProfileHelper */ private $profileHelper; @@ -15,7 +15,7 @@ class SeederHelper extends ResourceHelper */ private $videoHelper; - public function __construct(EntityManager $em, ProfileHelper $profileHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, UserProfileHelper $profileHelper, VideoHelper $videoHelper) { parent::__construct($em); $this->profileHelper = $profileHelper; @@ -28,7 +28,7 @@ public function createResource() $video = $this->videoHelper->persistResource(); $seeder = new Seeder(); - $seeder->setPlatform('string')->setIp('127.0.0.1')->setAccount($profile)->setVideo($video); + $seeder->setPlatform('string')->setIp('127.0.0.1')->setProfile($profile)->setVideo($video); return $seeder; } diff --git a/features/bootstrap/UserAccountHelper.php b/features/bootstrap/UserAccountHelper.php new file mode 100644 index 0000000..4f71cc4 --- /dev/null +++ b/features/bootstrap/UserAccountHelper.php @@ -0,0 +1,31 @@ +profileHelper = $profileHelper; + } + + public function createResource() + { + $profile = $this->profileHelper->persistResource(); + + $email = 'string'.self::$numberAccount.'@example.com'; + + $account = new UserAccount(); + $account->setEmail($email)->setPassword('string')->setSalt('string')->setProfile($profile); + + ++self::$numberAccount; + + return $account; + } + +} \ No newline at end of file diff --git a/features/bootstrap/UserProfileHelper.php b/features/bootstrap/UserProfileHelper.php new file mode 100644 index 0000000..ab206d6 --- /dev/null +++ b/features/bootstrap/UserProfileHelper.php @@ -0,0 +1,27 @@ +setUsername($username)->setFirstName('string') + ->setLastName('string'); + + ++self::$numberAccount; + + return $profile; + } +} diff --git a/features/bootstrap/ViewHelper.php b/features/bootstrap/ViewHelper.php index 7d5cdba..8b1f5b1 100644 --- a/features/bootstrap/ViewHelper.php +++ b/features/bootstrap/ViewHelper.php @@ -6,7 +6,7 @@ class ViewHelper extends ResourceHelper { /** - * @var ProfileHelper + * @var UserProfileHelper */ private $profileHelper; @@ -15,7 +15,7 @@ class ViewHelper extends ResourceHelper */ private $videoHelper; - public function __construct(EntityManager $em, ProfileHelper $profileHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, UserProfileHelper $profileHelper, VideoHelper $videoHelper) { parent::__construct($em); $this->profileHelper = $profileHelper; @@ -24,7 +24,7 @@ public function __construct(EntityManager $em, ProfileHelper $profileHelper, Vid public function createResource() { - $profile = $this->profileHelper>persistResource(); + $profile = $this->profileHelper->persistResource(); $video = $this->videoHelper->persistResource(); $view = new View(); diff --git a/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php b/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php index 18b62aa..aad6928 100644 --- a/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php +++ b/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php @@ -2,8 +2,8 @@ namespace AppBundle\DataFixtures\ORM\Fixtures; -use AppBundle\Entity\Account; -use AppBundle\Entity\Profile; +use AppBundle\Entity\UserAccount; +use AppBundle\Entity\UserProfile; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use Symfony\Bridge\Doctrine\Tests\Fixtures\ContainerAwareFixture; @@ -12,22 +12,23 @@ class AccountData extends ContainerAwareFixture implements OrderedFixtureInterfa { public function load(ObjectManager $manager) { - $privateData = new Account(); + $account = new UserProfile(); + $account + ->setFirstName('denis') + ->setLastName('denis') + ->setUsername('denis') + ; + + $privateData = new UserAccount(); $privateData ->setEmail('denis@denis.fr') ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) ->setPassword($this->container->get('security.password_encoder')->encodePassword($privateData, 'password')) + ->setProfile($account) ; + $manager->persist($account); $manager->persist($privateData); - $account = new Profile(); - $account - ->setFirstName('denis') - ->setLastName('denis') - ->setUsername('denis') - ->setAccount($privateData) - ; - $manager->persist($account); $manager->flush(); } diff --git a/src/AppBundle/Entity/Channel.php b/src/AppBundle/Entity/Channel.php index 2370b34..d1ff2c1 100644 --- a/src/AppBundle/Entity/Channel.php +++ b/src/AppBundle/Entity/Channel.php @@ -43,9 +43,9 @@ class Channel private $tags; /** - * @var Profile The owner's account + * @var UserProfile The owner's account * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="channels", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="channels", cascade={"persist"}) */ private $profile; @@ -87,12 +87,12 @@ public function __construct() $this->sustainabilityOffers = new ArrayCollection(); } - public function getProfile(): Profile + public function getProfile(): UserProfile { return $this->profile; } - public function setProfile(Profile $profile): Channel + public function setProfile(UserProfile $profile): Channel { $this->profile = $profile; diff --git a/src/AppBundle/Entity/Comment.php b/src/AppBundle/Entity/Comment.php index 702dc85..3b42906 100644 --- a/src/AppBundle/Entity/Comment.php +++ b/src/AppBundle/Entity/Comment.php @@ -41,9 +41,9 @@ class Comment private $video; /** - * @var Profile Author of the comment + * @var UserProfile Author of the comment * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile") + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile") */ private $author; @@ -104,12 +104,12 @@ public function setVideo(Video $video): Comment return $this; } - public function getAuthor(): Profile + public function getAuthor(): UserProfile { return $this->author; } - public function setAuthor(Profile $author): Comment + public function setAuthor(UserProfile $author): Comment { $this->author = $author; diff --git a/src/AppBundle/Entity/Forum.php b/src/AppBundle/Entity/Forum.php index e860522..b009bc2 100644 --- a/src/AppBundle/Entity/Forum.php +++ b/src/AppBundle/Entity/Forum.php @@ -42,9 +42,9 @@ class Forum private $video; /** - * @var Profile + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="forums", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="forums", cascade={"persist"}) */ private $createdBy; @@ -89,7 +89,7 @@ public function getCreatedBy() return $this->createdBy; } - public function setCreatedBy(Profile $createdBy): Forum + public function setCreatedBy(UserProfile $createdBy): Forum { $this->createdBy = $createdBy; diff --git a/src/AppBundle/Entity/Network.php b/src/AppBundle/Entity/Network.php index 4359105..18bf8f7 100644 --- a/src/AppBundle/Entity/Network.php +++ b/src/AppBundle/Entity/Network.php @@ -37,7 +37,7 @@ class Network /** * @var ArrayCollection * - * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Profile", inversedBy="networks", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="AppBundle\Entity\UserProfile", inversedBy="networks", cascade={"persist"}) */ private $peoples; diff --git a/src/AppBundle/Entity/OAuth/AccessToken.php b/src/AppBundle/Entity/OAuth/AccessToken.php index b7e20fb..eb6d001 100644 --- a/src/AppBundle/Entity/OAuth/AccessToken.php +++ b/src/AppBundle/Entity/OAuth/AccessToken.php @@ -24,7 +24,7 @@ class AccessToken extends BaseAccessToken protected $client; /** - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account") + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserAccount") */ protected $user; } diff --git a/src/AppBundle/Entity/OAuth/AuthCode.php b/src/AppBundle/Entity/OAuth/AuthCode.php index 77bb035..86954cf 100644 --- a/src/AppBundle/Entity/OAuth/AuthCode.php +++ b/src/AppBundle/Entity/OAuth/AuthCode.php @@ -24,7 +24,7 @@ class AuthCode extends BaseAuthCode protected $client; /** - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account") + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserAccount") */ protected $user; } diff --git a/src/AppBundle/Entity/OAuth/RefreshToken.php b/src/AppBundle/Entity/OAuth/RefreshToken.php index ef44d33..659e35c 100644 --- a/src/AppBundle/Entity/OAuth/RefreshToken.php +++ b/src/AppBundle/Entity/OAuth/RefreshToken.php @@ -24,7 +24,7 @@ class RefreshToken extends BaseRefreshToken protected $client; /** - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account") + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserAccount") */ protected $user; } diff --git a/src/AppBundle/Entity/Playlist.php b/src/AppBundle/Entity/Playlist.php index 83ccee7..a9bf8a1 100644 --- a/src/AppBundle/Entity/Playlist.php +++ b/src/AppBundle/Entity/Playlist.php @@ -52,9 +52,9 @@ class Playlist private $network; /** - * @var Profile + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="playlists", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="playlists", cascade={"persist"}) * @ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=true) */ private $profile; @@ -112,7 +112,7 @@ public function getProfile() return $this->profile; } - public function setProfile(Profile $profile): Playlist + public function setProfile(UserProfile $profile): Playlist { $this->profile = $profile; diff --git a/src/AppBundle/Entity/Reply.php b/src/AppBundle/Entity/Reply.php index 3124b87..72f2f6f 100644 --- a/src/AppBundle/Entity/Reply.php +++ b/src/AppBundle/Entity/Reply.php @@ -41,9 +41,9 @@ class Reply private $review; /** - * @var Profile + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="replies") + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="replies") */ private $author; @@ -92,12 +92,12 @@ public function setReview(Review $review): Reply return $this; } - public function getAuthor(): Profile + public function getAuthor(): UserProfile { return $this->author; } - public function setAuthor(Profile $author): Reply + public function setAuthor(UserProfile $author): Reply { $this->author = $author; diff --git a/src/AppBundle/Entity/Review.php b/src/AppBundle/Entity/Review.php index 7c0876c..4738310 100644 --- a/src/AppBundle/Entity/Review.php +++ b/src/AppBundle/Entity/Review.php @@ -42,9 +42,9 @@ class Review private $video; /** - * @var Profile + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="reviews") + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="reviews") */ private $author; @@ -128,12 +128,12 @@ public function setReplies($replies): Review return $this; } - public function getAuthor(): Profile + public function getAuthor(): UserProfile { return $this->author; } - public function setAuthor(Profile $author): Review + public function setAuthor(UserProfile $author): Review { $this->author = $author; diff --git a/src/AppBundle/Entity/Seeder.php b/src/AppBundle/Entity/Seeder.php index b480030..e784558 100644 --- a/src/AppBundle/Entity/Seeder.php +++ b/src/AppBundle/Entity/Seeder.php @@ -41,9 +41,9 @@ class Seeder private $ip; /** - * @var Profile + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="seeders", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="seeders", cascade={"persist"}) */ private $profile; @@ -78,12 +78,12 @@ public function setPlatform(string $platform): Seeder return $this; } - public function getProfile(): Profile + public function getProfile(): UserProfile { return $this->profile; } - public function setProfile(Profile $profile): Seeder + public function setProfile(UserProfile $profile): Seeder { $this->profile = $profile; diff --git a/src/AppBundle/Entity/SustainabilityOffer.php b/src/AppBundle/Entity/SustainabilityOffer.php index c32ad05..d0d2822 100644 --- a/src/AppBundle/Entity/SustainabilityOffer.php +++ b/src/AppBundle/Entity/SustainabilityOffer.php @@ -43,9 +43,9 @@ class SustainabilityOffer private $duration; /** - * @var Profile + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="sustainabilityOffers", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="sustainabilityOffers", cascade={"persist"}) */ private $profile; @@ -92,12 +92,12 @@ public function setDuration(int $duration): SustainabilityOffer return $this; } - public function getProfile(): Profile + public function getProfile(): UserProfile { return $this->profile; } - public function setProfile(Profile $profile): SustainabilityOffer + public function setProfile(UserProfile $profile): SustainabilityOffer { $this->profile = $profile; diff --git a/src/AppBundle/Entity/Account.php b/src/AppBundle/Entity/UserAccount.php similarity index 76% rename from src/AppBundle/Entity/Account.php rename to src/AppBundle/Entity/UserAccount.php index 66ce400..c32763f 100644 --- a/src/AppBundle/Entity/Account.php +++ b/src/AppBundle/Entity/UserAccount.php @@ -7,6 +7,7 @@ use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * User's account. @@ -14,7 +15,7 @@ * @ORM\Entity(repositoryClass="AppBundle\Repository\AccountRepository") * @ApiResource */ -class Account implements UserInterface +class UserAccount implements UserInterface { /** * @var int @@ -61,20 +62,20 @@ class Account implements UserInterface private $password; /** - * @var Profile + * @var UserProfile * - * @ORM\OneToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="account", cascade={"persist"}) + * @ORM\OneToOne(targetEntity="AppBundle\Entity\UserProfile", mappedBy="account", cascade={"persist"}) */ private $profile; - + public function getUsername(): string { - return $this->profile->getUsername(); + return $this->email; } - public function setUsername(string $username): Account + public function setUsername(string $username): UserAccount { - $this->profile->setUsername($username); + $this->email = $username; return $this; } @@ -84,7 +85,7 @@ public function getEmail(): string return $this->email; } - public function setEmail($email): Account + public function setEmail($email): UserAccount { $this->email = $email; @@ -96,7 +97,7 @@ public function getSalt(): string return $this->salt; } - public function setSalt(string $salt): Account + public function setSalt(string $salt): UserAccount { $this->salt = $salt; @@ -117,7 +118,7 @@ public function getPassword(): string return $this->password; } - public function setPassword(string $password): Account + public function setPassword(string $password): UserAccount { $this->password = $password; @@ -129,19 +130,19 @@ public function getId(): int return $this->id; } - public function setId(int $id): Account + public function setId(int $id): UserAccount { $this->id = $id; return $this; } - public function getProfile(): Profile + public function getProfile(): ?UserProfile { return $this->profile; } - public function setProfile(Profile $profile): Account + public function setProfile(UserProfile $profile): UserAccount { $this->profile = $profile; diff --git a/src/AppBundle/Entity/Profile.php b/src/AppBundle/Entity/UserProfile.php similarity index 85% rename from src/AppBundle/Entity/Profile.php rename to src/AppBundle/Entity/UserProfile.php index 8288fc7..86a5463 100644 --- a/src/AppBundle/Entity/Profile.php +++ b/src/AppBundle/Entity/UserProfile.php @@ -14,7 +14,7 @@ * @ORM\Entity * @ApiResource(attributes={"filters" = {"account.search"}, "normalization_context" = {"groups" = {"account"}}}) */ -class Profile +class UserProfile { /** * @var int The Id of the user @@ -134,9 +134,10 @@ class Profile private $lastName; /** - * @var Account + * @var UserAccount * - * @ORM\OneToOne(targetEntity="AppBundle\Entity\Account", mappedBy="profile", cascade={"persist"}) + * @ORM\OneToOne(targetEntity="AppBundle\Entity\UserAccount", inversedBy="profile", cascade={"persist"}) + * @ORM\JoinColumn(nullable=false) */ private $account; @@ -158,7 +159,7 @@ public function getViews() return $this->views; } - public function setViews($views): Profile + public function setViews($views): UserProfile { $this->views = $views; @@ -170,7 +171,7 @@ public function getChannels() return $this->channels; } - public function setChannels($channels): Profile + public function setChannels($channels): UserProfile { $this->channels = $channels; @@ -182,7 +183,7 @@ public function getId(): int return $this->id; } - public function setId($id): Profile + public function setId($id): UserProfile { $this->id = $id; @@ -194,7 +195,7 @@ public function getUsername(): string return $this->username; } - public function setUsername(string $username): Profile + public function setUsername(string $username): UserProfile { $this->username = $username; @@ -206,7 +207,7 @@ public function getFirstName(): string return $this->firstName; } - public function setFirstName(string $firstName): Profile + public function setFirstName(string $firstName): UserProfile { $this->firstName = $firstName; @@ -218,7 +219,7 @@ public function getLastName(): string return $this->lastName; } - public function setLastName(string $lastName): Profile + public function setLastName(string $lastName): UserProfile { $this->lastName = $lastName; @@ -230,7 +231,7 @@ public function getForums() return $this->forums; } - public function setForums($forums): Profile + public function setForums($forums): UserProfile { $this->forums = $forums; @@ -242,7 +243,7 @@ public function getNetworks() return $this->networks; } - public function setNetworks($networks): Profile + public function setNetworks($networks): UserProfile { $this->networks = $networks; @@ -254,7 +255,7 @@ public function getPlaylists() return $this->playlists; } - public function setPlaylist($playlists): Profile + public function setPlaylist($playlists): UserProfile { $this->playlists = $playlists; @@ -266,7 +267,7 @@ public function getReplies() return $this->replies; } - public function setReplies($replies): Profile + public function setReplies($replies): UserProfile { $this->replies = $replies; @@ -278,7 +279,7 @@ public function getReviews() return $this->reviews; } - public function setReviews($reviews): Profile + public function setReviews($reviews): UserProfile { $this->reviews = $reviews; @@ -290,7 +291,7 @@ public function getSustainabilityOffers() return $this->sustainabilityOffers; } - public function setSustainabilityOffers($sustainabilityOffers): Profile + public function setSustainabilityOffers($sustainabilityOffers): UserProfile { $this->sustainabilityOffers = $sustainabilityOffers; @@ -302,19 +303,19 @@ public function getSeeders() return $this->seeders; } - public function setSeeders($seeders): Profile + public function setSeeders($seeders): UserProfile { $this->seeders = $seeders; return $this; } - public function getAccount(): Account + public function getAccount(): UserAccount { return $this->account; } - public function setAccount(Account $account): Profile + public function setAccount(UserAccount $account): UserProfile { $this->account = $account; diff --git a/src/AppBundle/Entity/View.php b/src/AppBundle/Entity/View.php index 5f3ca70..49a2d89 100644 --- a/src/AppBundle/Entity/View.php +++ b/src/AppBundle/Entity/View.php @@ -23,9 +23,9 @@ class View private $id; /** - * @var Profile + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Profile", inversedBy="views", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="views", cascade={"persist"}) */ private $profile; @@ -46,12 +46,12 @@ public function setId(int $id) $this->id = $id; } - public function getProfile(): Profile + public function getProfile(): UserProfile { return $this->profile; } - public function setProfile(Profile $profile) + public function setProfile(UserProfile $profile) { $this->profile = $profile; diff --git a/src/AppBundle/EventSubscriber/AccountChecker.php b/src/AppBundle/EventSubscriber/AccountChecker.php index 4cb5861..002b0bf 100644 --- a/src/AppBundle/EventSubscriber/AccountChecker.php +++ b/src/AppBundle/EventSubscriber/AccountChecker.php @@ -3,9 +3,10 @@ namespace AppBundle\EventSubscriber; use ApiPlatform\Core\EventListener\EventPriorities; -use AppBundle\Entity\Profile; +use AppBundle\Entity\UserProfile; use AppBundle\Security\AccountVoter; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; @@ -26,22 +27,22 @@ public function __construct(AuthorizationCheckerInterface $authorizationChecker) public static function getSubscribedEvents() { return [ - KernelEvents::VIEW => [['checkAccountAccess', EventPriorities::POST_VALIDATE]], + KernelEvents::VIEW => [['onKernelRequest', EventPriorities::PRE_READ]], ]; } - public function checkAccountAccess(GetResponseForControllerResultEvent $event) + public function onKernelRequest(GetResponseEvent $event) { - $profile = $event->getControllerResult(); $method = $event->getRequest()->getMethod(); - if (!$profile instanceof Profile || Request::METHOD_POST !== $method) { + if (Request::METHOD_POST === $method || $event->getRequest()->getPathInfo() === '/oauth/v2/token') { return; } - if (!$this->authorizationChecker->isGranted('access', $profile)) { + if (!$this->authorizationChecker->isGranted('access', $event->getRequest()->getPathInfo())) { $response = new Response('You don\'t have access to this account', Response::HTTP_FORBIDDEN); $event->setResponse($response); } + } } \ No newline at end of file diff --git a/src/AppBundle/EventSubscriber/PasswordEncryption.php b/src/AppBundle/EventSubscriber/PasswordEncryption.php index 50ee232..63e41ba 100644 --- a/src/AppBundle/EventSubscriber/PasswordEncryption.php +++ b/src/AppBundle/EventSubscriber/PasswordEncryption.php @@ -3,10 +3,10 @@ namespace AppBundle\EventSubscriber; use ApiPlatform\Core\EventListener\EventPriorities; -use AppBundle\Entity\Profile; +use AppBundle\Entity\UserProfile; use AppBundle\Security\AccountVoter; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -25,17 +25,17 @@ public static function getSubscribedEvents() public function encryptPassword(GetResponseForControllerResultEvent $event) { - $profile = $event->getControllerResult(); + $account = $event->getControllerResult(); $method = $event->getRequest()->getMethod(); - if (!$profile instanceof Profile || Request::METHOD_POST !== $method) { + if (!$account instanceof Account || $method !== Request::METHOD_POST) { return; } - $profile->getAccount() + $account ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) ->setPassword($this->container->get('security.password_encoder') - ->encodePassword($profile->getAccount(), 'password')) + ->encodePassword($account, 'password')) ; } } \ No newline at end of file diff --git a/src/AppBundle/Repository/AccountRepository.php b/src/AppBundle/Repository/AccountRepository.php index e54c819..8e31fe0 100644 --- a/src/AppBundle/Repository/AccountRepository.php +++ b/src/AppBundle/Repository/AccountRepository.php @@ -16,4 +16,15 @@ public function findOneByUsername(string $username) ->getOneOrNullResult() ; } + + public function findOneByEmail(string $email) + { + return $this->createQueryBuilder('a') + ->select('a') + ->where('a.email = :email') + ->setParameter('email', $email) + ->getQuery() + ->getOneOrNullResult() + ; + } } diff --git a/src/AppBundle/Repository/ProfileRepository.php b/src/AppBundle/Repository/ProfileRepository.php deleted file mode 100644 index 4eef4df..0000000 --- a/src/AppBundle/Repository/ProfileRepository.php +++ /dev/null @@ -1,19 +0,0 @@ -createQueryBuilder('a') - ->select('a') - ->where('a.email = :email') - ->setParameter('email', $email) - ->getQuery() - ->getOneOrNullResult() - ; - } -} \ No newline at end of file diff --git a/src/AppBundle/Security/AccountProvider.php b/src/AppBundle/Security/AccountProvider.php index 35552d4..9753885 100644 --- a/src/AppBundle/Security/AccountProvider.php +++ b/src/AppBundle/Security/AccountProvider.php @@ -2,8 +2,8 @@ namespace AppBundle\Security; -use AppBundle\Entity\Account; -use AppBundle\Entity\Profile; +use AppBundle\Entity\UserAccount; +use AppBundle\Entity\UserProfile; use Doctrine\ORM\EntityManager; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; @@ -16,12 +16,12 @@ class AccountProvider implements UserProviderInterface public function __construct(EntityManager $em) { - $this->repository = $em->getRepository('AppBundle:Profile'); + $this->repository = $em->getRepository('AppBundle:UserAccount'); } public function loadUserByUsername($username) { - $account = $this->repository->findOneByUsername($username); + $account = $this->repository->findOneByEmail($username); if (null === $account) { throw new UsernameNotFoundException('No account found for email'); @@ -32,7 +32,7 @@ public function loadUserByUsername($username) public function refreshUser(UserInterface $user) { - if (!$user instanceof Profile) { + if (!$user instanceof UserProfile) { throw new UnsupportedUserException( sprintf('Instances of "%s" are not supported.', get_class($user)) ); @@ -43,6 +43,6 @@ public function refreshUser(UserInterface $user) public function supportsClass($class) { - return Account::class === $class; + return UserAccount::class === $class; } } diff --git a/src/AppBundle/Security/AccountVoter.php b/src/AppBundle/Security/AccountVoter.php index 518b804..f875599 100644 --- a/src/AppBundle/Security/AccountVoter.php +++ b/src/AppBundle/Security/AccountVoter.php @@ -2,8 +2,8 @@ namespace AppBundle\Security; -use AppBundle\Entity\Account; -use AppBundle\Entity\Profile; +use AppBundle\Entity\UserAccount; +use AppBundle\Entity\UserProfile; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\Voter\Voter; @@ -18,7 +18,7 @@ protected function supports($attribute, $subject) return false; } - if (!$subject instanceof Account) { + if ($subject === null) { return false; } @@ -29,21 +29,22 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { $user = $token->getUser(); - if (!$user instanceof Profile) { + if (!$user instanceof UserAccount) { return false; } - $profile = $subject; + $profileId = explode('/', $subject)[2]; + if ($attribute === self::ACCESS) { - return $this->canAccess($profile, $user); + return $this->canAccess($profileId, $user); } throw new \LogicException('This code should not be reached!'); } - private function canAccess(Profile $profile, Account $account) + private function canAccess(string $profileId, UserAccount $account) { - return $profile->getAccount()->getId() === $account->getId(); + return $account->getId() === intval($profileId); } } \ No newline at end of file diff --git a/src/AppBundle/Validator/Constraints/PlaylistClassValidator.php b/src/AppBundle/Validator/Constraints/PlaylistClassValidator.php index 7a6960c..40c0208 100644 --- a/src/AppBundle/Validator/Constraints/PlaylistClassValidator.php +++ b/src/AppBundle/Validator/Constraints/PlaylistClassValidator.php @@ -9,7 +9,7 @@ class PlaylistClassValidator extends ConstraintValidator { public function validate($playlist, Constraint $constraint) { - if (!$this->ternaryXor($playlist->getChannel(), $playlist->getNetwork(), $playlist->getAccount())) { + if (!$this->ternaryXor($playlist->getChannel(), $playlist->getNetwork(), $playlist->getProfile())) { $this->context->buildViolation($constraint->message)->atPath('Playlist')->addViolation(); } } diff --git a/var/cache/.gitkeep b/var/cache/.gitkeep deleted file mode 100644 index e69de29..0000000 From fe6c62604de703a9926a3604c03c063555f9b12d Mon Sep 17 00:00:00 2001 From: mike1796 Date: Fri, 4 Aug 2017 17:49:14 +0200 Subject: [PATCH 5/5] Security and voters seems to be ok --- ...04131111.php => Version20170804145916.php} | 42 ++--- app/config/services.yml | 2 +- features/Channel.feature | 32 ++-- features/Comment.feature | 8 +- features/Forum.feature | 8 +- features/Network.feature | 18 +- features/Playlist.feature | 15 +- features/Reply.feature | 8 +- features/Review.feature | 8 +- features/Seeder.feature | 8 +- features/SustainabilityOffer.feature | 8 +- .../{Account.feature => UserAccount.feature} | 81 ++++----- .../{Profile.feature => UserProfile.feature} | 164 +++++++++--------- features/View.feature | 6 +- features/bootstrap/ChannelHelper.php | 2 +- features/bootstrap/PlaylistHelper.php | 3 +- features/bootstrap/SeederHelper.php | 2 +- .../bootstrap/SustainabilityOfferHelper.php | 2 +- features/bootstrap/UserAccountHelper.php | 11 +- features/bootstrap/UserProfileHelper.php | 8 +- features/bootstrap/ViewHelper.php | 2 +- .../DataFixtures/ORM/Fixtures/AccountData.php | 16 +- src/AppBundle/DataFixtures/ORM/fixtures.yml | 35 ++-- src/AppBundle/Entity/Channel.php | 10 +- src/AppBundle/Entity/Playlist.php | 10 +- src/AppBundle/Entity/Seeder.php | 10 +- src/AppBundle/Entity/SustainabilityOffer.php | 10 +- src/AppBundle/Entity/UserAccount.php | 17 +- src/AppBundle/Entity/UserProfile.php | 25 ++- src/AppBundle/Entity/View.php | 10 +- .../EventSubscriber/AccountChecker.php | 13 +- .../EventSubscriber/PasswordEncryption.php | 17 +- ...pository.php => UserAccountRepository.php} | 2 +- src/AppBundle/Security/AccountProvider.php | 4 +- src/AppBundle/Security/AccountVoter.php | 13 +- .../Constraints/PlaylistClassValidator.php | 2 +- var/sessions/.gitkeep | 0 37 files changed, 303 insertions(+), 329 deletions(-) rename app/DoctrineMigrations/{Version20170804131111.php => Version20170804145916.php} (91%) rename features/{Account.feature => UserAccount.feature} (68%) rename features/{Profile.feature => UserProfile.feature} (80%) rename src/AppBundle/Repository/{AccountRepository.php => UserAccountRepository.php} (92%) delete mode 100644 var/sessions/.gitkeep diff --git a/app/DoctrineMigrations/Version20170804131111.php b/app/DoctrineMigrations/Version20170804145916.php similarity index 91% rename from app/DoctrineMigrations/Version20170804131111.php rename to app/DoctrineMigrations/Version20170804145916.php index e6578b2..7738bde 100644 --- a/app/DoctrineMigrations/Version20170804131111.php +++ b/app/DoctrineMigrations/Version20170804145916.php @@ -8,7 +8,7 @@ /** * Auto-generated Migration: Please modify to your needs! */ -class Version20170804131111 extends AbstractMigration +class Version20170804145916 extends AbstractMigration { /** * @param Schema $schema @@ -40,8 +40,8 @@ public function up(Schema $schema) $this->addSql('CREATE SEQUENCE metadata_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE ip_request_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE category_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE view (id INT NOT NULL, profile_id INT DEFAULT NULL, video_id INT DEFAULT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_FEFDAB8ECCFA12B8 ON view (profile_id)'); + $this->addSql('CREATE TABLE view (id INT NOT NULL, user_profile_id INT DEFAULT NULL, video_id INT DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_FEFDAB8E6B9DD454 ON view (user_profile_id)'); $this->addSql('CREATE INDEX IDX_FEFDAB8E29C1004E ON view (video_id)'); $this->addSql('CREATE TABLE forum (id INT NOT NULL, video_id INT DEFAULT NULL, created_by_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_852BBECD29C1004E ON forum (video_id)'); @@ -59,11 +59,11 @@ public function up(Schema $schema) $this->addSql('CREATE TABLE review (id INT NOT NULL, video_id INT DEFAULT NULL, author_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, date_comment TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_794381C629C1004E ON review (video_id)'); $this->addSql('CREATE INDEX IDX_794381C6F675F31B ON review (author_id)'); - $this->addSql('CREATE TABLE user_profile (id INT NOT NULL, account_id INT NOT NULL, username VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE user_profile (id INT NOT NULL, user_account_id INT NOT NULL, username VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE UNIQUE INDEX UNIQ_D95AB405F85E0677 ON user_profile (username)'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_D95AB4059B6B5FBA ON user_profile (account_id)'); - $this->addSql('CREATE TABLE sustainability_offer (id INT NOT NULL, profile_id INT DEFAULT NULL, channel_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, duration INT NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_BDC3DF35CCFA12B8 ON sustainability_offer (profile_id)'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_D95AB4053C0C9956 ON user_profile (user_account_id)'); + $this->addSql('CREATE TABLE sustainability_offer (id INT NOT NULL, user_profile_id INT DEFAULT NULL, channel_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, duration INT NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_BDC3DF356B9DD454 ON sustainability_offer (user_profile_id)'); $this->addSql('CREATE INDEX IDX_BDC3DF3572F5A1AA ON sustainability_offer (channel_id)'); $this->addSql('CREATE TABLE video (id INT NOT NULL, channel_id INT DEFAULT NULL, metadata_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, number_view INT DEFAULT NULL, hash VARCHAR(255) NOT NULL, magnet VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_7CC7DA2C72F5A1AA ON video (channel_id)'); @@ -73,8 +73,8 @@ public function up(Schema $schema) $this->addSql('CREATE INDEX IDX_AECE2B7D12469DE2 ON video_category (category_id)'); $this->addSql('CREATE TABLE user_account (id INT NOT NULL, email VARCHAR(255) NOT NULL, salt VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE UNIQUE INDEX UNIQ_253B48AEE7927C74 ON user_account (email)'); - $this->addSql('CREATE TABLE seeder (id INT NOT NULL, profile_id INT DEFAULT NULL, video_id INT DEFAULT NULL, platform VARCHAR(255) NOT NULL, ip VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_8801CDCECCFA12B8 ON seeder (profile_id)'); + $this->addSql('CREATE TABLE seeder (id INT NOT NULL, user_profile_id INT DEFAULT NULL, video_id INT DEFAULT NULL, platform VARCHAR(255) NOT NULL, ip VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_8801CDCE6B9DD454 ON seeder (user_profile_id)'); $this->addSql('CREATE INDEX IDX_8801CDCE29C1004E ON seeder (video_id)'); $this->addSql('CREATE TABLE annotation (id INT NOT NULL, video_id INT DEFAULT NULL, begin_time INT NOT NULL, end_time INT NOT NULL, annotation_text VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_2E443EF229C1004E ON annotation (video_id)'); @@ -100,16 +100,16 @@ public function up(Schema $schema) $this->addSql('CREATE TABLE client (id INT NOT NULL, random_id VARCHAR(255) NOT NULL, redirect_uris TEXT NOT NULL, secret VARCHAR(255) NOT NULL, allowed_grant_types TEXT NOT NULL, PRIMARY KEY(id))'); $this->addSql('COMMENT ON COLUMN client.redirect_uris IS \'(DC2Type:array)\''); $this->addSql('COMMENT ON COLUMN client.allowed_grant_types IS \'(DC2Type:array)\''); - $this->addSql('CREATE TABLE channel (id INT NOT NULL, profile_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, tags TEXT DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE channel (id INT NOT NULL, user_profile_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, tags TEXT DEFAULT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE UNIQUE INDEX UNIQ_A2F98E475E237E06 ON channel (name)'); - $this->addSql('CREATE INDEX IDX_A2F98E47CCFA12B8 ON channel (profile_id)'); + $this->addSql('CREATE INDEX IDX_A2F98E476B9DD454 ON channel (user_profile_id)'); $this->addSql('COMMENT ON COLUMN channel.tags IS \'(DC2Type:array)\''); $this->addSql('CREATE TABLE subtitles (id INT NOT NULL, video_id INT DEFAULT NULL, begin_time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, end_time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, path VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_A739C98629C1004E ON subtitles (video_id)'); $this->addSql('CREATE TABLE metadata (id INT NOT NULL, height INT NOT NULL, width INT NOT NULL, format VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE TABLE ip_request (id INT NOT NULL, ip VARCHAR(255) NOT NULL, date_request TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, accesses INT NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE TABLE category (id INT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8ECCFA12B8 FOREIGN KEY (profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8E6B9DD454 FOREIGN KEY (user_profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE view ADD CONSTRAINT FK_FEFDAB8E29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE forum ADD CONSTRAINT FK_852BBECD29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE forum ADD CONSTRAINT FK_852BBECDB03A8386 FOREIGN KEY (created_by_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); @@ -122,14 +122,14 @@ public function up(Schema $schema) $this->addSql('ALTER TABLE reply ADD CONSTRAINT FK_FDA8C6E0F675F31B FOREIGN KEY (author_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE review ADD CONSTRAINT FK_794381C629C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE review ADD CONSTRAINT FK_794381C6F675F31B FOREIGN KEY (author_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE user_profile ADD CONSTRAINT FK_D95AB4059B6B5FBA FOREIGN KEY (account_id) REFERENCES user_account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE sustainability_offer ADD CONSTRAINT FK_BDC3DF35CCFA12B8 FOREIGN KEY (profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE user_profile ADD CONSTRAINT FK_D95AB4053C0C9956 FOREIGN KEY (user_account_id) REFERENCES user_account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE sustainability_offer ADD CONSTRAINT FK_BDC3DF356B9DD454 FOREIGN KEY (user_profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE sustainability_offer ADD CONSTRAINT FK_BDC3DF3572F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE video ADD CONSTRAINT FK_7CC7DA2C72F5A1AA FOREIGN KEY (channel_id) REFERENCES channel (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE video ADD CONSTRAINT FK_7CC7DA2CDC9EE959 FOREIGN KEY (metadata_id) REFERENCES metadata (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE video_category ADD CONSTRAINT FK_AECE2B7D29C1004E FOREIGN KEY (video_id) REFERENCES video (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE video_category ADD CONSTRAINT FK_AECE2B7D12469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE seeder ADD CONSTRAINT FK_8801CDCECCFA12B8 FOREIGN KEY (profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE seeder ADD CONSTRAINT FK_8801CDCE6B9DD454 FOREIGN KEY (user_profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE seeder ADD CONSTRAINT FK_8801CDCE29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE annotation ADD CONSTRAINT FK_2E443EF229C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE network_user_profile ADD CONSTRAINT FK_BC28636D34128B91 FOREIGN KEY (network_id) REFERENCES network (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); @@ -142,7 +142,7 @@ public function up(Schema $schema) $this->addSql('ALTER TABLE refresh_token ADD CONSTRAINT FK_C74F2195A76ED395 FOREIGN KEY (user_id) REFERENCES user_account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE access_token ADD CONSTRAINT FK_B6A2DD6819EB6921 FOREIGN KEY (client_id) REFERENCES client (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE access_token ADD CONSTRAINT FK_B6A2DD68A76ED395 FOREIGN KEY (user_id) REFERENCES user_account (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE channel ADD CONSTRAINT FK_A2F98E47CCFA12B8 FOREIGN KEY (profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE channel ADD CONSTRAINT FK_A2F98E476B9DD454 FOREIGN KEY (user_profile_id) REFERENCES user_profile (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE subtitles ADD CONSTRAINT FK_A739C98629C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); } @@ -156,16 +156,16 @@ public function down(Schema $schema) $this->addSql('CREATE SCHEMA public'); $this->addSql('ALTER TABLE reply DROP CONSTRAINT FK_FDA8C6E03E2E969B'); - $this->addSql('ALTER TABLE view DROP CONSTRAINT FK_FEFDAB8ECCFA12B8'); + $this->addSql('ALTER TABLE view DROP CONSTRAINT FK_FEFDAB8E6B9DD454'); $this->addSql('ALTER TABLE forum DROP CONSTRAINT FK_852BBECDB03A8386'); $this->addSql('ALTER TABLE comment DROP CONSTRAINT FK_9474526CF675F31B'); $this->addSql('ALTER TABLE playlist DROP CONSTRAINT FK_D782112D9B6B5FBA'); $this->addSql('ALTER TABLE reply DROP CONSTRAINT FK_FDA8C6E0F675F31B'); $this->addSql('ALTER TABLE review DROP CONSTRAINT FK_794381C6F675F31B'); - $this->addSql('ALTER TABLE sustainability_offer DROP CONSTRAINT FK_BDC3DF35CCFA12B8'); - $this->addSql('ALTER TABLE seeder DROP CONSTRAINT FK_8801CDCECCFA12B8'); + $this->addSql('ALTER TABLE sustainability_offer DROP CONSTRAINT FK_BDC3DF356B9DD454'); + $this->addSql('ALTER TABLE seeder DROP CONSTRAINT FK_8801CDCE6B9DD454'); $this->addSql('ALTER TABLE network_user_profile DROP CONSTRAINT FK_BC28636D6B9DD454'); - $this->addSql('ALTER TABLE channel DROP CONSTRAINT FK_A2F98E47CCFA12B8'); + $this->addSql('ALTER TABLE channel DROP CONSTRAINT FK_A2F98E476B9DD454'); $this->addSql('ALTER TABLE view DROP CONSTRAINT FK_FEFDAB8E29C1004E'); $this->addSql('ALTER TABLE forum DROP CONSTRAINT FK_852BBECD29C1004E'); $this->addSql('ALTER TABLE comment DROP CONSTRAINT FK_9474526C29C1004E'); @@ -174,7 +174,7 @@ public function down(Schema $schema) $this->addSql('ALTER TABLE seeder DROP CONSTRAINT FK_8801CDCE29C1004E'); $this->addSql('ALTER TABLE annotation DROP CONSTRAINT FK_2E443EF229C1004E'); $this->addSql('ALTER TABLE subtitles DROP CONSTRAINT FK_A739C98629C1004E'); - $this->addSql('ALTER TABLE user_profile DROP CONSTRAINT FK_D95AB4059B6B5FBA'); + $this->addSql('ALTER TABLE user_profile DROP CONSTRAINT FK_D95AB4053C0C9956'); $this->addSql('ALTER TABLE auth_code DROP CONSTRAINT FK_5933D02CA76ED395'); $this->addSql('ALTER TABLE refresh_token DROP CONSTRAINT FK_C74F2195A76ED395'); $this->addSql('ALTER TABLE access_token DROP CONSTRAINT FK_B6A2DD68A76ED395'); diff --git a/app/config/services.yml b/app/config/services.yml index a56c112..a4553a2 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -23,7 +23,7 @@ services: app.security.account_voter: class: AppBundle\Security\AccountVoter tags: - - { name: security.voter, voter: access } + - { name: security.voter } app.event_subscriber.account_checker: class: AppBundle\EventSubscriber\AccountChecker diff --git a/features/Channel.feature b/features/Channel.feature index 34f22b6..55e73d4 100644 --- a/features/Channel.feature +++ b/features/Channel.feature @@ -6,7 +6,7 @@ Feature: Manage channel Background: Given I am connected as "denis@denis.fr" with password "password" - And There are "profile" "/profiles/2" + And There are "user profile" "/user_profiles/2" @refreshSchema @requiresOAuth @@ -16,7 +16,7 @@ Feature: Manage channel And I send a "POST" request to "/channels" with body: """ { - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "name": "string", "tags": [ "string" @@ -32,7 +32,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "id": 1, "name": "string", "tags": [ @@ -88,7 +88,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "id": 1, "name": "string", "tags": [ @@ -116,7 +116,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "id": 1, "name": "string", "tags": [ @@ -147,7 +147,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "id": 1, "name": "string", "tags": [ @@ -184,7 +184,7 @@ Feature: Manage channel { "@id": "/channels/1", "@type": "Channel", - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "id": 1, "name": "string", "tags": [ @@ -206,9 +206,9 @@ Feature: Manage channel { "@id": "/channels/2", "@type": "Channel", - "profile": "/profiles/3", + "userProfile": "/user_profiles/3", "id": 2, - "name": "string18", + "name": "string4", "tags": [ "string" ], @@ -220,9 +220,9 @@ Feature: Manage channel { "@id": "/channels/3", "@type": "Channel", - "profile": "/profiles/4", + "userProfile": "/user_profiles/4", "id": 3, - "name": "string19", + "name": "string5", "tags": [ "string" ], @@ -234,9 +234,9 @@ Feature: Manage channel { "@id": "/channels/4", "@type": "Channel", - "profile": "/profiles/5", + "userProfile": "/user_profiles/5", "id": 4, - "name": "string20", + "name": "string6", "tags": [ "string" ], @@ -293,7 +293,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "id": 1, "name": "stringUpdated", "tags": [ @@ -337,7 +337,7 @@ Feature: Manage channel "name": "string", "channel": "/channels/1", "network": null, - "profile": null + "userProfile": null } """ @@ -354,7 +354,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "id": 1, "name": "stringUpdated", "tags": [ diff --git a/features/Comment.feature b/features/Comment.feature index 2a31fbd..d056bf7 100644 --- a/features/Comment.feature +++ b/features/Comment.feature @@ -19,7 +19,7 @@ Feature: Manage comment "content": "string", "dateComment": "2017-02-03T08:56:37.848Z", "video": "/videos/1", - "author": "/profiles/1" + "author": "/user_profiles/1" } """ Then the response status code should be 201 @@ -35,7 +35,7 @@ Feature: Manage comment "content": "string", "dateComment": "2017-02-03T08:56:37+00:00", "video": "/videos/1", - "author": "/profiles/1" + "author": "/user_profiles/1" } """ @@ -91,7 +91,7 @@ Feature: Manage comment "content": "string", "dateComment": "2017-02-03T08:56:37+01:00", "video": "/videos/1", - "author": "/profiles/1" + "author": "/user_profiles/1" } ], "hydra:totalItems": 1 @@ -120,7 +120,7 @@ Feature: Manage comment "content": "stringUpdated", "dateComment": "2017-02-03T08:56:37+01:00", "video": "/videos/1", - "author": "/profiles/1" + "author": "/user_profiles/1" } """ diff --git a/features/Forum.feature b/features/Forum.feature index 0364f80..e3a22f9 100644 --- a/features/Forum.feature +++ b/features/Forum.feature @@ -18,7 +18,7 @@ Feature: Manage forum { "name": "string", "video": "/videos/1", - "createdBy": "/profiles/1" + "createdBy": "/user_profiles/1" } """ Then the response status code should be 201 @@ -33,7 +33,7 @@ Feature: Manage forum "id": 1, "name": "string", "video": "/videos/1", - "createdBy": "/profiles/1" + "createdBy": "/user_profiles/1" } """ @@ -84,7 +84,7 @@ Feature: Manage forum "id": 1, "name": "string", "video": "/videos/1", - "createdBy": "/profiles/1" + "createdBy": "/user_profiles/1" } ], "hydra:totalItems": 1 @@ -112,7 +112,7 @@ Feature: Manage forum "id": 1, "name": "stringUpdated", "video": "/videos/1", - "createdBy": "/profiles/1" + "createdBy": "/user_profiles/1" } """ diff --git a/features/Network.feature b/features/Network.feature index 5a0fee3..153cb94 100644 --- a/features/Network.feature +++ b/features/Network.feature @@ -38,15 +38,15 @@ Feature: Manage network """ Scenario: Put a user - Given There are "profile" "/profiles/1,/profiles/2" + Given There are "user profile" "/user_profiles/1,/user_profiles/2" When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" And I send a "PUT" request to "/networks/1" with body: """ { "peoples": [ - "/profiles/1", - "/profiles/2" + "/user_profiles/1", + "/user_profiles/2" ] } """ @@ -63,8 +63,8 @@ Feature: Manage network "channels": [ "/channels/1" ], "name": "string", "peoples": [ - "/profiles/1", - "/profiles/2" + "/user_profiles/1", + "/user_profiles/2" ], "playlists": [] } @@ -90,8 +90,8 @@ Feature: Manage network "channels": [ "/channels/1" ], "name": "string", "peoples": [ - "/profiles/1", - "/profiles/2" + "/user_profiles/1", + "/user_profiles/2" ], "playlists": [] } @@ -117,8 +117,8 @@ Feature: Manage network "channels": [ "/channels/1" ], "name": "string", "peoples": [ - "/profiles/1", - "/profiles/2" + "/user_profiles/1", + "/user_profiles/2" ], "playlists": [ "/playlists/1", diff --git a/features/Playlist.feature b/features/Playlist.feature index 8f12dd9..8966268 100644 --- a/features/Playlist.feature +++ b/features/Playlist.feature @@ -6,7 +6,6 @@ Feature: Manage playlist Background: Given I am connected as "denis@denis.fr" with password "password" - And There are "profile" "/profiles/2" @refreshSchema @requiresOAuth @@ -17,7 +16,7 @@ Feature: Manage playlist """ { "name": "string", - "profile": "/profiles/1" + "userProfile": "/user_profiles/1" } """ Then the response status code should be 201 @@ -33,7 +32,7 @@ Feature: Manage playlist "name": "string", "channel": null, "network": null, - "profile": "/profiles/1" + "userProfile": "/user_profiles/1" } """ @@ -57,7 +56,7 @@ Feature: Manage playlist "name": "string", "channel": null, "network": null, - "profile": "/profiles/1" + "userProfile": "/user_profiles/1" } ], "hydra:totalItems": 1 @@ -86,7 +85,7 @@ Feature: Manage playlist "name": "stringUpdated", "channel": null, "network": null, - "profile": "/profiles/1" + "userProfile": "/user_profiles/1" } """ @@ -114,7 +113,7 @@ Feature: Manage playlist "name": "string", "channel": "/channels/1", "network": null, - "profile": null + "userProfile": null } """ @@ -142,7 +141,7 @@ Feature: Manage playlist "name": "string", "channel": null, "network": "/networks/1", - "profile": null + "userProfile": null } """ @@ -153,7 +152,7 @@ Feature: Manage playlist """ { "channel": "/channels/1", - "profile": "/profiles/1" + "userProfile": "/user_profiles/1" } """ Then the response status code should be 400 diff --git a/features/Reply.feature b/features/Reply.feature index fdf253c..2e1071c 100644 --- a/features/Reply.feature +++ b/features/Reply.feature @@ -18,7 +18,7 @@ Feature: Manage reply { "content": "string", "review": "/reviews/1", - "author": "/profiles/1", + "author": "/user_profiles/1", "dateReply": "2017-02-04T09:36:08.014Z" } """ @@ -34,7 +34,7 @@ Feature: Manage reply "id": 1, "content": "string", "review": "/reviews/1", - "author": "/profiles/1", + "author": "/user_profiles/1", "dateReply": "2017-02-04T09:36:08+00:00" } """ @@ -90,7 +90,7 @@ Feature: Manage reply "id": 1, "content": "string", "review": "/reviews/1", - "author": "/profiles/1", + "author": "/user_profiles/1", "dateReply": "2017-02-04T09:36:08+01:00" } ], @@ -119,7 +119,7 @@ Feature: Manage reply "id": 1, "content": "stringUpdated", "review": "/reviews/1", - "author": "/profiles/1", + "author": "/user_profiles/1", "dateReply": "2017-02-04T09:36:08+01:00" } """ diff --git a/features/Review.feature b/features/Review.feature index 1251a1f..3b3af32 100644 --- a/features/Review.feature +++ b/features/Review.feature @@ -19,7 +19,7 @@ Feature: Manage review "content": "string", "video": "/videos/1", "dateReview": "2017-02-04T09:36:08.044Z", - "author": "/profiles/1" + "author": "/user_profiles/1" } """ Then the response status code should be 201 @@ -36,7 +36,7 @@ Feature: Manage review "video": "/videos/1", "dateReview": "2017-02-04T09:36:08+00:00", "replies": [], - "author": "/profiles/1" + "author": "/user_profiles/1" } """ @@ -61,7 +61,7 @@ Feature: Manage review "/replies/1", "/replies/2" ], - "author": "/profiles/1" + "author": "/user_profiles/1" } """ @@ -123,7 +123,7 @@ Feature: Manage review "/replies/1", "/replies/2" ], - "author": "/profiles/1" + "author": "/user_profiles/1" } """ diff --git a/features/Seeder.feature b/features/Seeder.feature index f6c3d03..08422fa 100644 --- a/features/Seeder.feature +++ b/features/Seeder.feature @@ -17,7 +17,7 @@ Feature: Manage seeder """ { "platform": "string", - "profile": "/profiles/1", + "userProfile": "/user_profiles/1", "video": "/videos/1", "ip": "127.0.0.1" } @@ -33,7 +33,7 @@ Feature: Manage seeder "@type": "Seeder", "id": 1, "platform": "string", - "profile": "/profiles/1", + "userProfile": "/user_profiles/1", "ip": "127.0.0.1", "video": "/videos/1" } @@ -89,7 +89,7 @@ Feature: Manage seeder "@type": "Seeder", "id": 1, "platform": "string", - "profile": "/profiles/1", + "userProfile": "/user_profiles/1", "ip": "127.0.0.1", "video": "/videos/1" } @@ -118,7 +118,7 @@ Feature: Manage seeder "@type": "Seeder", "id": 1, "platform": "stringUpdated", - "profile": "/profiles/1", + "userProfile": "/user_profiles/1", "ip": "127.0.0.1", "video": "/videos/1" } diff --git a/features/SustainabilityOffer.feature b/features/SustainabilityOffer.feature index 4c11b38..bd15f5e 100644 --- a/features/SustainabilityOffer.feature +++ b/features/SustainabilityOffer.feature @@ -18,7 +18,7 @@ Feature: Manage substainability_offer { "name": "string", "duration": 0, - "profile": "/profiles/1", + "userProfile": "/user_profiles/1", "channel": "/channels/1" } """ @@ -34,7 +34,7 @@ Feature: Manage substainability_offer "id": 1, "name": "string", "duration": 0, - "profile": "/profiles/1", + "userProfile": "/user_profiles/1", "channel": "/channels/1" } """ @@ -90,7 +90,7 @@ Feature: Manage substainability_offer "id": 1, "name": "string", "duration": 0, - "profile": "/profiles/1", + "userProfile": "/user_profiles/1", "channel": "/channels/1" } ], @@ -119,7 +119,7 @@ Feature: Manage substainability_offer "id": 1, "name": "stringUpdated", "duration": 0, - "profile": "/profiles/1", + "userProfile": "/user_profiles/1", "channel": "/channels/1" } """ diff --git a/features/Account.feature b/features/UserAccount.feature similarity index 68% rename from features/Account.feature rename to features/UserAccount.feature index 0cc7bfb..bf7a5f9 100644 --- a/features/Account.feature +++ b/features/UserAccount.feature @@ -1,4 +1,4 @@ -# features/Account.feature +# features/UserAccount.feature Feature: Manage account In order to manage accounts As a client software developer @@ -12,7 +12,7 @@ Feature: Manage account Scenario: Create an account When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" - And I send a "POST" request to "/accounts" with body: + And I send a "POST" request to "/user_accounts" with body: """ { "email": "string@string.fr", @@ -26,9 +26,9 @@ Feature: Manage account And the JSON should be equal to: """ { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", + "@context": "/contexts/UserAccount", + "@id": "/user_accounts/2", + "@type": "UserAccount", "username": "string@string.fr", "email": "string@string.fr", "salt": "salt", @@ -37,14 +37,14 @@ Feature: Manage account ], "password": "password", "id": 2, - "profile": "/profiles/2" + "userProfile": null } """ Scenario: Throw errors when there is only bad properties When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" - And I send a "POST" request to "/accounts" with body: + And I send a "POST" request to "/user_accounts" with body: """ { } @@ -76,39 +76,39 @@ Feature: Manage account } """ - Scenario: Get his own account + Scenario: Get his own user_account When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/1" + And I send a "GET" request to "/user_accounts/1" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Account", - "@id": "/accounts/1", - "@type": "Account", - "username": "", + "@context": "/contexts/UserAccount", + "@id": "/user_accounts/1", + "@type": "UserAccount", + "username": "denis@denis.fr", "email": "denis@denis.fr", - "salt": "salt", + "salt": "iakegoihtfs4w44sgsg880wg", "roles": [ "ROLE_USER" ], - "password": "password", - "id": 2, - "profile": "/profiles/1" + "password": "hvXTcPLThKqPeuYBr6qebw3SBAC1PkXR78vlr5GongvcOLyOniqjJ4QTYNoNsqHewKO0K+b5HhfEJwRSk0NJjw==", + "id": 1, + "userProfile": "/user_profiles/1" } """ - Scenario: Get another account + Scenario: Get another user_account When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/accounts/2" + And I send a "GET" request to "/user_accounts/2" Then the response status code should be 403 - Scenario: Update his account + Scenario: Update his user_account When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" - And I send a "PUT" request to "/accounts/1" with body: + And I send a "PUT" request to "/user_accounts/1" with body: """ { } @@ -119,40 +119,35 @@ Feature: Manage account And the JSON should be equal to: """ { - "@context": "/contexts/Account", - "@id": "/accounts/2", - "@type": "Account", - "id": 2, - "username": "stringUpdated", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "channels": [], - "views": [], - "forums": [], - "networks": [], - "playlists": [], - "replies": [], - "reviews": [], - "sustainabilityOffers": [], - "seeders": [] + "@context": "/contexts/UserAccount", + "@id": "/user_accounts/1", + "@type": "UserAccount", + "username": "denis@denis.fr", + "email": "denis@denis.fr", + "salt": "iakegoihtfs4w44sgsg880wg", + "roles": [ + "ROLE_USER" + ], + "password": "hvXTcPLThKqPeuYBr6qebw3SBAC1PkXR78vlr5GongvcOLyOniqjJ4QTYNoNsqHewKO0K+b5HhfEJwRSk0NJjw==", + "id": 1, + "userProfile": "/user_profiles/1" } """ - Scenario: Update another account + Scenario: Update another user_account When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" - And I send a "PUT" request to "/accounts/2" with body: + And I send a "PUT" request to "/user_accounts/2" with body: """ { - "username": "stringUpdated" + "emai": "stringUpdated@denis.fr" } """ Then the response status code should be 403 - Scenario: Delete an account + Scenario: Delete an user_account When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" - And I send a "DELETE" request to "/accounts/2" + And I send a "DELETE" request to "/user_accounts/2" Then the response status code should be 403 diff --git a/features/Profile.feature b/features/UserProfile.feature similarity index 80% rename from features/Profile.feature rename to features/UserProfile.feature index c4ff800..580a9c2 100644 --- a/features/Profile.feature +++ b/features/UserProfile.feature @@ -1,23 +1,25 @@ -# features/Profile.feature -Feature: Manage Profile - In order to manage Profile +# features/UserProfile.feature +Feature: Manage UserProfile + In order to manage UserProfile As a client software developer I need to be able to retrieve, create, update and delete them trough the API. Background: Given I am connected as "denis@denis.fr" with password "password" + And There are "user account" "/user_accounts/2" @refreshSchema @requiresOAuth - Scenario: Create a profile + Scenario: Create a user_profile When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" - And I send a "POST" request to "/profiles" with body: + And I send a "POST" request to "/user_profiles" with body: """ { "username": "string", "firstName": "string", - "lastName": "string" + "lastName": "string", + "userAccount": "/user_accounts/2" } """ Then the response status code should be 201 @@ -26,9 +28,9 @@ Feature: Manage Profile And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "string", "channels": [], @@ -45,22 +47,22 @@ Feature: Manage Profile } """ - Scenario: Retrieve the profile list + Scenario: Retrieve the user profile list When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles" + And I send a "GET" request to "/user_profiles" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles", "@type": "hydra:Collection", "hydra:member": [ { - "@id": "/profiles/1", - "@type": "Profile", + "@id": "/user_profiles/1", + "@type": "UserProfile", "id": 1, "username": "denis", "channels": [], @@ -76,8 +78,8 @@ Feature: Manage Profile "lastName": "denis" }, { - "@id": "/profiles/2", - "@type": "Profile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "string", "channels": [], @@ -96,7 +98,7 @@ Feature: Manage Profile "hydra:totalItems": 2, "hydra:search": { "@type": "hydra:IriTemplate", - "hydra:template": "/profiles{?id,id[],username,firstName}", + "hydra:template": "/user_profiles{?id,id[],username,firstName}", "hydra:variableRepresentation": "BasicRepresentation", "hydra:mapping": [ { @@ -131,12 +133,10 @@ Feature: Manage Profile Scenario: Throw errors when there is only bad properties When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" - And I send a "POST" request to "/profiles" with body: + And I send a "POST" request to "/user_profiles" with body: """ { - "username": "string", - "firstName": "string", - "lastName": "string" + "username": "" } """ Then the response status code should be 400 @@ -166,10 +166,10 @@ Feature: Manage Profile } """ - Scenario: Update a profile + Scenario: Update a user_profile When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" - And I send a "PUT" request to "/profiles/2" with body: + And I send a "PUT" request to "/user_profiles/2" with body: """ { "username": "stringUpdated" @@ -181,9 +181,9 @@ Feature: Manage Profile And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [], @@ -200,18 +200,18 @@ Feature: Manage Profile } """ - Scenario: Get a specific profile + Scenario: Get a specific user_profile When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles/2" + And I send a "GET" request to "/user_profiles/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [], @@ -228,19 +228,19 @@ Feature: Manage Profile } """ - Scenario: See channel in profile - Given There are "channel" "/channels/1,/channels/2" which have "profile" "/profiles/2" + Scenario: See channel in user profile + Given There are "channel" "/channels/1,/channels/2" which have "user profile" "/user_profiles/2" When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles/2" + And I send a "GET" request to "/user_profiles/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [ @@ -260,19 +260,19 @@ Feature: Manage Profile } """ - Scenario: See view in profile - Given There are "view" "/views/1,/views/2" which have "profile" "/profiles/2" + Scenario: See view in user profile + Given There are "view" "/views/1,/views/2" which have "user profile" "/user_profiles/2" When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles/2" + And I send a "GET" request to "/user_profiles/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [ @@ -295,19 +295,19 @@ Feature: Manage Profile } """ - Scenario: See forum in profile - Given There are "forum" "/forums/1,/forums/2" which have "profile" "/profiles/2" + Scenario: See forum in user profile + Given There are "forum" "/forums/1,/forums/2" which have "user profile" "/user_profiles/2" When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles/2" + And I send a "GET" request to "/user_profiles/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [ @@ -334,18 +334,18 @@ Feature: Manage Profile """ Scenario: See network in profile - Given There are "network" "/networks/1,/networks/2" which have "profile" "/profiles/2" + Given There are "network" "/networks/1,/networks/2" which have "user profile" "/user_profiles/2" When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles/2" + And I send a "GET" request to "/user_profiles/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [ @@ -375,18 +375,18 @@ Feature: Manage Profile """ Scenario: See review in profile - Given There are "review" "/reviews/1,/reviews/2" which have "profile" "/profiles/2" + Given There are "review" "/reviews/1,/reviews/2" which have "user profile" "/user_profiles/2" When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles/2" + And I send a "GET" request to "/user_profiles/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [ @@ -419,18 +419,18 @@ Feature: Manage Profile """ Scenario: See reply in profile - Given There are "reply" "/replies/1,/replies/2" which have "profile" "/profiles/1,/profiles/2" + Given There are "reply" "/replies/1,/replies/2" which have "user profile" "/user_profiles/1,/user_profiles/2" When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles/2" + And I send a "GET" request to "/user_profiles/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [ @@ -466,18 +466,18 @@ Feature: Manage Profile """ Scenario: See Sustainability Offers in profile - Given There are "sustainability offer" "/sustainability_offers/1,/sustainability_offers/2" which have "profile" "/profiles/2" + Given There are "sustainability offer" "/sustainability_offers/1,/sustainability_offers/2" which have "user profile" "/user_profiles/2" When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles/2" + And I send a "GET" request to "/user_profiles/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [ @@ -516,18 +516,18 @@ Feature: Manage Profile """ Scenario: See seeder in profile - Given There are "seeder" "/seeders/1,/seeders/2" which have "profile" "/profiles/2" + Given There are "seeder" "/seeders/1,/seeders/2" which have "user profile" "/user_profiles/2" When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles/2" + And I send a "GET" request to "/user_profiles/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [ @@ -569,18 +569,18 @@ Feature: Manage Profile """ Scenario: See playlist in profile - Given There are "playlist" "/playlists/1,/playlist/2" which have "profile" "/profiles/2" + Given There are "playlist" "/playlists/1,/playlist/2" which have "user profile" "/user_profiles/2" When I add "Accept" header equal to "application/ld+json" - And I send a "GET" request to "/profiles/2" + And I send a "GET" request to "/user_profiles/2" Then the response status code should be 200 And the response should be in JSON And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" And the JSON should be equal to: """ { - "@context": "/contexts/Profile", - "@id": "/profiles/2", - "@type": "Profile", + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", "id": 2, "username": "stringUpdated", "channels": [ @@ -627,11 +627,11 @@ Feature: Manage Profile Scenario: Delete an profile When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" - And I send a "DELETE" request to "/profiles/2" + And I send a "DELETE" request to "/user_profiles/2" Then the response status code should be 204 Scenario: Delete an profile When I add "Content-Type" header equal to "application/ld+json" And I add "Accept" header equal to "application/ld+json" - And I send a "DELETE" request to "/profiles/2" + And I send a "DELETE" request to "/user_profiles/2" Then the response status code should be 404 diff --git a/features/View.feature b/features/View.feature index a3ca332..4d09cab 100644 --- a/features/View.feature +++ b/features/View.feature @@ -16,7 +16,7 @@ Feature: Manage view And I send a "POST" request to "/views" with body: """ { - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "video": "/videos/1" } """ @@ -30,7 +30,7 @@ Feature: Manage view "@id": "/views/1", "@type": "View", "id": 1, - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "video": "/videos/1" } """ @@ -52,7 +52,7 @@ Feature: Manage view "@id": "/views/1", "@type": "View", "id": 1, - "profile": "/profiles/2", + "userProfile": "/user_profiles/2", "video": "/videos/1" } ], diff --git a/features/bootstrap/ChannelHelper.php b/features/bootstrap/ChannelHelper.php index 5ea3d0c..bcd4a48 100644 --- a/features/bootstrap/ChannelHelper.php +++ b/features/bootstrap/ChannelHelper.php @@ -22,7 +22,7 @@ public function createResource() $name = 'string'.self::$numberChannel; $channel = new Channel(); - $channel->setProfile($profile)->setName($name)->setTags(['string']); + $channel->setUserProfile($profile)->setName($name)->setTags(['string']); ++self::$numberChannel; diff --git a/features/bootstrap/PlaylistHelper.php b/features/bootstrap/PlaylistHelper.php index dea5117..05ed9bf 100644 --- a/features/bootstrap/PlaylistHelper.php +++ b/features/bootstrap/PlaylistHelper.php @@ -18,11 +18,10 @@ public function __construct(EntityManager $em, UserProfileHelper $profileHelper) public function createResource() { - $profile = $this->profileHelper->persistResource(); $playlist = new Playlist(); - $playlist->setProfile($profile)->setName('string'); + $playlist->setUserProfile($profile)->setName('string'); return $playlist; } diff --git a/features/bootstrap/SeederHelper.php b/features/bootstrap/SeederHelper.php index 72fe50b..2ab981f 100644 --- a/features/bootstrap/SeederHelper.php +++ b/features/bootstrap/SeederHelper.php @@ -28,7 +28,7 @@ public function createResource() $video = $this->videoHelper->persistResource(); $seeder = new Seeder(); - $seeder->setPlatform('string')->setIp('127.0.0.1')->setProfile($profile)->setVideo($video); + $seeder->setPlatform('string')->setIp('127.0.0.1')->setUserProfile($profile)->setVideo($video); return $seeder; } diff --git a/features/bootstrap/SustainabilityOfferHelper.php b/features/bootstrap/SustainabilityOfferHelper.php index 1eb0a51..a793654 100644 --- a/features/bootstrap/SustainabilityOfferHelper.php +++ b/features/bootstrap/SustainabilityOfferHelper.php @@ -22,7 +22,7 @@ public function createResource() $sustainabilityOffer = new SustainabilityOffer(); $sustainabilityOffer->setName('string')->setDuration(0) - ->setProfile($channel->getProfile())->setChannel($channel); + ->setUserProfile($channel->getUserProfile())->setChannel($channel); return $sustainabilityOffer; } diff --git a/features/bootstrap/UserAccountHelper.php b/features/bootstrap/UserAccountHelper.php index 4f71cc4..de68e7e 100644 --- a/features/bootstrap/UserAccountHelper.php +++ b/features/bootstrap/UserAccountHelper.php @@ -6,26 +6,21 @@ class UserAccountHelper extends ResourceHelper { private static $numberAccount = 0; - private $profileHelper; - public function __construct(EntityManager $em, UserProfileHelper $profileHelper) + public function __construct(EntityManager $em) { parent::__construct($em); - $this->profileHelper = $profileHelper; } public function createResource() { - $profile = $this->profileHelper->persistResource(); - $email = 'string'.self::$numberAccount.'@example.com'; $account = new UserAccount(); - $account->setEmail($email)->setPassword('string')->setSalt('string')->setProfile($profile); + $account->setEmail($email)->setPassword('string')->setSalt('string'); ++self::$numberAccount; return $account; } - -} \ No newline at end of file +} diff --git a/features/bootstrap/UserProfileHelper.php b/features/bootstrap/UserProfileHelper.php index ab206d6..436e358 100644 --- a/features/bootstrap/UserProfileHelper.php +++ b/features/bootstrap/UserProfileHelper.php @@ -6,19 +6,23 @@ class UserProfileHelper extends ResourceHelper { private static $numberAccount = 0; + private $userAccountHelper; - public function __construct(EntityManager $em) + public function __construct(EntityManager $em, UserAccountHelper $userAccountHelper) { parent::__construct($em); + $this->userAccountHelper = $userAccountHelper; } public function createResource() { + $account = $this->userAccountHelper->persistResource(); + $username = 'string'.self::$numberAccount; $profile = new UserProfile(); $profile->setUsername($username)->setFirstName('string') - ->setLastName('string'); + ->setLastName('string')->setUserAccount($account); ++self::$numberAccount; diff --git a/features/bootstrap/ViewHelper.php b/features/bootstrap/ViewHelper.php index 8b1f5b1..1d0ab58 100644 --- a/features/bootstrap/ViewHelper.php +++ b/features/bootstrap/ViewHelper.php @@ -28,7 +28,7 @@ public function createResource() $video = $this->videoHelper->persistResource(); $view = new View(); - $view->setVideo($video)->setProfile($profile); + $view->setVideo($video)->setUserProfile($profile); return $view; } diff --git a/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php b/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php index aad6928..38350cc 100644 --- a/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php +++ b/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php @@ -12,22 +12,22 @@ class AccountData extends ContainerAwareFixture implements OrderedFixtureInterfa { public function load(ObjectManager $manager) { + $privateData = new UserAccount(); + $privateData + ->setEmail('denis@denis.fr') + ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) + ->setPassword($this->container->get('security.password_encoder')->encodePassword($privateData, 'password')) + ; $account = new UserProfile(); $account ->setFirstName('denis') ->setLastName('denis') ->setUsername('denis') + ->setUserAccount($privateData) ; - $privateData = new UserAccount(); - $privateData - ->setEmail('denis@denis.fr') - ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) - ->setPassword($this->container->get('security.password_encoder')->encodePassword($privateData, 'password')) - ->setProfile($account) - ; - $manager->persist($account); $manager->persist($privateData); + $manager->persist($account); $manager->flush(); } diff --git a/src/AppBundle/DataFixtures/ORM/fixtures.yml b/src/AppBundle/DataFixtures/ORM/fixtures.yml index 5c57791..9f2f339 100644 --- a/src/AppBundle/DataFixtures/ORM/fixtures.yml +++ b/src/AppBundle/DataFixtures/ORM/fixtures.yml @@ -1,29 +1,30 @@ -AppBundle\Entity\Profile: - profile_{1..10}: - username: - firstName: - lastName: - profile_michel: - username: michel - firstName: Michel - lastName: Michel -AppBundle\Entity\Account: +AppBundle\Entity\UserAccount: account_{1..10}: email: password: /ZPeKADSrd8e3wUM7f6DpK/0ukgbztjkSkasUz0Znugln//yx4zXtZTCUckmi/MsRkCCGaZQsTcSX2MTuXfwmw== salt: 12xiixme87nk4cs4sgws400ko - profile: '@profile_' account_michel: email: michel@yopmail.fr password: /ZPeKADSrd8e3wUM7f6DpK/0ukgbztjkSkasUz0Znugln//yx4zXtZTCUckmi/MsRkCCGaZQsTcSX2MTuXfwmw== salt: 12xiixme87nk4cs4sgws400ko - profile: '@profile_michel' + +AppBundle\Entity\UserProfile: + profile_{1..10}: + username: + firstName: + lastName: + userAccount: '@account_' + profile_michel: + username: michel + firstName: Michel + lastName: Michel + userAccount: '@account_michel' AppBundle\Entity\Channel: channel_michel: name: - profile: '@profile_michel' + userProfile: '@profile_michel' AppBundle\Entity\Category: category_michel: @@ -113,7 +114,7 @@ AppBundle\Entity\Seeder: seeder_{1..5}: platform: ip: - profile: '@profile_michel' + userProfile: '@profile_michel' video: '@video_michel' AppBundle\Entity\Subtitles: @@ -127,15 +128,15 @@ AppBundle\Entity\SustainabilityOffer: sustainability_offer_{1..5}: name: duration: 0 - profile: '@profile_michel' + userProfile: '@profile_michel' channel: '@channel_michel' AppBundle\Entity\View: view_{1..5}: - profile: '@profile_michel' + userProfile: '@profile_michel' video: '@video_michel' AppBundle\Entity\Playlist: playlist_{1..5}: name: - profile: '@profile_michel' + userProfile: '@profile_michel' diff --git a/src/AppBundle/Entity/Channel.php b/src/AppBundle/Entity/Channel.php index d1ff2c1..5525c6e 100644 --- a/src/AppBundle/Entity/Channel.php +++ b/src/AppBundle/Entity/Channel.php @@ -47,7 +47,7 @@ class Channel * * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="channels", cascade={"persist"}) */ - private $profile; + private $userProfile; /** * @var Video @@ -87,14 +87,14 @@ public function __construct() $this->sustainabilityOffers = new ArrayCollection(); } - public function getProfile(): UserProfile + public function getUserProfile(): UserProfile { - return $this->profile; + return $this->userProfile; } - public function setProfile(UserProfile $profile): Channel + public function setUserProfile(UserProfile $profile): Channel { - $this->profile = $profile; + $this->userProfile = $profile; return $this; } diff --git a/src/AppBundle/Entity/Playlist.php b/src/AppBundle/Entity/Playlist.php index a9bf8a1..42832b8 100644 --- a/src/AppBundle/Entity/Playlist.php +++ b/src/AppBundle/Entity/Playlist.php @@ -57,7 +57,7 @@ class Playlist * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="playlists", cascade={"persist"}) * @ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=true) */ - private $profile; + private $userProfile; public function getId(): int { @@ -107,14 +107,14 @@ public function setNetwork(Network $network): Playlist return $this; } - public function getProfile() + public function getUserProfile() { - return $this->profile; + return $this->userProfile; } - public function setProfile(UserProfile $profile): Playlist + public function setUserProfile(UserProfile $userProfile): Playlist { - $this->profile = $profile; + $this->userProfile = $userProfile; return $this; } diff --git a/src/AppBundle/Entity/Seeder.php b/src/AppBundle/Entity/Seeder.php index e784558..1c099dc 100644 --- a/src/AppBundle/Entity/Seeder.php +++ b/src/AppBundle/Entity/Seeder.php @@ -45,7 +45,7 @@ class Seeder * * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="seeders", cascade={"persist"}) */ - private $profile; + private $userProfile; /** * @var Video @@ -78,14 +78,14 @@ public function setPlatform(string $platform): Seeder return $this; } - public function getProfile(): UserProfile + public function getUserProfile(): UserProfile { - return $this->profile; + return $this->userProfile; } - public function setProfile(UserProfile $profile): Seeder + public function setUserProfile(UserProfile $userProfile): Seeder { - $this->profile = $profile; + $this->userProfile = $userProfile; return $this; } diff --git a/src/AppBundle/Entity/SustainabilityOffer.php b/src/AppBundle/Entity/SustainabilityOffer.php index d0d2822..b20c371 100644 --- a/src/AppBundle/Entity/SustainabilityOffer.php +++ b/src/AppBundle/Entity/SustainabilityOffer.php @@ -47,7 +47,7 @@ class SustainabilityOffer * * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="sustainabilityOffers", cascade={"persist"}) */ - private $profile; + private $userProfile; /** * @var Channel @@ -92,14 +92,14 @@ public function setDuration(int $duration): SustainabilityOffer return $this; } - public function getProfile(): UserProfile + public function getUserProfile(): UserProfile { - return $this->profile; + return $this->userProfile; } - public function setProfile(UserProfile $profile): SustainabilityOffer + public function setUserProfile(UserProfile $userProfile): SustainabilityOffer { - $this->profile = $profile; + $this->userProfile = $userProfile; return $this; } diff --git a/src/AppBundle/Entity/UserAccount.php b/src/AppBundle/Entity/UserAccount.php index c32763f..4aca575 100644 --- a/src/AppBundle/Entity/UserAccount.php +++ b/src/AppBundle/Entity/UserAccount.php @@ -7,12 +7,11 @@ use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; -use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * User's account. * - * @ORM\Entity(repositoryClass="AppBundle\Repository\AccountRepository") + * @ORM\Entity(repositoryClass="AppBundle\Repository\UserAccountRepository") * @ApiResource */ class UserAccount implements UserInterface @@ -64,10 +63,10 @@ class UserAccount implements UserInterface /** * @var UserProfile * - * @ORM\OneToOne(targetEntity="AppBundle\Entity\UserProfile", mappedBy="account", cascade={"persist"}) + * @ORM\OneToOne(targetEntity="AppBundle\Entity\UserProfile", mappedBy="userAccount", cascade={"persist"}) */ - private $profile; - + private $userProfile; + public function getUsername(): string { return $this->email; @@ -137,14 +136,14 @@ public function setId(int $id): UserAccount return $this; } - public function getProfile(): ?UserProfile + public function getUserProfile(): ?UserProfile { - return $this->profile; + return $this->userProfile; } - public function setProfile(UserProfile $profile): UserAccount + public function setUserProfile(UserProfile $userProfile): UserAccount { - $this->profile = $profile; + $this->userProfile = $userProfile; return $this; } diff --git a/src/AppBundle/Entity/UserProfile.php b/src/AppBundle/Entity/UserProfile.php index 86a5463..f849773 100644 --- a/src/AppBundle/Entity/UserProfile.php +++ b/src/AppBundle/Entity/UserProfile.php @@ -41,7 +41,7 @@ class UserProfile /** * @var ArrayCollection The list of the channels * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Channel", mappedBy="profile", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\Channel", mappedBy="userProfile", cascade={"persist"}) * @Groups({"account"}) */ private $channels; @@ -50,7 +50,7 @@ class UserProfile * @var ArrayCollection The list of views * * @Groups({"account"}) - * @ORM\OneToMany(targetEntity="AppBundle\Entity\View", mappedBy="profile", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\View", mappedBy="userProfile", cascade={"persist"}) */ private $views; @@ -74,7 +74,7 @@ class UserProfile /** * @var ArrayCollection * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Playlist", mappedBy="profile", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\Playlist", mappedBy="userProfile", cascade={"persist"}) * @Groups({"account"}) */ private $playlists; @@ -98,7 +98,7 @@ class UserProfile /** * @var ArrayCollection * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\SustainabilityOffer", mappedBy="profile", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\SustainabilityOffer", mappedBy="userProfile", cascade={"persist"}) * @Groups({"account"}) */ private $sustainabilityOffers; @@ -106,7 +106,7 @@ class UserProfile /** * @var ArrayCollection * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Seeder", mappedBy="profile", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\Seeder", mappedBy="userProfile", cascade={"persist"}) * @Groups({"account"}) */ private $seeders; @@ -136,10 +136,10 @@ class UserProfile /** * @var UserAccount * - * @ORM\OneToOne(targetEntity="AppBundle\Entity\UserAccount", inversedBy="profile", cascade={"persist"}) + * @ORM\OneToOne(targetEntity="AppBundle\Entity\UserAccount", inversedBy="userProfile", cascade={"persist"}) * @ORM\JoinColumn(nullable=false) */ - private $account; + private $userAccount; public function __construct() { @@ -310,16 +310,15 @@ public function setSeeders($seeders): UserProfile return $this; } - public function getAccount(): UserAccount + public function getUserAccount(): UserAccount { - return $this->account; + return $this->userAccount; } - public function setAccount(UserAccount $account): UserProfile + public function setUserAccount(UserAccount $userAccount): UserProfile { - $this->account = $account; + $this->userAccount = $userAccount; return $this; } - -} \ No newline at end of file +} diff --git a/src/AppBundle/Entity/View.php b/src/AppBundle/Entity/View.php index 49a2d89..e656972 100644 --- a/src/AppBundle/Entity/View.php +++ b/src/AppBundle/Entity/View.php @@ -27,7 +27,7 @@ class View * * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="views", cascade={"persist"}) */ - private $profile; + private $userProfile; /** * @var Video @@ -46,14 +46,14 @@ public function setId(int $id) $this->id = $id; } - public function getProfile(): UserProfile + public function getUserProfile(): UserProfile { - return $this->profile; + return $this->userProfile; } - public function setProfile(UserProfile $profile) + public function setUserProfile(UserProfile $userProfile) { - $this->profile = $profile; + $this->userProfile = $userProfile; return $this; } diff --git a/src/AppBundle/EventSubscriber/AccountChecker.php b/src/AppBundle/EventSubscriber/AccountChecker.php index 002b0bf..ebabadc 100644 --- a/src/AppBundle/EventSubscriber/AccountChecker.php +++ b/src/AppBundle/EventSubscriber/AccountChecker.php @@ -3,17 +3,12 @@ namespace AppBundle\EventSubscriber; use ApiPlatform\Core\EventListener\EventPriorities; -use AppBundle\Entity\UserProfile; -use AppBundle\Security\AccountVoter; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; -use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; class AccountChecker implements EventSubscriberInterface { @@ -34,15 +29,15 @@ public static function getSubscribedEvents() public function onKernelRequest(GetResponseEvent $event) { $method = $event->getRequest()->getMethod(); + $arrayPath = explode('/', $event->getRequest()->getPathInfo()); - if (Request::METHOD_POST === $method || $event->getRequest()->getPathInfo() === '/oauth/v2/token') { + if (Request::METHOD_POST === $method || $arrayPath[1] !== 'user_accounts') { return; } - if (!$this->authorizationChecker->isGranted('access', $event->getRequest()->getPathInfo())) { + if (!$this->authorizationChecker->isGranted('access', $arrayPath)) { $response = new Response('You don\'t have access to this account', Response::HTTP_FORBIDDEN); $event->setResponse($response); } - } -} \ No newline at end of file +} diff --git a/src/AppBundle/EventSubscriber/PasswordEncryption.php b/src/AppBundle/EventSubscriber/PasswordEncryption.php index 63e41ba..73a45bf 100644 --- a/src/AppBundle/EventSubscriber/PasswordEncryption.php +++ b/src/AppBundle/EventSubscriber/PasswordEncryption.php @@ -3,16 +3,11 @@ namespace AppBundle\EventSubscriber; use ApiPlatform\Core\EventListener\EventPriorities; -use AppBundle\Entity\UserProfile; -use AppBundle\Security\AccountVoter; +use AppBundle\Entity\UserAccount; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; -use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; class PasswordEncryption implements EventSubscriberInterface { @@ -25,10 +20,10 @@ public static function getSubscribedEvents() public function encryptPassword(GetResponseForControllerResultEvent $event) { - $account = $event->getControllerResult(); + /*$account = $event->getControllerResult(); $method = $event->getRequest()->getMethod(); - if (!$account instanceof Account || $method !== Request::METHOD_POST) { + if (!$account instanceof UserAccount || $method !== Request::METHOD_POST) { return; } @@ -36,6 +31,6 @@ public function encryptPassword(GetResponseForControllerResultEvent $event) ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) ->setPassword($this->container->get('security.password_encoder') ->encodePassword($account, 'password')) - ; + ;*/ } -} \ No newline at end of file +} diff --git a/src/AppBundle/Repository/AccountRepository.php b/src/AppBundle/Repository/UserAccountRepository.php similarity index 92% rename from src/AppBundle/Repository/AccountRepository.php rename to src/AppBundle/Repository/UserAccountRepository.php index 8e31fe0..4f6777d 100644 --- a/src/AppBundle/Repository/AccountRepository.php +++ b/src/AppBundle/Repository/UserAccountRepository.php @@ -4,7 +4,7 @@ use Doctrine\ORM\EntityRepository; -class AccountRepository extends EntityRepository +class UserAccountRepository extends EntityRepository { public function findOneByUsername(string $username) { diff --git a/src/AppBundle/Security/AccountProvider.php b/src/AppBundle/Security/AccountProvider.php index 9753885..2dd36f1 100644 --- a/src/AppBundle/Security/AccountProvider.php +++ b/src/AppBundle/Security/AccountProvider.php @@ -3,7 +3,6 @@ namespace AppBundle\Security; use AppBundle\Entity\UserAccount; -use AppBundle\Entity\UserProfile; use Doctrine\ORM\EntityManager; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; @@ -22,7 +21,6 @@ public function __construct(EntityManager $em) public function loadUserByUsername($username) { $account = $this->repository->findOneByEmail($username); - if (null === $account) { throw new UsernameNotFoundException('No account found for email'); } @@ -32,7 +30,7 @@ public function loadUserByUsername($username) public function refreshUser(UserInterface $user) { - if (!$user instanceof UserProfile) { + if (!$user instanceof UserAccount) { throw new UnsupportedUserException( sprintf('Instances of "%s" are not supported.', get_class($user)) ); diff --git a/src/AppBundle/Security/AccountVoter.php b/src/AppBundle/Security/AccountVoter.php index f875599..ab72ed6 100644 --- a/src/AppBundle/Security/AccountVoter.php +++ b/src/AppBundle/Security/AccountVoter.php @@ -3,8 +3,6 @@ namespace AppBundle\Security; use AppBundle\Entity\UserAccount; -use AppBundle\Entity\UserProfile; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\Voter\Voter; @@ -18,7 +16,7 @@ protected function supports($attribute, $subject) return false; } - if ($subject === null) { + if ($subject === null || !isset($subject[2])) { return false; } @@ -33,11 +31,8 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token) return false; } - $profileId = explode('/', $subject)[2]; - - if ($attribute === self::ACCESS) { - return $this->canAccess($profileId, $user); + return $this->canAccess($subject[2], $user); } throw new \LogicException('This code should not be reached!'); @@ -45,6 +40,6 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token) private function canAccess(string $profileId, UserAccount $account) { - return $account->getId() === intval($profileId); + return $account->getId() === (int) $profileId; } -} \ No newline at end of file +} diff --git a/src/AppBundle/Validator/Constraints/PlaylistClassValidator.php b/src/AppBundle/Validator/Constraints/PlaylistClassValidator.php index 40c0208..eaa93ac 100644 --- a/src/AppBundle/Validator/Constraints/PlaylistClassValidator.php +++ b/src/AppBundle/Validator/Constraints/PlaylistClassValidator.php @@ -9,7 +9,7 @@ class PlaylistClassValidator extends ConstraintValidator { public function validate($playlist, Constraint $constraint) { - if (!$this->ternaryXor($playlist->getChannel(), $playlist->getNetwork(), $playlist->getProfile())) { + if (!$this->ternaryXor($playlist->getChannel(), $playlist->getNetwork(), $playlist->getUserProfile())) { $this->context->buildViolation($constraint->message)->atPath('Playlist')->addViolation(); } } diff --git a/var/sessions/.gitkeep b/var/sessions/.gitkeep deleted file mode 100644 index e69de29..0000000