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/Version20170325155608.php b/app/DoctrineMigrations/Version20170804145916.php similarity index 61% rename from app/DoctrineMigrations/Version20170325155608.php rename to app/DoctrineMigrations/Version20170804145916.php index a43c84c..7738bde 100644 --- a/app/DoctrineMigrations/Version20170325155608.php +++ b/app/DoctrineMigrations/Version20170804145916.php @@ -8,7 +8,7 @@ /** * Auto-generated Migration: Please modify to your needs! */ -class Version20170325155608 extends AbstractMigration +class Version20170804145916 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, 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 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, 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_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 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, 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)'); + $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, 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_A2F98E479B6B5FBA ON channel (account_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 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_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 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_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 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_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 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_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'); } /** @@ -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_FEFDAB8E6B9DD454'); $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_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_A2F98E476B9DD454'); $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_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'); + $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 9add31b..a4553a2 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -18,4 +18,20 @@ 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 + tags: + - { name: security.voter } + + app.event_subscriber.account_checker: + class: AppBundle\EventSubscriber\AccountChecker + arguments: [ "@security.authorization_checker" ] + tags: + - { name: kernel.event_listener, event: kernel.request } + + app.event_subscriber.password_encryption: + class: AppBundle\EventSubscriber\PasswordEncryption + tags: + - { name: kernel.event_listener, event: kernel.view } 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/Account.feature b/features/Account.feature deleted file mode 100644 index f3949c8..0000000 --- a/features/Account.feature +++ /dev/null @@ -1,670 +0,0 @@ -# features/Account.feature -Feature: Manage account - In order to manage accounts - 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 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: - """ - { - "username": "string", - "email": "string@string.fr", - "firstName": "string", - "lastName": "string", - "password": "password", - "salt": "salt" - } - """ - 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/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": [] - } - """ - - 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/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..55e73d4 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 "user profile" "/user_profiles/2" @refreshSchema @requiresOAuth @@ -16,7 +16,7 @@ Feature: Manage channel And I send a "POST" request to "/channels" with body: """ { - "account": "/accounts/2", + "userProfile": "/user_profiles/2", "name": "string", "tags": [ "string" @@ -32,7 +32,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "account": "/accounts/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", - "account": "/accounts/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", - "account": "/accounts/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", - "account": "/accounts/2", + "userProfile": "/user_profiles/2", "id": 1, "name": "string", "tags": [ @@ -184,7 +184,7 @@ Feature: Manage channel { "@id": "/channels/1", "@type": "Channel", - "account": "/accounts/2", + "userProfile": "/user_profiles/2", "id": 1, "name": "string", "tags": [ @@ -206,9 +206,9 @@ Feature: Manage channel { "@id": "/channels/2", "@type": "Channel", - "account": "/accounts/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", - "account": "/accounts/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", - "account": "/accounts/5", + "userProfile": "/user_profiles/5", "id": 4, - "name": "string20", + "name": "string6", "tags": [ "string" ], @@ -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", + "userProfile": "/user_profiles/2", "id": 1, "name": "stringUpdated", "tags": [ @@ -349,7 +337,7 @@ Feature: Manage channel "name": "string", "channel": "/channels/1", "network": null, - "account": null + "userProfile": null } """ @@ -366,7 +354,7 @@ Feature: Manage channel "@context": "/contexts/Channel", "@id": "/channels/1", "@type": "Channel", - "account": "/accounts/2", + "userProfile": "/user_profiles/2", "id": 1, "name": "stringUpdated", "tags": [ diff --git a/features/Comment.feature b/features/Comment.feature index 780c427..d056bf7 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": "/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": "/accounts/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": "/accounts/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": "/accounts/1" + "author": "/user_profiles/1" } """ diff --git a/features/Forum.feature b/features/Forum.feature index 3982b30..e3a22f9 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": "/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": "/accounts/1" + "createdBy": "/user_profiles/1" } """ @@ -84,7 +84,7 @@ Feature: Manage forum "id": 1, "name": "string", "video": "/videos/1", - "createdBy": "/accounts/1" + "createdBy": "/user_profiles/1" } ], "hydra:totalItems": 1 @@ -112,7 +112,7 @@ Feature: Manage forum "id": 1, "name": "stringUpdated", "video": "/videos/1", - "createdBy": "/accounts/1" + "createdBy": "/user_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..153cb94 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 "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": [ - "/accounts/1", - "/accounts/2" + "/user_profiles/1", + "/user_profiles/2" ] } """ @@ -63,8 +63,8 @@ Feature: Manage network "channels": [ "/channels/1" ], "name": "string", "peoples": [ - "/accounts/1", - "/accounts/2" + "/user_profiles/1", + "/user_profiles/2" ], "playlists": [] } @@ -90,8 +90,8 @@ Feature: Manage network "channels": [ "/channels/1" ], "name": "string", "peoples": [ - "/accounts/1", - "/accounts/2" + "/user_profiles/1", + "/user_profiles/2" ], "playlists": [] } @@ -117,8 +117,8 @@ Feature: Manage network "channels": [ "/channels/1" ], "name": "string", "peoples": [ - "/accounts/1", - "/accounts/2" + "/user_profiles/1", + "/user_profiles/2" ], "playlists": [ "/playlists/1", diff --git a/features/Playlist.feature b/features/Playlist.feature index a8ebce0..8966268 100644 --- a/features/Playlist.feature +++ b/features/Playlist.feature @@ -5,8 +5,7 @@ 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" @refreshSchema @requiresOAuth @@ -17,7 +16,7 @@ Feature: Manage playlist """ { "name": "string", - "account": "/accounts/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, - "account": "/accounts/1" + "userProfile": "/user_profiles/1" } """ @@ -57,7 +56,7 @@ Feature: Manage playlist "name": "string", "channel": null, "network": null, - "account": "/accounts/1" + "userProfile": "/user_profiles/1" } ], "hydra:totalItems": 1 @@ -86,7 +85,7 @@ Feature: Manage playlist "name": "stringUpdated", "channel": null, "network": null, - "account": "/accounts/1" + "userProfile": "/user_profiles/1" } """ @@ -114,7 +113,7 @@ Feature: Manage playlist "name": "string", "channel": "/channels/1", "network": null, - "account": null + "userProfile": null } """ @@ -142,7 +141,7 @@ Feature: Manage playlist "name": "string", "channel": null, "network": "/networks/1", - "account": null + "userProfile": null } """ @@ -153,7 +152,7 @@ Feature: Manage playlist """ { "channel": "/channels/1", - "account": "/accounts/1" + "userProfile": "/user_profiles/1" } """ Then the response status code should be 400 diff --git a/features/Reply.feature b/features/Reply.feature index 2eee6fb..2e1071c 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": "/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": "/accounts/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": "/accounts/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": "/accounts/1", + "author": "/user_profiles/1", "dateReply": "2017-02-04T09:36:08+01:00" } """ diff --git a/features/Review.feature b/features/Review.feature index 885bbaf..3b3af32 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": "/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": "/accounts/1" + "author": "/user_profiles/1" } """ @@ -61,7 +61,7 @@ Feature: Manage review "/replies/1", "/replies/2" ], - "author": "/accounts/1" + "author": "/user_profiles/1" } """ @@ -123,7 +123,7 @@ Feature: Manage review "/replies/1", "/replies/2" ], - "author": "/accounts/1" + "author": "/user_profiles/1" } """ diff --git a/features/Seeder.feature b/features/Seeder.feature index db4fdca..08422fa 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", + "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", - "account": "/accounts/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", - "account": "/accounts/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", - "account": "/accounts/1", + "userProfile": "/user_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..bd15f5e 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", + "userProfile": "/user_profiles/1", "channel": "/channels/1" } """ @@ -34,7 +34,7 @@ Feature: Manage substainability_offer "id": 1, "name": "string", "duration": 0, - "account": "/accounts/1", + "userProfile": "/user_profiles/1", "channel": "/channels/1" } """ @@ -90,7 +90,7 @@ Feature: Manage substainability_offer "id": 1, "name": "string", "duration": 0, - "account": "/accounts/1", + "userProfile": "/user_profiles/1", "channel": "/channels/1" } ], @@ -119,7 +119,7 @@ Feature: Manage substainability_offer "id": 1, "name": "stringUpdated", "duration": 0, - "account": "/accounts/1", + "userProfile": "/user_profiles/1", "channel": "/channels/1" } """ diff --git a/features/UserAccount.feature b/features/UserAccount.feature new file mode 100644 index 0000000..bf7a5f9 --- /dev/null +++ b/features/UserAccount.feature @@ -0,0 +1,153 @@ +# features/UserAccount.feature +Feature: Manage account + In order to manage accounts + 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" + + @refreshSchema + @requiresOAuth + 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 "/user_accounts" with body: + """ + { + "email": "string@string.fr", + "password": "password", + "salt": "salt" + } + """ + 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/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/UserAccount", + "@id": "/user_accounts/2", + "@type": "UserAccount", + "username": "string@string.fr", + "email": "string@string.fr", + "salt": "salt", + "roles": [ + "ROLE_USER" + ], + "password": "password", + "id": 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 "/user_accounts" with body: + """ + { + } + """ + 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": "email: This value should not be blank.\nsalt: This value should not be blank.\npassword: This value should not be blank.", + "violations": [ + { + "propertyPath": "email", + "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: Get his own user_account + When I add "Accept" header equal to "application/ld+json" + 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/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: Get another user_account + When I add "Accept" header equal to "application/ld+json" + And I send a "GET" request to "/user_accounts/2" + Then the response status code should be 403 + + 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 "/user_accounts/1" with body: + """ + { + } + """ + 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/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 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 "/user_accounts/2" with body: + """ + { + "emai": "stringUpdated@denis.fr" + } + """ + Then the response status code should be 403 + + + 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 "/user_accounts/2" + Then the response status code should be 403 diff --git a/features/UserProfile.feature b/features/UserProfile.feature new file mode 100644 index 0000000..580a9c2 --- /dev/null +++ b/features/UserProfile.feature @@ -0,0 +1,637 @@ +# 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 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 "/user_profiles" with body: + """ + { + "username": "string", + "firstName": "string", + "lastName": "string", + "userAccount": "/user_accounts/2" + } + """ + 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/ld+json; charset=utf-8" + And the JSON should be equal to: + """ + { + "@context": "/contexts/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "id": 2, + "username": "string", + "channels": [], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: Retrieve the user profile list + When I add "Accept" header equal to "application/ld+json" + 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/UserProfile", + "@id": "/user_profiles", + "@type": "hydra:Collection", + "hydra:member": [ + { + "@id": "/user_profiles/1", + "@type": "UserProfile", + "id": 1, + "username": "denis", + "channels": [], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "denis", + "lastName": "denis" + }, + { + "@id": "/user_profiles/2", + "@type": "UserProfile", + "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": "/user_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 "/user_profiles" with body: + """ + { + "username": "" + } + """ + 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 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 "/user_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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "id": 2, + "username": "stringUpdated", + "channels": [], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + Scenario: Get a specific user_profile + When I add "Accept" header equal to "application/ld+json" + 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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "id": 2, + "username": "stringUpdated", + "channels": [], + "views": [], + "forums": [], + "networks": [], + "playlists": [], + "replies": [], + "reviews": [], + "sustainabilityOffers": [], + "seeders": [], + "firstName": "string", + "lastName": "string" + } + """ + + 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 "/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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "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 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 "/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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "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 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 "/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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "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 "user profile" "/user_profiles/2" + When I add "Accept" header equal to "application/ld+json" + 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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "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 "user profile" "/user_profiles/2" + When I add "Accept" header equal to "application/ld+json" + 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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "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 "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 "/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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "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 "user profile" "/user_profiles/2" + When I add "Accept" header equal to "application/ld+json" + 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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "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 "user profile" "/user_profiles/2" + When I add "Accept" header equal to "application/ld+json" + 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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "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 "user profile" "/user_profiles/2" + When I add "Accept" header equal to "application/ld+json" + 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/UserProfile", + "@id": "/user_profiles/2", + "@type": "UserProfile", + "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 "/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 "/user_profiles/2" + Then the response status code should be 404 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..4d09cab 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", + "userProfile": "/user_profiles/2", "video": "/videos/1" } """ @@ -30,7 +30,7 @@ Feature: Manage view "@id": "/views/1", "@type": "View", "id": 1, - "account": "/accounts/2", + "userProfile": "/user_profiles/2", "video": "/videos/1" } """ @@ -52,7 +52,7 @@ Feature: Manage view "@id": "/views/1", "@type": "View", "id": 1, - "account": "/accounts/2", + "userProfile": "/user_profiles/2", "video": "/videos/1" } ], diff --git a/features/bootstrap/ChannelHelper.php b/features/bootstrap/ChannelHelper.php index dc10fc3..bcd4a48 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, UserProfileHelper $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->setUserProfile($profile)->setName($name)->setTags(['string']); ++self::$numberChannel; diff --git a/features/bootstrap/CommentHelper.php b/features/bootstrap/CommentHelper.php index 205d5ad..fccd1a0 100644 --- a/features/bootstrap/CommentHelper.php +++ b/features/bootstrap/CommentHelper.php @@ -6,31 +6,31 @@ class CommentHelper extends ResourceHelper { /** - * @var AccountHelper + * @var UserProfileHelper */ - private $accountHelper; + private $profileHelper; /** * @var VideoHelper */ private $videoHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, UserProfileHelper $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..cb6ef7d 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -67,21 +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['Channel'] = new ChannelHelper($this->manager, $this->helpers['Account']); - $this->helpers['Playlist'] = new PlaylistHelper($this->manager, $this->helpers['Account']); + $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['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['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['Account'], $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 4973007..aa021ea 100644 --- a/features/bootstrap/ForumHelper.php +++ b/features/bootstrap/ForumHelper.php @@ -6,7 +6,7 @@ class ForumHelper extends ResourceHelper { /** - * @var AccountHelper + * @var UserProfileHelper */ 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, 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 == 'Account') { + 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 == 'Account') { + if ($nameResource2 == 'UserProfile') { return parent::relationExists($resource, 'CreatedBy', $resource2); } diff --git a/features/bootstrap/NetworkHelper.php b/features/bootstrap/NetworkHelper.php index 47b4147..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 == 'Account') { + 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 == 'Account') { + if ($nameResource2 == 'UserProfile') { return parent::relationExists($resource, 'Peoples', $resource2); } diff --git a/features/bootstrap/PlaylistHelper.php b/features/bootstrap/PlaylistHelper.php index ad55ab1..05ed9bf 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, UserProfileHelper $profileHelper) { parent::__construct($em); - $this->accountHelper = $accountHelper; + $this->profileHelper = $profileHelper; } public function createResource() { - $account = $this->accountHelper->persistResource(); + $profile = $this->profileHelper->persistResource(); $playlist = new Playlist(); - $playlist->setAccount($account)->setName('string'); + $playlist->setUserProfile($profile)->setName('string'); return $playlist; } diff --git a/features/bootstrap/ReplyHelper.php b/features/bootstrap/ReplyHelper.php index ddbca19..8f61e95 100644 --- a/features/bootstrap/ReplyHelper.php +++ b/features/bootstrap/ReplyHelper.php @@ -6,36 +6,36 @@ class ReplyHelper extends ResourceHelper { /** - * @var AccountHelper + * @var UserProfileHelper */ - private $accountHelper; + private $profileHelper; /** * @var ReviewHelper */ private $reviewHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, ReviewHelper $reviewHelper) + public function __construct(EntityManager $em, UserProfileHelper $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 == '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 == 'Account') { + if ($nameResource2 == 'UserProfile') { return parent::relationExists($resource, 'Author', $resource2); } diff --git a/features/bootstrap/ReviewHelper.php b/features/bootstrap/ReviewHelper.php index 5e39a4c..3151337 100644 --- a/features/bootstrap/ReviewHelper.php +++ b/features/bootstrap/ReviewHelper.php @@ -6,36 +6,36 @@ class ReviewHelper extends ResourceHelper { /** - * @var AccountHelper + * @var UserProfileHelper */ - private $accountHelper; + private $profileHelper; /** * @var VideoHelper */ private $videoHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, UserProfileHelper $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 == '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 == 'Account') { + if ($nameResource2 == 'UserProfile') { return parent::relationExists($resource, 'Author', $resource2); } diff --git a/features/bootstrap/SeederHelper.php b/features/bootstrap/SeederHelper.php index 04af2f2..2ab981f 100644 --- a/features/bootstrap/SeederHelper.php +++ b/features/bootstrap/SeederHelper.php @@ -6,29 +6,29 @@ class SeederHelper extends ResourceHelper { /** - * @var AccountHelper + * @var UserProfileHelper */ - private $accountHelper; + private $profileHelper; /** * @var VideoHelper */ private $videoHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, UserProfileHelper $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')->setUserProfile($profile)->setVideo($video); return $seeder; } diff --git a/features/bootstrap/SustainabilityOfferHelper.php b/features/bootstrap/SustainabilityOfferHelper.php index 9eef9cf..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) - ->setAccount($channel->getAccount())->setChannel($channel); + ->setUserProfile($channel->getUserProfile())->setChannel($channel); return $sustainabilityOffer; } diff --git a/features/bootstrap/AccountHelper.php b/features/bootstrap/UserAccountHelper.php similarity index 52% rename from features/bootstrap/AccountHelper.php rename to features/bootstrap/UserAccountHelper.php index 0d6bb84..de68e7e 100644 --- a/features/bootstrap/AccountHelper.php +++ b/features/bootstrap/UserAccountHelper.php @@ -1,9 +1,9 @@ setUsername($username)->setEmail($email)->setFirstName('string') - ->setLastName('string')->setPassword('string')->setSalt('string'); + $account = new UserAccount(); + $account->setEmail($email)->setPassword('string')->setSalt('string'); ++self::$numberAccount; diff --git a/features/bootstrap/UserProfileHelper.php b/features/bootstrap/UserProfileHelper.php new file mode 100644 index 0000000..436e358 --- /dev/null +++ b/features/bootstrap/UserProfileHelper.php @@ -0,0 +1,31 @@ +userAccountHelper = $userAccountHelper; + } + + public function createResource() + { + $account = $this->userAccountHelper->persistResource(); + + $username = 'string'.self::$numberAccount; + + $profile = new UserProfile(); + $profile->setUsername($username)->setFirstName('string') + ->setLastName('string')->setUserAccount($account); + + ++self::$numberAccount; + + return $profile; + } +} diff --git a/features/bootstrap/ViewHelper.php b/features/bootstrap/ViewHelper.php index 1cddcff..1d0ab58 100644 --- a/features/bootstrap/ViewHelper.php +++ b/features/bootstrap/ViewHelper.php @@ -6,29 +6,29 @@ class ViewHelper extends ResourceHelper { /** - * @var AccountHelper + * @var UserProfileHelper */ - private $accountHelper; + private $profileHelper; /** * @var VideoHelper */ private $videoHelper; - public function __construct(EntityManager $em, AccountHelper $accountHelper, VideoHelper $videoHelper) + public function __construct(EntityManager $em, UserProfileHelper $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)->setUserProfile($profile); return $view; } diff --git a/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php b/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php index 70bc88e..38350cc 100644 --- a/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php +++ b/src/AppBundle/DataFixtures/ORM/Fixtures/AccountData.php @@ -2,7 +2,8 @@ namespace AppBundle\DataFixtures\ORM\Fixtures; -use AppBundle\Entity\Account; +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; @@ -11,16 +12,23 @@ class AccountData extends ContainerAwareFixture implements OrderedFixtureInterfa { public function load(ObjectManager $manager) { - $account = new Account(); + $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') - ->setEmail('denis@denis.fr') - ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) - ->setPassword($this->container->get('security.password_encoder')->encodePassword($account, 'password')) + ->setUserAccount($privateData) ; + + $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 492171a..9f2f339 100644 --- a/src/AppBundle/DataFixtures/ORM/fixtures.yml +++ b/src/AppBundle/DataFixtures/ORM/fixtures.yml @@ -1,23 +1,30 @@ -AppBundle\Entity\Account: + +AppBundle\Entity\UserAccount: account_{1..10}: - username: email: - firstName: - lastName: password: /ZPeKADSrd8e3wUM7f6DpK/0ukgbztjkSkasUz0Znugln//yx4zXtZTCUckmi/MsRkCCGaZQsTcSX2MTuXfwmw== salt: 12xiixme87nk4cs4sgws400ko account_michel: - username: michel email: michel@yopmail.fr - firstName: Michel - lastName: Michel password: /ZPeKADSrd8e3wUM7f6DpK/0ukgbztjkSkasUz0Znugln//yx4zXtZTCUckmi/MsRkCCGaZQsTcSX2MTuXfwmw== salt: 12xiixme87nk4cs4sgws400ko +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: - account: '@account_michel' + userProfile: '@profile_michel' AppBundle\Entity\Category: category_michel: @@ -75,18 +82,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 +101,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' + userProfile: '@profile_michel' video: '@video_michel' AppBundle\Entity\Subtitles: @@ -121,15 +128,15 @@ AppBundle\Entity\SustainabilityOffer: sustainability_offer_{1..5}: name: duration: 0 - account: '@account_michel' + userProfile: '@profile_michel' channel: '@channel_michel' AppBundle\Entity\View: view_{1..5}: - account: '@account_michel' + userProfile: '@profile_michel' video: '@video_michel' AppBundle\Entity\Playlist: playlist_{1..5}: name: - account: '@account_michel' + userProfile: '@profile_michel' 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..5525c6e 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 UserProfile The owner's account * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="channels", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="channels", cascade={"persist"}) */ - private $account; + private $userProfile; /** * @var Video @@ -87,14 +87,14 @@ public function __construct() $this->sustainabilityOffers = new ArrayCollection(); } - public function getAccount(): Account + public function getUserProfile(): UserProfile { - return $this->account; + return $this->userProfile; } - public function setAccount(Account $account) + public function setUserProfile(UserProfile $profile): Channel { - $this->account = $account; + $this->userProfile = $profile; return $this; } diff --git a/src/AppBundle/Entity/Comment.php b/src/AppBundle/Entity/Comment.php index 4e9c3c6..3b42906 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 UserProfile Author of the comment * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account") + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile") */ private $author; @@ -104,12 +104,12 @@ public function setVideo(Video $video): Comment return $this; } - public function getAuthor(): Account + public function getAuthor(): UserProfile { return $this->author; } - public function setAuthor(Account $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 3fc4d2b..b009bc2 100644 --- a/src/AppBundle/Entity/Forum.php +++ b/src/AppBundle/Entity/Forum.php @@ -42,9 +42,9 @@ class Forum private $video; /** - * @var Account + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="forums", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", 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(UserProfile $createdBy): Forum { $this->createdBy = $createdBy; diff --git a/src/AppBundle/Entity/Network.php b/src/AppBundle/Entity/Network.php index 46bed43..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\Account", inversedBy="networks", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity="AppBundle\Entity\UserProfile", 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/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 949df68..42832b8 100644 --- a/src/AppBundle/Entity/Playlist.php +++ b/src/AppBundle/Entity/Playlist.php @@ -52,12 +52,12 @@ class Playlist private $network; /** - * @var Account + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="playlists", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="playlists", cascade={"persist"}) * @ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=true) */ - private $account; + private $userProfile; public function getId(): int { @@ -107,14 +107,14 @@ public function setNetwork(Network $network): Playlist return $this; } - public function getAccount() + public function getUserProfile() { - return $this->account; + return $this->userProfile; } - public function setAccount(Account $account): Playlist + public function setUserProfile(UserProfile $userProfile): Playlist { - $this->account = $account; + $this->userProfile = $userProfile; return $this; } diff --git a/src/AppBundle/Entity/Reply.php b/src/AppBundle/Entity/Reply.php index 0c97e78..72f2f6f 100644 --- a/src/AppBundle/Entity/Reply.php +++ b/src/AppBundle/Entity/Reply.php @@ -41,9 +41,9 @@ class Reply private $review; /** - * @var Account + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", 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(): Account + public function getAuthor(): UserProfile { return $this->author; } - public function setAuthor($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 e4e70bd..4738310 100644 --- a/src/AppBundle/Entity/Review.php +++ b/src/AppBundle/Entity/Review.php @@ -42,9 +42,9 @@ class Review private $video; /** - * @var Account + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", 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(): Account + public function getAuthor(): UserProfile { return $this->author; } - public function setAuthor(Account $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 6c17471..1c099dc 100644 --- a/src/AppBundle/Entity/Seeder.php +++ b/src/AppBundle/Entity/Seeder.php @@ -41,11 +41,11 @@ class Seeder private $ip; /** - * @var Account + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="seeders", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="seeders", cascade={"persist"}) */ - private $account; + private $userProfile; /** * @var Video @@ -78,14 +78,14 @@ public function setPlatform(string $platform): Seeder return $this; } - public function getAccount(): Account + public function getUserProfile(): UserProfile { - return $this->account; + return $this->userProfile; } - public function setAccount(Account $account): Seeder + public function setUserProfile(UserProfile $userProfile): Seeder { - $this->account = $account; + $this->userProfile = $userProfile; 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..b20c371 100644 --- a/src/AppBundle/Entity/SustainabilityOffer.php +++ b/src/AppBundle/Entity/SustainabilityOffer.php @@ -43,11 +43,11 @@ class SustainabilityOffer private $duration; /** - * @var Account + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="sustainabilityOffers", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="sustainabilityOffers", cascade={"persist"}) */ - private $account; + private $userProfile; /** * @var Channel @@ -92,14 +92,14 @@ public function setDuration(int $duration): SustainabilityOffer return $this; } - public function getAccount(): Account + public function getUserProfile(): UserProfile { - return $this->account; + return $this->userProfile; } - public function setAccount($account): SustainabilityOffer + public function setUserProfile(UserProfile $userProfile): SustainabilityOffer { - $this->account = $account; + $this->userProfile = $userProfile; 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/UserAccount.php b/src/AppBundle/Entity/UserAccount.php new file mode 100644 index 0000000..4aca575 --- /dev/null +++ b/src/AppBundle/Entity/UserAccount.php @@ -0,0 +1,150 @@ +email; + } + + public function setUsername(string $username): UserAccount + { + $this->email = $username; + + return $this; + } + + public function getEmail(): string + { + return $this->email; + } + + public function setEmail($email): UserAccount + { + $this->email = $email; + + return $this; + } + + public function getSalt(): string + { + return $this->salt; + } + + public function setSalt(string $salt): UserAccount + { + $this->salt = $salt; + + return $this; + } + + public function getRoles(): array + { + return ['ROLE_USER']; + } + + public function eraseCredentials() + { + } + + public function getPassword(): string + { + return $this->password; + } + + public function setPassword(string $password): UserAccount + { + $this->password = $password; + + return $this; + } + + public function getId(): int + { + return $this->id; + } + + public function setId(int $id): UserAccount + { + $this->id = $id; + + return $this; + } + + public function getUserProfile(): ?UserProfile + { + return $this->userProfile; + } + + public function setUserProfile(UserProfile $userProfile): UserAccount + { + $this->userProfile = $userProfile; + + return $this; + } +} diff --git a/src/AppBundle/Entity/Account.php b/src/AppBundle/Entity/UserProfile.php similarity index 72% rename from src/AppBundle/Entity/Account.php rename to src/AppBundle/Entity/UserProfile.php index 8a71ff9..f849773 100644 --- a/src/AppBundle/Entity/Account.php +++ b/src/AppBundle/Entity/UserProfile.php @@ -5,17 +5,16 @@ 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; use Symfony\Component\Validator\Constraints as Assert; /** * User's account. * - * @ORM\Entity(repositoryClass="AppBundle\Repository\AccountRepository") + * @ORM\Entity * @ApiResource(attributes={"filters" = {"account.search"}, "normalization_context" = {"groups" = {"account"}}}) */ -class Account implements UserInterface +class UserProfile { /** * @var int The Id of the user @@ -39,43 +38,10 @@ class Account implements UserInterface */ private $username; - /** - * @var string The email of the user - * - * @ORM\Column(type="string", unique=true) - * - * @Groups({"account"}) - * @Assert\NotBlank - * @Assert\Email - */ - private $email; - - /** - * @var string The first name of user - * - * @ORM\Column(type="string") - * - * @Groups({"account"}) - * @Assert\NotBlank - * @Assert\Type("string") - */ - private $firstName; - - /** - * @var string The last name of user - * - * @ORM\Column(type="string") - * - * @Groups({"account"}) - * @Assert\NotBlank - * @Assert\Type("string") - */ - private $lastName; - /** * @var ArrayCollection The list of the channels * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Channel", mappedBy="account", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\Channel", mappedBy="userProfile", cascade={"persist"}) * @Groups({"account"}) */ private $channels; @@ -84,7 +50,7 @@ class Account implements UserInterface * @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="userProfile", cascade={"persist"}) */ private $views; @@ -108,7 +74,7 @@ class Account implements UserInterface /** * @var ArrayCollection * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Playlist", mappedBy="account", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\Playlist", mappedBy="userProfile", cascade={"persist"}) * @Groups({"account"}) */ private $playlists; @@ -132,7 +98,7 @@ class Account implements UserInterface /** * @var ArrayCollection * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\SustainabilityOffer", mappedBy="account", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\SustainabilityOffer", mappedBy="userProfile", cascade={"persist"}) * @Groups({"account"}) */ private $sustainabilityOffers; @@ -140,30 +106,40 @@ class Account implements UserInterface /** * @var ArrayCollection * - * @ORM\OneToMany(targetEntity="AppBundle\Entity\Seeder", mappedBy="account", cascade={"persist"}) + * @ORM\OneToMany(targetEntity="AppBundle\Entity\Seeder", mappedBy="userProfile", cascade={"persist"}) * @Groups({"account"}) */ private $seeders; /** - * @var string The salt of the user + * @var string The first name of user * * @ORM\Column(type="string") * + * @Groups({"account"}) * @Assert\NotBlank * @Assert\Type("string") */ - private $salt; + private $firstName; /** - * @var string password of the user + * @var string The last name of user * * @ORM\Column(type="string") * + * @Groups({"account"}) * @Assert\NotBlank * @Assert\Type("string") */ - private $password; + private $lastName; + + /** + * @var UserAccount + * + * @ORM\OneToOne(targetEntity="AppBundle\Entity\UserAccount", inversedBy="userProfile", cascade={"persist"}) + * @ORM\JoinColumn(nullable=false) + */ + private $userAccount; public function __construct() { @@ -183,7 +159,7 @@ public function getViews() return $this->views; } - public function setViews($views) + public function setViews($views): UserProfile { $this->views = $views; @@ -195,7 +171,7 @@ public function getChannels() return $this->channels; } - public function setChannels($channels) + public function setChannels($channels): UserProfile { $this->channels = $channels; @@ -207,7 +183,7 @@ public function getId(): int return $this->id; } - public function setId($id) + public function setId($id): UserProfile { $this->id = $id; @@ -219,31 +195,19 @@ public function getUsername(): string return $this->username; } - public function setUsername($username) + public function setUsername(string $username): UserProfile { $this->username = $username; return $this; } - public function getEmail(): string - { - return $this->email; - } - - public function setEmail($email) - { - $this->email = $email; - - return $this; - } - public function getFirstName(): string { return $this->firstName; } - public function setFirstName($firstName) + public function setFirstName(string $firstName): UserProfile { $this->firstName = $firstName; @@ -255,7 +219,7 @@ public function getLastName(): string return $this->lastName; } - public function setLastName($lastName) + public function setLastName(string $lastName): UserProfile { $this->lastName = $lastName; @@ -267,7 +231,7 @@ public function getForums() return $this->forums; } - public function setForums($forums): Account + public function setForums($forums): UserProfile { $this->forums = $forums; @@ -279,7 +243,7 @@ public function getNetworks() return $this->networks; } - public function setNetworks($networks): Account + public function setNetworks($networks): UserProfile { $this->networks = $networks; @@ -291,7 +255,7 @@ public function getPlaylists() return $this->playlists; } - public function setPlaylist($playlists): Account + public function setPlaylist($playlists): UserProfile { $this->playlists = $playlists; @@ -303,7 +267,7 @@ public function getReplies() return $this->replies; } - public function setReplies($replies): Account + public function setReplies($replies): UserProfile { $this->replies = $replies; @@ -315,7 +279,7 @@ public function getReviews() return $this->reviews; } - public function setReviews($reviews): Account + public function setReviews($reviews): UserProfile { $this->reviews = $reviews; @@ -327,7 +291,7 @@ public function getSustainabilityOffers() return $this->sustainabilityOffers; } - public function setSustainabilityOffers($sustainabilityOffers): Account + public function setSustainabilityOffers($sustainabilityOffers): UserProfile { $this->sustainabilityOffers = $sustainabilityOffers; @@ -339,42 +303,21 @@ public function getSeeders() return $this->seeders; } - public function setSeeders($seeders): Account + public function setSeeders($seeders): UserProfile { $this->seeders = $seeders; return $this; } - public function getSalt(): string - { - return $this->salt; - } - - public function setSalt(string $salt): Account - { - $this->salt = $salt; - - return $this; - } - - public function getRoles(): array - { - return ['ROLE_USER']; - } - - public function eraseCredentials() - { - } - - public function getPassword(): string + public function getUserAccount(): UserAccount { - return $this->password; + return $this->userAccount; } - public function setPassword(string $password): Account + public function setUserAccount(UserAccount $userAccount): UserProfile { - $this->password = $password; + $this->userAccount = $userAccount; return $this; } 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..e656972 100644 --- a/src/AppBundle/Entity/View.php +++ b/src/AppBundle/Entity/View.php @@ -23,11 +23,11 @@ class View private $id; /** - * @var Account + * @var UserProfile * - * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account", inversedBy="views", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserProfile", inversedBy="views", cascade={"persist"}) */ - private $account; + private $userProfile; /** * @var Video @@ -46,14 +46,14 @@ public function setId(int $id) $this->id = $id; } - public function getAccount(): Account + public function getUserProfile(): UserProfile { - return $this->account; + return $this->userProfile; } - public function setAccount(Account $account) + public function setUserProfile(UserProfile $userProfile) { - $this->account = $account; + $this->userProfile = $userProfile; return $this; } diff --git a/src/AppBundle/EventSubscriber/AccountChecker.php b/src/AppBundle/EventSubscriber/AccountChecker.php new file mode 100644 index 0000000..ebabadc --- /dev/null +++ b/src/AppBundle/EventSubscriber/AccountChecker.php @@ -0,0 +1,43 @@ +authorizationChecker = $authorizationChecker; + } + + public static function getSubscribedEvents() + { + return [ + KernelEvents::VIEW => [['onKernelRequest', EventPriorities::PRE_READ]], + ]; + } + + public function onKernelRequest(GetResponseEvent $event) + { + $method = $event->getRequest()->getMethod(); + $arrayPath = explode('/', $event->getRequest()->getPathInfo()); + + if (Request::METHOD_POST === $method || $arrayPath[1] !== 'user_accounts') { + return; + } + + if (!$this->authorizationChecker->isGranted('access', $arrayPath)) { + $response = new Response('You don\'t have access to this account', Response::HTTP_FORBIDDEN); + $event->setResponse($response); + } + } +} diff --git a/src/AppBundle/EventSubscriber/PasswordEncryption.php b/src/AppBundle/EventSubscriber/PasswordEncryption.php new file mode 100644 index 0000000..73a45bf --- /dev/null +++ b/src/AppBundle/EventSubscriber/PasswordEncryption.php @@ -0,0 +1,36 @@ + [['encryptPassword', EventPriorities::PRE_WRITE]], + ]; + } + + public function encryptPassword(GetResponseForControllerResultEvent $event) + { + /*$account = $event->getControllerResult(); + $method = $event->getRequest()->getMethod(); + + if (!$account instanceof UserAccount || $method !== Request::METHOD_POST) { + return; + } + + $account + ->setSalt(base_convert(uniqid(mt_rand(), true), 16, 36)) + ->setPassword($this->container->get('security.password_encoder') + ->encodePassword($account, 'password')) + ;*/ + } +} 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/Repository/AccountRepository.php b/src/AppBundle/Repository/UserAccountRepository.php similarity index 90% rename from src/AppBundle/Repository/AccountRepository.php rename to src/AppBundle/Repository/UserAccountRepository.php index 5af92be..4f6777d 100644 --- a/src/AppBundle/Repository/AccountRepository.php +++ b/src/AppBundle/Repository/UserAccountRepository.php @@ -4,27 +4,27 @@ use Doctrine\ORM\EntityRepository; -class AccountRepository extends EntityRepository +class UserAccountRepository extends EntityRepository { - public function findOneByEmail(string $email) + public function findOneByUsername(string $username) { return $this->createQueryBuilder('a') ->select('a') - ->where('a.email = :email') - ->setParameter('email', $email) + ->where('a.username = :username') + ->setParameter('username', $username) ->getQuery() ->getOneOrNullResult() ; } - public function findOneByUsername(string $username) + public function findOneByEmail(string $email) { return $this->createQueryBuilder('a') ->select('a') - ->where('a.username = :username') - ->setParameter('username', $username) + ->where('a.email = :email') + ->setParameter('email', $email) ->getQuery() ->getOneOrNullResult() - ; + ; } } diff --git a/src/AppBundle/Security/AccountProvider.php b/src/AppBundle/Security/AccountProvider.php index 7f5c094..2dd36f1 100644 --- a/src/AppBundle/Security/AccountProvider.php +++ b/src/AppBundle/Security/AccountProvider.php @@ -2,7 +2,7 @@ namespace AppBundle\Security; -use AppBundle\Entity\Account; +use AppBundle\Entity\UserAccount; use Doctrine\ORM\EntityManager; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; @@ -15,13 +15,12 @@ class AccountProvider implements UserProviderInterface public function __construct(EntityManager $em) { - $this->repository = $em->getRepository('AppBundle:Account'); + $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'); } @@ -31,7 +30,7 @@ public function loadUserByUsername($username) public function refreshUser(UserInterface $user) { - if (!$user instanceof Account) { + if (!$user instanceof UserAccount) { throw new UnsupportedUserException( sprintf('Instances of "%s" are not supported.', get_class($user)) ); @@ -42,6 +41,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 new file mode 100644 index 0000000..ab72ed6 --- /dev/null +++ b/src/AppBundle/Security/AccountVoter.php @@ -0,0 +1,45 @@ +getUser(); + + if (!$user instanceof UserAccount) { + return false; + } + + if ($attribute === self::ACCESS) { + return $this->canAccess($subject[2], $user); + } + + throw new \LogicException('This code should not be reached!'); + } + + private function canAccess(string $profileId, UserAccount $account) + { + return $account->getId() === (int) $profileId; + } +} 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/src/AppBundle/Validator/Constraints/PlaylistClassValidator.php b/src/AppBundle/Validator/Constraints/PlaylistClassValidator.php index 7a6960c..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->getAccount())) { + if (!$this->ternaryXor($playlist->getChannel(), $playlist->getNetwork(), $playlist->getUserProfile())) { $this->context->buildViolation($constraint->message)->atPath('Playlist')->addViolation(); } } 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()); diff --git a/var/cache/.gitkeep b/var/cache/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/var/sessions/.gitkeep b/var/sessions/.gitkeep deleted file mode 100644 index e69de29..0000000