aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-09-06 20:21:49 +0200
committerThomas Citharel <tcit@tcit.fr>2017-06-23 09:18:39 +0200
commitf1900b686eb8d7c41a940eede778234ac55086e1 (patch)
tree3282794540fceaecc831fc9c736cecc57dbc1728
parent29714661b1df78871ceaf0e079f11041a8641d4b (diff)
downloadwallabag-f1900b686eb8d7c41a940eede778234ac55086e1.tar.gz
wallabag-f1900b686eb8d7c41a940eede778234ac55086e1.tar.zst
wallabag-f1900b686eb8d7c41a940eede778234ac55086e1.zip
Added migration for user group
Just a first draft of #805
-rw-r--r--app/DoctrineMigrations/Version20160906180558.php35
-rw-r--r--app/config/config.yml2
-rw-r--r--app/config/routing.yml4
-rw-r--r--src/Wallabag/UserBundle/Entity/Group.php20
-rw-r--r--src/Wallabag/UserBundle/Entity/User.php12
5 files changed, 71 insertions, 2 deletions
diff --git a/app/DoctrineMigrations/Version20160906180558.php b/app/DoctrineMigrations/Version20160906180558.php
new file mode 100644
index 00000000..227bb20f
--- /dev/null
+++ b/app/DoctrineMigrations/Version20160906180558.php
@@ -0,0 +1,35 @@
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema;
7
8/**
9 * Auto-generated Migration: Please modify to your needs!
10 */
11class Version20160906180558 extends AbstractMigration
12{
13 /**
14 * @param Schema $schema
15 */
16 public function up(Schema $schema)
17 {
18 $this->addSql('CREATE TABLE `wallabag_group` (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, roles LONGTEXT NOT NULL, UNIQUE INDEX UNIQ_B2305B375E237E06 (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
19 $this->addSql('CREATE TABLE wallabag_user_group (user_id INT NOT NULL, group_id INT NOT NULL, INDEX IDX_6E85169A76ED395 (user_id), INDEX IDX_6E85169FE54D947 (group_id), PRIMARY KEY(user_id, group_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
20 $this->addSql('ALTER TABLE wallabag_user_group ADD CONSTRAINT FK_6E85169A76ED395 FOREIGN KEY (user_id) REFERENCES `wallabag_user` (id)');
21 $this->addSql('ALTER TABLE wallabag_user_group ADD CONSTRAINT FK_6E85169FE54D947 FOREIGN KEY (group_id) REFERENCES `wallabag_group` (id)');
22 }
23
24 /**
25 * @param Schema $schema
26 */
27 public function down(Schema $schema)
28 {
29 $this->abortIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\'.');
30
31 $this->addSql('ALTER TABLE wallabag_user_group DROP FOREIGN KEY FK_6E85169FE54D947');
32 $this->addSql('DROP TABLE `wallabag_group`');
33 $this->addSql('DROP TABLE wallabag_user_group');
34 }
35}
diff --git a/app/config/config.yml b/app/config/config.yml
index 2bc5e3b3..f1d93aaa 100644
--- a/app/config/config.yml
+++ b/app/config/config.yml
@@ -178,6 +178,8 @@ fos_user:
178 db_driver: orm 178 db_driver: orm
179 firewall_name: secured_area 179 firewall_name: secured_area
180 user_class: Wallabag\UserBundle\Entity\User 180 user_class: Wallabag\UserBundle\Entity\User
181 group:
182 group_class: Wallabag\UserBundle\Entity\Group
181 registration: 183 registration:
182 confirmation: 184 confirmation:
183 enabled: "%fosuser_confirmation%" 185 enabled: "%fosuser_confirmation%"
diff --git a/app/config/routing.yml b/app/config/routing.yml
index 0bd2d130..9c916f7d 100644
--- a/app/config/routing.yml
+++ b/app/config/routing.yml
@@ -41,6 +41,10 @@ homepage:
41fos_user: 41fos_user:
42 resource: "@FOSUserBundle/Resources/config/routing/all.xml" 42 resource: "@FOSUserBundle/Resources/config/routing/all.xml"
43 43
44fos_user_group:
45 resource: "@FOSUserBundle/Resources/config/routing/group.xml"
46 prefix: /group
47
44fos_oauth_server_token: 48fos_oauth_server_token:
45 resource: "@FOSOAuthServerBundle/Resources/config/routing/token.xml" 49 resource: "@FOSOAuthServerBundle/Resources/config/routing/token.xml"
46 50
diff --git a/src/Wallabag/UserBundle/Entity/Group.php b/src/Wallabag/UserBundle/Entity/Group.php
new file mode 100644
index 00000000..9145959d
--- /dev/null
+++ b/src/Wallabag/UserBundle/Entity/Group.php
@@ -0,0 +1,20 @@
1<?php
2
3namespace Wallabag\UserBundle\Entity;
4
5use FOS\UserBundle\Model\Group as BaseGroup;
6use Doctrine\ORM\Mapping as ORM;
7
8/**
9 * @ORM\Entity
10 * @ORM\Table(name="`group`")
11 */
12class Group extends BaseGroup
13{
14 /**
15 * @ORM\Id
16 * @ORM\Column(type="integer")
17 * @ORM\GeneratedValue(strategy="AUTO")
18 */
19 protected $id;
20}
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php
index aba76ca7..781f7b03 100644
--- a/src/Wallabag/UserBundle/Entity/User.php
+++ b/src/Wallabag/UserBundle/Entity/User.php
@@ -98,8 +98,16 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
98 private $authCode; 98 private $authCode;
99 99
100 /** 100 /**
101 * @var bool 101 * @ORM\ManyToMany(targetEntity="Wallabag\UserBundle\Entity\Group")
102 * 102 * @ORM\JoinTable(name="user_group",
103 * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
104 * inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
105 * )
106 */
107 protected $groups;
108
109 /**
110 * @var bool Enabled yes/no
103 * @ORM\Column(type="boolean") 111 * @ORM\Column(type="boolean")
104 */ 112 */
105 private $twoFactorAuthentication = false; 113 private $twoFactorAuthentication = false;