diff --git a/Dockerfile b/Dockerfile
index 06ad62a31b3a60cb4f38278dd02915e8fcda139b..61f7e518666f10f3b47cd80441bb0db9603ba068 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,9 +1,3 @@
-###########################################################################################
-#
-# Image pour le dev.
-#
-###########################################################################################
-
ARG PHP_VERSION
FROM unicaen-dev-php${PHP_VERSION}-apache
@@ -18,11 +12,7 @@ ENV APACHE_CONF_DIR=/etc/apache2 \
## Installation de packages requis.
RUN apt-get update -qq && \
apt-get install -y \
- sqlite3 \
- php${PHP_VERSION}-pdo-sqlite
-
-RUN pecl install ast && \
- echo "extension=ast.so" > ${PHP_CONF_DIR}/cli/conf.d/ast.ini
+ php${PHP_VERSION}-pgsql
# Nettoyage
RUN apt-get autoremove -y && apt-get clean && rm -rf /tmp/* /var/tmp/*
diff --git a/README.md b/README.md
index 3c82b89080d0de1915a97540a07e3fd23cfe5d75..b42359a54bcf522c3652dd741bd4530bb7a8ab18 100644
--- a/README.md
+++ b/README.md
@@ -11,20 +11,20 @@
## Module Demo
-Le module démo fournit une base de données de démonstration permettant d'avoir une authentification locale
-qui fonctionne.
+Le squelette d'application possède un module "démo" qui utilise une base de données PostgreSQL de démonstration
+permettant d'avoir une authentification locale qui fonctionne.
-Jetez un oeil à la base de données de démo présente dans le module 'Demo' :
-
- $ docker-compose run skeleton-application sqlite3 module/Demo/data/db/demo.sqlite ".schema"
-
-Interrogez la table `user` pour vérifier la présence de l'utilisateur local `demo`, exemple :
-
- $ docker-compose run skeleton-application sqlite3 module/Demo/data/db/demo.sqlite "select * from user;"
+Cette base de données est fournie par le service `db` (fichier de config `docker-compose.yml`).
+Il y a également un service `adminer` fournissant de quoi explorer la base de données avec l'outil
+["Adminer"](https://www.adminer.org) en vous rendant à l'adresse `localhost:8432` et en utilisant les informations
+ de connexion à la bdd présentes dans le `docker-compose.yml`.
## Configuration du projet
-- Renommez `config/autoload/local.php.dist` en `local.php`.
+- Renommez `config/autoload/local.php.dist` en `local.php` :
+```bash
+mv config/autoload/local.php.dist config/autoload/local.php
+```
- Copiez dans votre dossier `config/autoload` les fichiers de configuration locaux et globaux `.dist`
des bibliothèques utilisées sans leur extension `.dist` :
@@ -35,7 +35,8 @@ cp vendor/unicaen/auth/config/unicaen-auth.global.php.dist config/autoload/unica
cp vendor/unicaen/auth/config/unicaen-auth.local.php.dist config/autoload/unicaen-auth.local.php
```
-- Le cas échéant, reportez-vous aux docs des modules concernés pour adapter ces fichiers de configuration à vos besoins :
+- Le cas échéant, reportez-vous aux docs des modules concernés pour adapter ces fichiers de configuration
+à vos besoins :
- [unicaen/app](https://git.unicaen.fr/lib/unicaen/app)
- [unicaen/auth](https://git.unicaen.fr/lib/unicaen/auth)
diff --git a/composer.json b/composer.json
index 3c38369c5087fa3a15e1ebd353a311d974a7eebe..47d81d0b5ccf41ffd95f3f9857c7ddbf41c32ea9 100755
--- a/composer.json
+++ b/composer.json
@@ -8,14 +8,14 @@
}
],
"require": {
- "unicaen/app": "dev-zf-3.x",
- "unicaen/auth": "dev-zf-3.x",
- "unicaen/bjy-authorize": "dev-zf-3.x",
- "unicaen/faq": "dev-zf-3.x",
- "unicaen/ldap": "dev-zf-3.x"
+ "unicaen/app": "^3.0",
+ "unicaen/auth": "^3.0",
+ "unicaen/bjy-authorize": "^3.0",
+ "unicaen/faq": "^3.0",
+ "unicaen/ldap": "^3.0"
},
"require-dev": {
- "zendframework/zend-test": ">=2.3",
+ "zendframework/zend-test": "^3.2",
"phpunit/phpunit": ">=3.7",
"zendframework/zend-developer-tools": ">=1.0"
},
diff --git a/composer.lock b/composer.lock
index 43d9a74f34fbbd9abbfa87caaab943b69bc636d2..120ed6952d1651de14475f3462fe1d8e05498ac7 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "472fe5bd83d98e8ce14043b863c18ace",
+ "content-hash": "a868570eddc575aa0674ec170b0b473f",
"packages": [
{
"name": "beberlei/assert",
@@ -2176,11 +2176,11 @@
},
{
"name": "unicaen/app",
- "version": "dev-zf-3.x",
+ "version": "3.0.0",
"source": {
"type": "git",
"url": "https://git.unicaen.fr/lib/unicaen/app.git",
- "reference": "f18f3a9ae51144c0bf5dc07b6139fba07314fc6a"
+ "reference": "fe92dcafbefbfdcdea019ef0c963b8b5efca4037"
},
"require": {
"beberlei/assert": "^2.9",
@@ -2236,22 +2236,22 @@
]
},
"description": "Module de base des applications unicaen",
- "time": "2019-09-16T09:49:44+00:00"
+ "time": "2019-09-16T13:15:55+00:00"
},
{
"name": "unicaen/auth",
- "version": "dev-zf-3.x",
+ "version": "3.0.1",
"source": {
"type": "git",
"url": "https://git.unicaen.fr/lib/unicaen/auth.git",
- "reference": "12c05066041f8c305c1c95ac933ed95eb128401a"
+ "reference": "433bbe5a7d3f5089cfc390ea5cbef90b9a56186e"
},
"require": {
- "beberlei/assert": "^2.9",
"jasig/phpcas": "^1.3",
+ "php": "7.3.*",
"ramsey/uuid": "^3.7",
- "unicaen/app": "dev-zf-3.x",
- "unicaen/bjy-authorize": "dev-zf-3.x"
+ "unicaen/app": "^3.0",
+ "unicaen/bjy-authorize": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^5.6"
@@ -2267,19 +2267,19 @@
]
},
"description": "Module d'authentification pour les applications Unicaen",
- "time": "2019-09-11T09:05:45+00:00"
+ "time": "2019-09-18T12:02:04+00:00"
},
{
"name": "unicaen/bjy-authorize",
- "version": "dev-zf-3.x",
+ "version": "3.0.0",
"source": {
"type": "git",
"url": "https://git.unicaen.fr/lib/unicaen/bjy-authorize.git",
- "reference": "790c5fddb1a3a89ed904faa633722c57c5c472f5"
+ "reference": "9480124324d8b1c6de56cdf27ab687fea2216c84"
},
"require": {
"doctrine/common": "^2.7",
- "php": ">=5.6 || >=7.0",
+ "php": "7.3.*",
"zendframework/zend-cache": "^2.8",
"zendframework/zend-eventmanager": "^3.2",
"zendframework/zend-http": "^2.10",
@@ -2328,24 +2328,23 @@
"zf2",
"zfc-user"
],
- "time": "2019-03-21T09:05:22+00:00"
+ "time": "2019-09-18T07:15:38+00:00"
},
{
"name": "unicaen/faq",
- "version": "dev-zf-3.x",
+ "version": "3.0.0",
"source": {
"type": "git",
"url": "https://git.unicaen.fr/lib/unicaen/faq.git",
- "reference": "c6f03783941b0dd0c553a0e01cd84519959550e2"
+ "reference": "1caeeb64aa47aeaba737e06e221d1b82b380dd46"
},
"require": {
- "unicaen/app": "dev-zf-3.x"
+ "unicaen/app": "^3.0"
},
"require-dev": {
"phpspec/prophecy": "^1.6",
"phpunit/phpunit": "^5.6",
- "snapshotpl/zf-snap-event-debugger": "1.*",
- "zendframework/zend-test": "^2.4 || ^3.0"
+ "zendframework/zend-test": "^3.0"
},
"type": "library",
"autoload": {
@@ -2357,18 +2356,18 @@
]
},
"description": "Module de foire aux questions",
- "time": "2019-03-20T15:37:21+00:00"
+ "time": "2019-09-18T08:11:53+00:00"
},
{
"name": "unicaen/ldap",
- "version": "dev-zf-3.x",
+ "version": "3.0.0",
"source": {
"type": "git",
"url": "https://git.unicaen.fr/lib/unicaen/ldap.git",
- "reference": "2dca4963d882e9e9ea590a34ed22de3b6d922941"
+ "reference": "26bcaef4f761087a975139b2d1e54e935869b78c"
},
"require": {
- "php": "^5.6 || ^7.0",
+ "php": "7.3.*",
"zendframework/zend-config": "^3.2",
"zendframework/zend-i18n": "^2.9",
"zendframework/zend-ldap": "^2.10",
@@ -2380,7 +2379,7 @@
},
"require-dev": {
"phpunit/phpunit": ">=3.7",
- "zendframework/zend-test": ">=2.2"
+ "zendframework/zend-test": "^3.2"
},
"type": "library",
"autoload": {
@@ -2394,7 +2393,7 @@
]
},
"description": "Module Ldap des applications Unicaen",
- "time": "2019-05-23T13:04:14+00:00"
+ "time": "2019-09-18T09:15:50+00:00"
},
{
"name": "zendframework/zend-authentication",
@@ -5452,16 +5451,16 @@
},
{
"name": "phpunit/php-code-coverage",
- "version": "7.0.7",
+ "version": "7.0.8",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "7743bbcfff2a907e9ee4a25be13d0f8ec5e73800"
+ "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7743bbcfff2a907e9ee4a25be13d0f8ec5e73800",
- "reference": "7743bbcfff2a907e9ee4a25be13d0f8ec5e73800",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa0d179a13284c7420fc281fc32750e6cc7c9e2f",
+ "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f",
"shasum": ""
},
"require": {
@@ -5470,7 +5469,7 @@
"php": "^7.2",
"phpunit/php-file-iterator": "^2.0.2",
"phpunit/php-text-template": "^1.2.1",
- "phpunit/php-token-stream": "^3.1.0",
+ "phpunit/php-token-stream": "^3.1.1",
"sebastian/code-unit-reverse-lookup": "^1.0.1",
"sebastian/environment": "^4.2.2",
"sebastian/version": "^2.0.1",
@@ -5511,7 +5510,7 @@
"testing",
"xunit"
],
- "time": "2019-07-25T05:31:54+00:00"
+ "time": "2019-09-17T06:24:36+00:00"
},
{
"name": "phpunit/php-file-iterator",
@@ -5655,16 +5654,16 @@
},
{
"name": "phpunit/php-token-stream",
- "version": "3.1.0",
+ "version": "3.1.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
- "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a"
+ "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e899757bb3df5ff6e95089132f32cd59aac2220a",
- "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff",
+ "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff",
"shasum": ""
},
"require": {
@@ -5700,7 +5699,7 @@
"keywords": [
"tokenizer"
],
- "time": "2019-07-25T05:29:42+00:00"
+ "time": "2019-09-17T06:23:10+00:00"
},
{
"name": "phpunit/phpunit",
@@ -6735,13 +6734,7 @@
],
"aliases": [],
"minimum-stability": "stable",
- "stability-flags": {
- "unicaen/app": 20,
- "unicaen/auth": 20,
- "unicaen/bjy-authorize": 20,
- "unicaen/faq": 20,
- "unicaen/ldap": 20
- },
+ "stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
diff --git a/config/autoload/global.php b/config/autoload/global.php
index 2ff19548ad7448d503c02f06d3b86930ad9c8bbd..823bb91afcf995dc469bd5c1c29e61109091ba7b 100755
--- a/config/autoload/global.php
+++ b/config/autoload/global.php
@@ -1,6 +1,6 @@
<?php
-return array(
- 'translator' => array(
+return [
+ 'translator' => [
'locale' => 'fr_FR',
- ),
-);
+ ],
+];
diff --git a/data/.gitignore b/data/.gitignore
index ae8c28abc275267367968fe4b31d3a876b03ddb9..d20dcaf1bc063d14321a4575a9c0fc898238eb2a 100644
--- a/data/.gitignore
+++ b/data/.gitignore
@@ -1 +1,2 @@
DoctrineORMModule/
+db/
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index 1d96644bdb1f96bf244ec232fbd409adfb2fdf64..79216a45d4a1e4cc619baae14fb858a2ed83404f 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -14,3 +14,22 @@ services:
volumes:
- .:/app
working_dir: /app
+
+ db:
+ image: postgres
+ restart: always
+ environment:
+ POSTGRES_USER: admin
+ POSTGRES_PASSWORD: admin
+ POSTGRES_DB: demo
+ ports:
+ - 8432:5432
+ volumes:
+ - ./data/db:/var/lib/postgresql/data
+ - ./docker/db/:/docker-entrypoint-initdb.d/
+
+ adminer:
+ image: adminer
+ restart: always
+ ports:
+ - 9080:8080
diff --git a/docker/db/1-schema.sql b/docker/db/1-schema.sql
new file mode 100644
index 0000000000000000000000000000000000000000..4bb92b1284a3e9e123e58b6112f3b6fdf37312bc
--- /dev/null
+++ b/docker/db/1-schema.sql
@@ -0,0 +1,64 @@
+CREATE TABLE "user" (
+ id BIGSERIAL PRIMARY KEY,
+ username VARCHAR(255) DEFAULT NULL,
+ email VARCHAR(255) DEFAULT NULL,
+ display_name VARCHAR(64) DEFAULT NULL,
+ password VARCHAR(128) NOT NULL,
+ state SMALLINT default 1
+) ;
+CREATE UNIQUE INDEX user_username_unique ON "user" (username);
+
+alter table "user" add PASSWORD_RESET_TOKEN varchar(256) default null;
+
+create unique index USER_PASSWORD_RESET_TOKEN_UN on "user" (PASSWORD_RESET_TOKEN);
+
+CREATE TABLE user_role (
+ id BIGSERIAL PRIMARY KEY,
+ role_id VARCHAR(64) NOT NULL,
+ is_default SMALLINT NOT NULL DEFAULT 0,
+ parent_id BIGINT DEFAULT NULL,
+ ldap_filter varchar(255) DEFAULT NULL,
+ FOREIGN KEY (parent_id) REFERENCES user_role (id) ON DELETE SET NULL
+);
+CREATE UNIQUE INDEX user_role_roleid_unique ON user_role (role_id);
+
+
+CREATE TABLE user_role_linker (
+ user_id BIGINT NOT NULL,
+ role_id BIGINT NOT NULL,
+ PRIMARY KEY (user_id, role_id),
+ FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE,
+ FOREIGN KEY (role_id) REFERENCES user_role (id) ON DELETE CASCADE
+);
+CREATE UNIQUE INDEX user_role_linker_unique ON user_role_linker (user_id, role_id);
+
+
+
+
+CREATE TABLE IF NOT EXISTS categorie_privilege (
+ id BIGSERIAL PRIMARY KEY,
+ code VARCHAR(150) NOT NULL,
+ libelle VARCHAR(200) NOT NULL,
+ ordre INT
+);
+CREATE UNIQUE INDEX categorie_privilege_unique ON categorie_privilege (code);
+
+
+CREATE TABLE IF NOT EXISTS privilege (
+ id BIGSERIAL PRIMARY KEY,
+ categorie_id BIGINT NOT NULL,
+ code VARCHAR(150) NOT NULL,
+ libelle VARCHAR(200) NOT NULL,
+ ordre INT,
+ FOREIGN KEY (categorie_id) REFERENCES categorie_privilege (id) ON DELETE CASCADE
+);
+CREATE UNIQUE INDEX privilege_unique ON privilege (code);
+
+CREATE TABLE IF NOT EXISTS role_privilege (
+ role_id BIGINT NOT NULL,
+ privilege_id BIGINT NOT NULL,
+ PRIMARY KEY (role_id, privilege_id),
+ FOREIGN KEY (role_id) REFERENCES user_role (id) ON DELETE CASCADE,
+ FOREIGN KEY (privilege_id) REFERENCES privilege (id) ON DELETE CASCADE
+);
+CREATE UNIQUE INDEX role_privilege_unique ON role_privilege (role_id, privilege_id);
diff --git a/docker/db/2-data.sql b/docker/db/2-data.sql
new file mode 100644
index 0000000000000000000000000000000000000000..c3433d0d96d89fe59a84bb1825be74aa14664f88
--- /dev/null
+++ b/docker/db/2-data.sql
@@ -0,0 +1,30 @@
+
+-- Données
+
+INSERT INTO user_role (id, role_id, is_default, parent_id) VALUES
+(1, 'Standard', 1, NULL),
+(2, 'Gestionnaire', 0, 1),
+(3, 'Super-gestionnaire', 0, 2),
+(4, 'Administrateur', 0, 3);
+
+INSERT INTO categorie_privilege (id, code, libelle, ordre) VALUES
+(1, 'droit', 'Gestion des droits', 1);
+
+INSERT INTO privilege (id, categorie_id, code, libelle, ordre) VALUES
+(1, 1, 'role-visualisation', 'Rôles - Visualisation', 1),
+(2, 1, 'role-edition', 'Rôles - Édition', 2),
+(3, 1, 'privilege-visualisation', 'Privilèges - Visualisation', 3),
+(4, 1, 'privilege-edition', 'Privilèges - Édition', 4);
+
+INSERT INTO role_privilege (role_id, privilege_id) VALUES
+(4, 1),
+(4, 2),
+(4, 3),
+(4, 4);
+
+INSERT INTO "user" (username, email, display_name, password, state) VALUES
+ -- utilisateur demo/azerty
+ ('demo', 'demo@mail.fr', 'Demo Crite', '$2y$10$PxXnVLYnGEzEnfqPqRKJSe9AabocES2H4bBK5VzzJlzuj1rVt7Lwu', 1);
+
+INSERT INTO user_role_linker(user_id, role_id)
+SELECT u.id, r.id FROM "user" u, user_role r WHERE u.username = 'demo' and r.role_id = 'Standard';
diff --git a/module/Demo/bin/create_demo_db.sh b/module/Demo/bin/create_demo_db.sh
deleted file mode 100755
index 33ce16fc2316e678e350dbe1b14ff0c1bd5cc94d..0000000000000000000000000000000000000000
--- a/module/Demo/bin/create_demo_db.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env bash
-
-DIR=$(cd `dirname $0` && pwd)
-DBPATH=${DIR}/../data/db/demo.sqlite
-
-sqlite3 ${DBPATH} < ${DIR}/../data/demo.sqlite.sql && \
-chmod 777 ${DBPATH} && \
-chmod 777 `dirname ${DBPATH}`
diff --git a/module/Demo/config/module.config.php b/module/Demo/config/module.config.php
index 046697925e0fe0e2bfd7d91d1d3adf98168bf432..ae6f72a400e63d9a951df4d98f185cde83c74268 100755
--- a/module/Demo/config/module.config.php
+++ b/module/Demo/config/module.config.php
@@ -3,16 +3,26 @@
namespace Demo;
return [
+ //
+ // ATTENTION: config Doctrine à déplacer dans `APP/config/autoload/`.
+ //
'doctrine' => [
'connection' => [
'orm_default' => [
- 'driverClass' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver',
+ 'driverClass' => \Doctrine\DBAL\Driver\PDOPgSql\Driver::class,
'params' => [
- 'path' => __DIR__ . '/../data/db/demo.sqlite',
+ 'host' => 'db', //
+ 'user' => 'admin', // cf. docker-compose.yml
+ 'password' => 'admin', //
+ 'dbname' => 'demo', //
+ 'port' => '5432',
+ 'charset' => 'utf8',
+ 'driverOptions' => [1002 => 'SET NAMES utf8']
],
],
],
],
+
'bjyauthorize' => [
'guards' => [
'BjyAuthorize\Guard\Controller' => [
diff --git a/module/Demo/data/db/demo.sqlite b/module/Demo/data/db/demo.sqlite
deleted file mode 100755
index cede42626ca8e68f5f2e81258866701abacae6d7..0000000000000000000000000000000000000000
Binary files a/module/Demo/data/db/demo.sqlite and /dev/null differ
diff --git a/module/Demo/data/demo.sqlite.sql b/module/Demo/data/demo.sqlite.sql
deleted file mode 100644
index 7de5346fa3d45a4951e5b5cce0fddb3961c0b70b..0000000000000000000000000000000000000000
--- a/module/Demo/data/demo.sqlite.sql
+++ /dev/null
@@ -1,98 +0,0 @@
-CREATE TABLE IF NOT EXISTS user
-(
- id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
- username VARCHAR(255) DEFAULT NULL,
- email VARCHAR(255) DEFAULT NULL,
- display_name VARCHAR(64) DEFAULT NULL,
- password VARCHAR(128) NOT NULL,
- state SMALLINT default 1
-);
-ALTER TABLE user ADD PASSWORD_RESET_TOKEN varchar(256) DEFAULT NULL;
-CREATE UNIQUE INDEX user_unique_username ON user(username);
-CREATE UNIQUE INDEX USER_PASSWORD_RESET_TOKEN_UN ON user (PASSWORD_RESET_TOKEN);
-
-
-CREATE TABLE IF NOT EXISTS user_role (
- id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
- role_id VARCHAR(64) NOT NULL,
- is_default TINYINT(1) NOT NULL DEFAULT 0,
- parent_id INTEGER NULL DEFAULT NULL,
- ldap_filter varchar(255) DEFAULT NULL,
-
- FOREIGN KEY (parent_id) REFERENCES user_role (id) ON DELETE SET NULL
-);
-CREATE UNIQUE INDEX role_unique_role_id ON user_role(role_id);
-CREATE INDEX role_idx_parent_id ON user_role(parent_id);
-
-
-CREATE TABLE IF NOT EXISTS user_role_linker (
- user_id INTEGER NOT NULL,
- role_id INTEGER NOT NULL,
- PRIMARY KEY (user_id, role_id),
- FOREIGN KEY (role_id) REFERENCES user_role (id) ON DELETE CASCADE,
- FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE
-);
-CREATE INDEX user_role_linker_idx_role_id ON user_role_linker(role_id);
-CREATE INDEX user_role_linker_idx_user_id ON user_role_linker(user_id);
-
-
-CREATE TABLE IF NOT EXISTS categorie_privilege (
- id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
- code VARCHAR(150) NOT NULL,
- libelle VARCHAR(200) NOT NULL,
- ordre INTEGER
-);
-CREATE UNIQUE INDEX categorie_unique_code ON categorie_privilege(code);
-
-
-CREATE TABLE IF NOT EXISTS privilege (
- id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
- categorie_id INTEGER NOT NULL,
- code VARCHAR(150) NOT NULL,
- libelle VARCHAR(200) NOT NULL,
- ordre INTEGER,
- FOREIGN KEY (categorie_id) REFERENCES categorie_privilege (id) ON DELETE CASCADE
-);
-CREATE UNIQUE INDEX privilege_unique_code ON privilege(code);
-
-
-CREATE TABLE IF NOT EXISTS role_privilege (
- role_id INTEGER NOT NULL,
- privilege_id INTEGER NOT NULL,
- PRIMARY KEY (role_id,privilege_id),
- FOREIGN KEY (role_id) REFERENCES user_role (id) ON DELETE CASCADE,
- FOREIGN KEY (privilege_id) REFERENCES privilege (id) ON DELETE CASCADE
-);
-CREATE INDEX idx_role_id on role_privilege(role_id);
-CREATE INDEX idx_privilege_id on role_privilege(privilege_id);
-
-
--- Données
-
-INSERT INTO user_role (id, role_id, is_default, parent_id) VALUES
- (1, 'Standard', 1, NULL),
- (2, 'Gestionnaire', 0, 1),
- (3, 'Super-gestionnaire', 0, 2),
- (4, 'Administrateur', 0, 3);
-
-INSERT INTO categorie_privilege (id, code, libelle, ordre) VALUES
- (1, 'droit', 'Gestion des droits', 1);
-
-INSERT INTO privilege (id, categorie_id, code, libelle, ordre) VALUES
- (1, 1, 'role-visualisation', 'Rôles - Visualisation', 1),
- (2, 1, 'role-edition', 'Rôles - Édition', 2),
- (3, 1, 'privilege-visualisation', 'Privilèges - Visualisation', 3),
- (4, 1, 'privilege-edition', 'Privilèges - Édition', 4);
-
-INSERT INTO role_privilege (role_id, privilege_id) VALUES
- (4, 1),
- (4, 2),
- (4, 3),
- (4, 4);
-
-INSERT INTO user (username, email, display_name, password, state) VALUES
- -- utilisateur demo/azerty
- ('demo', 'demo@mail.fr', 'Demo', '$2y$10$PxXnVLYnGEzEnfqPqRKJSe9AabocES2H4bBK5VzzJlzuj1rVt7Lwu', 1);
-
-INSERT INTO user_role_linker(user_id, role_id)
-SELECT u.id, r.id FROM user u, user_role r WHERE u.username = 'demo' and r.role_id = 'Standard';