Unverified Commit b2303f4f authored by Ivan Gabriele's avatar Ivan Gabriele Committed by GitHub
Browse files

feat(app): remove areas and tags data (#940)

parent 19a8b374
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "lf",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 100,
"proseWrap": "always"
"proseWrap": "always",
"quoteProps": "as-needed",
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false
}
......@@ -18,8 +18,6 @@ jobs:
script:
- yarn test
after_script:
# Push tests coverage data to Coveralls:
- ./node_modules/.bin/coveralls < ./coverage/lcov.info
# Push tests coverage data to Codecov:
- npx codecov
......
# Back-office du code du travail numérique
[![Travis CI Status][img-travis]][link-travis]
[![Coveralls Code Coverage][img-coveralls]][link-coveralls]
[![Coveralls Code Coverage][img-codecov]][link-codecov]
Ce dépôt regroupe les applications d'administration des données du [code du travail
numérique][link-cdtn].
......@@ -138,14 +138,12 @@ Le code source de ce dépôt est distribué sous la [licence Apache 2.0][link-li
---
[img-coveralls]:
https://img.shields.io/coveralls/github/SocialGouv/code-du-travail-backoffice?style=flat-square
[img-travis]:
https://img.shields.io/travis/SocialGouv/code-du-travail-backoffice/dev.svg?style=flat-square
[img-codecov]: https://img.shields.io/codecov/c/github/SocialGouv/code-du-travail-backoffice?style=flat-square
[img-travis]: https://img.shields.io/travis/SocialGouv/code-du-travail-backoffice/dev.svg?style=flat-square
[link-cdtn]: https://codedutravail.num.social.gouv.fr
[link-coveralls]: https://coveralls.io/github/SocialGouv/code-du-travail-backoffice
[link-issue-1]:
https://github.com/docker/docker-credential-helpers/issues/103#issuecomment-421822269
[link-codecov]: https://codecov.io/gh/SocialGouv/code-du-travail-backoffice
[link-issue-1]: https://github.com/docker/docker-credential-helpers/issues/103#issuecomment-421822269
[link-issue-2]: https://github.com/facebook/jest/issues/3254#issuecomment-297214395
[link-license]: https://github.com/SocialGouv/code-du-travail-backoffice/blob/master/LICENSE
[link-travis]: https://travis-ci.com/SocialGouv/code-du-travail-backoffice
-------------------------------------- UP --------------------------------------
ALTER TABLE api.locations
DROP COLUMN area_id;
DROP TABLE api.areas;
DROP TYPE zone_category;
------------------------------------- DOWN -------------------------------------
CREATE TYPE zone_category AS ENUM (
'department',
'overseas_collectivity',
'region',
'sui_generis_collectivity'
);
CREATE TABLE api.areas(
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name varchar(255) NOT NULL,
category zone_category NOT NULL,
code varchar(5) UNIQUE,
created_at timestamptz NOT NULL DEFAULT NOW(),
updated_at timestamptz NOT NULL DEFAULT NOW(),
parent_id uuid REFERENCES api.areas(id)
);
GRANT SELECT, INSERT, UPDATE ON api.areas TO administrator;
GRANT SELECT ON api.areas TO anonymous;
GRANT SELECT ON api.areas TO contributor;
ALTER TABLE api.locations
ADD COLUMN area_id uuid REFERENCES api.areas(id);
-------------------------------------- UP --------------------------------------
DROP TABLE api.answers_tags;
DROP TABLE api.questions_tags;
DROP TABLE api.tags;
DROP TABLE api.tags_categories;
------------------------------------- DOWN -------------------------------------
CREATE TABLE api.tags_categories(
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
value text NOT NULL,
created_at timestamptz NOT NULL DEFAULT NOW(),
updated_at timestamptz NOT NULL DEFAULT NOW()
);
CREATE TRIGGER update_updated_at
BEFORE UPDATE ON api.tags_categories
FOR EACH ROW
EXECUTE PROCEDURE set_updated_at();
GRANT SELECT ON api.tags_categories TO contributor;
GRANT SELECT, INSERT, UPDATE, DELETE ON api.tags_categories TO administrator;
CREATE TABLE api.tags(
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
value varchar(255) UNIQUE NOT NULL,
created_at timestamptz NOT NULL DEFAULT NOW(),
updated_at timestamptz NOT NULL DEFAULT NOW(),
tag_category_id uuid REFERENCES api.tags_categories(id) ON DELETE SET NULL
);
CREATE TRIGGER update_updated_at
BEFORE UPDATE ON api.tags
FOR EACH ROW
EXECUTE PROCEDURE set_updated_at();
GRANT SELECT ON api.tags TO contributor;
GRANT SELECT, INSERT, UPDATE, DELETE ON api.tags TO administrator;
CREATE TABLE api.questions_tags(
id serial PRIMARY KEY,
question_id uuid NOT NULL REFERENCES api.questions(id),
tag_id uuid NOT NULL REFERENCES api.tags(id)
);
GRANT SELECT ON api.questions_tags TO contributor;
GRANT SELECT, INSERT, UPDATE, DELETE ON api.questions_tags TO administrator;
GRANT USAGE, SELECT ON SEQUENCE api.questions_tags_id_seq TO administrator;
CREATE TABLE api.answers_tags(
id serial PRIMARY KEY,
answer_id uuid NOT NULL REFERENCES api.answers(id),
tag_id uuid NOT NULL REFERENCES api.tags(id)
);
CREATE CONSTRAINT TRIGGER ensure_user_can_update_answer
AFTER UPDATE ON api.answers_tags
FOR EACH ROW
EXECUTE PROCEDURE check_user_can_update_answer();
GRANT SELECT, INSERT, DELETE ON api.answers_tags TO contributor;
GRANT USAGE, SELECT ON SEQUENCE api.answers_tags_id_seq TO contributor;
GRANT SELECT, INSERT, UPDATE, DELETE ON api.answers_tags TO administrator;
GRANT USAGE, SELECT ON SEQUENCE api.answers_tags_id_seq TO administrator;
const getMigrationQuery = require("../../../scripts/db/getMigrationQuery");
exports.up = async knex => {
await knex.raw(getMigrationQuery("20200220133636_drop_areas_table").up());
};
exports.down = async knex => {
await knex.raw(getMigrationQuery("20200220133636_drop_areas_table").down());
};
const getMigrationQuery = require("../../../scripts/db/getMigrationQuery");
exports.up = async knex => {
await knex.raw(getMigrationQuery("20200220134628_drop_tags_table").up());
};
exports.down = async knex => {
await knex.raw(getMigrationQuery("20200220134628_drop_tags_table").down());
};
......@@ -16,19 +16,20 @@ exports.seed = async knex => {
await knex("api.answers_comments").del();
global.spinner.start(`Emptying tables: api.answers_references`);
await knex("api.answers_references").del();
global.spinner.start(`Emptying tables: api.answers_tags`);
await knex("api.answers_tags").del();
global.spinner.start(`Emptying tables: api.questions_tags`);
await knex("api.questions_tags").del();
global.spinner.start(`Emptying tables: api.tags`);
await knex("api.tags").del();
global.spinner.start(`Emptying tables: api.tags_categories`);
await knex("api.tags_categories").del();
global.spinner.start(`Emptying tables: api.answers`);
await knex("api.answers").del();
global.spinner.start(`Emptying tables: api.questions`);
await knex("api.questions").del();
global.spinner.start(`Emptying tables: api.definitions`);
await knex("api.logs").del();
global.spinner.start(`Emptying tables: api.requests`);
await knex("api.logs").del();
global.spinner.start(`Emptying tables: api.themes`);
await knex("api.logs").del();
global.spinner.start(`Emptying tables: api.references`);
await knex("api.logs").del();
global.spinner.start(`Emptying tables: api.logs`);
await knex("api.logs").del();
......@@ -43,8 +44,6 @@ exports.seed = async knex => {
await knex("api.locations").del();
global.spinner.start(`Emptying tables: api.agreements`);
await knex("api.agreements").del();
global.spinner.start(`Emptying tables: api.areas`);
await knex("api.areas").del();
global.spinner.succeed(`Tables emptied.`);
};
exports.seed = async knex => {
global.spinner.start(`Generating areas...`);
const { data: areas } = await global.axios.get("/areas");
await knex("api.areas").insert(areas);
global.spinner.succeed(`Areas generated.`);
};
......@@ -5,9 +5,7 @@ exports.seed = async knex => {
await knex("api.locations").insert(locations);
const { data: locationsAgreements } = await global.axios.get(
"/locations_agreements"
);
const { data: locationsAgreements } = await global.axios.get("/locations_agreements");
await knex("api.locations_agreements").insert(locationsAgreements);
......
......@@ -10,7 +10,7 @@ const LABOR_LAW_REFERENCES_LENGTH = LABOR_LAW_REFERENCES.length;
function getRandomAnswerReference(answerId, category) {
const answerReference = {
answer_id: answerId,
category
category,
};
switch (category) {
......@@ -18,21 +18,21 @@ function getRandomAnswerReference(answerId, category) {
return {
...answerReference,
value: dumdum.text([12, 120]),
url: Math.random() < 0.5 ? "https://example.com" : null
url: Math.random() < 0.5 ? "https://example.com" : null,
};
case ANSWER_REFERENCE_CATEGORY[1]:
return {
...answerReference,
value: `Article ${Math.ceil(Math.random() * 99)}`,
url: null
url: null,
};
case ANSWER_REFERENCE_CATEGORY[2]:
return {
...answerReference,
value: LABOR_LAW_REFERENCES[Math.floor(Math.random() * LABOR_LAW_REFERENCES_LENGTH)],
url: null
url: null,
};
}
}
......@@ -51,32 +51,14 @@ function getRandomAnswerReferences(answerId) {
return answerReferences;
}
function getRandomAnswerTags(tags, answerId) {
const answerTags = [];
let i = Math.floor(Math.random() * 5);
while (i-- > 0) {
const tagIndex = Math.floor(Math.random() * tags.length);
const tag = tags[tagIndex];
answerTags.push({
answer_id: answerId,
tag_id: tag.id
});
}
return answerTags;
}
exports.seed = async knex => {
global.spinner.start(`Generating answers...`);
const questions = await knex("api.questions");
const agreements = await knex("api.agreements");
const activeAgreementIds = await knex("api.locations_agreements").map(
({ agreement_id }) => agreement_id
({ agreement_id }) => agreement_id,
);
const tags = await knex("api.tags");
for (let question of questions) {
global.spinner.start(`Generating answers: ${question.value}`);
......@@ -86,7 +68,7 @@ exports.seed = async knex => {
prevalue: "",
value: dumdum.text([260, 620]),
question_id: question.id,
agreement_id: null
agreement_id: null,
};
await knex("api.answers").insert([genericAnswer]);
......@@ -100,7 +82,7 @@ exports.seed = async knex => {
prevalue: "",
value: "",
question_id: question.id,
agreement_id: agreement.id
agreement_id: agreement.id,
};
}
......@@ -113,7 +95,7 @@ exports.seed = async knex => {
prevalue: "",
value: "",
question_id: question.id,
agreement_id: agreement.id
agreement_id: agreement.id,
};
case dice < diceBalance[1]:
......@@ -123,7 +105,7 @@ exports.seed = async knex => {
value: "",
question_id: question.id,
agreement_id: agreement.id,
user_id: "00000000-0000-4000-8000-000000000402"
user_id: "00000000-0000-4000-8000-000000000402",
};
case dice < diceBalance[2]:
......@@ -133,7 +115,7 @@ exports.seed = async knex => {
value: "",
question_id: question.id,
agreement_id: agreement.id,
user_id: "00000000-0000-4000-8000-000000000402"
user_id: "00000000-0000-4000-8000-000000000402",
};
case dice < diceBalance[3]:
......@@ -143,7 +125,7 @@ exports.seed = async knex => {
value: dumdum.text([260, 620]),
question_id: question.id,
agreement_id: agreement.id,
user_id: "00000000-0000-4000-8000-000000000402"
user_id: "00000000-0000-4000-8000-000000000402",
};
default:
......@@ -154,7 +136,7 @@ exports.seed = async knex => {
question_id: question.id,
agreement_id: agreement.id,
user_id: "00000000-0000-4000-8000-000000000402",
is_published: Math.random() < 0.75
is_published: Math.random() < 0.75,
};
}
});
......@@ -167,19 +149,10 @@ exports.seed = async knex => {
const answersReferences = answerIds.reduce(
(prev, answerId) => [...prev, ...getRandomAnswerReferences(answerId)],
[]
[],
);
global.spinner.start(`Generating answers tags...`);
await knex("api.answers_references").insert(answersReferences);
const answersTags = answerIds.reduce(
(prev, answerId) => [...prev, ...getRandomAnswerTags(tags, answerId)],
[]
);
await knex("api.answers_tags").insert(answersTags);
}
global.spinner.succeed(`Answers generated.`);
......
const TAGS_CATEGORIES = [
{
id: "00000000-0000-4000-8000-000000000501",
value: "Cible"
},
{
id: "00000000-0000-4000-8000-000000000502",
value: "Particularisme"
},
{
id: "00000000-0000-4000-8000-000000000503",
value: "Thème"
},
{
id: "00000000-0000-4000-8000-000000000504",
value: "Type d'horaire"
},
{
id: "00000000-0000-4000-8000-000000000505",
value: "Type de contrat"
},
{
id: "00000000-0000-4000-8000-000000000506",
value: "Temps de travail"
}
];
const TAGS = [
{ value: `CDI`, tag_category_id: "00000000-0000-4000-8000-000000000505" },
{ value: `CDD`, tag_category_id: "00000000-0000-4000-8000-000000000505" },
{ value: `CTT`, tag_category_id: "00000000-0000-4000-8000-000000000505" },
{ value: `CESU`, tag_category_id: "00000000-0000-4000-8000-000000000505" },
{ value: `CEA`, tag_category_id: "00000000-0000-4000-8000-000000000505" },
{
value: `Contrat de professionnalisation`,
tag_category_id: "00000000-0000-4000-8000-000000000505"
},
{
value: `Contrat d'apprentissage`,
tag_category_id: "00000000-0000-4000-8000-000000000505"
},
{
value: `Contrat saisonnier`,
tag_category_id: "00000000-0000-4000-8000-000000000505"
},
{
value: `Contrat de travail`,
tag_category_id: "00000000-0000-4000-8000-000000000503"
},
{
value: `Durée du travail`,
tag_category_id: "00000000-0000-4000-8000-000000000503"
},
{
value: `Embauche`,
tag_category_id: "00000000-0000-4000-8000-000000000503"
},
{ value: `Rupture`, tag_category_id: "00000000-0000-4000-8000-000000000503" },
{
value: `Inaptitude`,
tag_category_id: "00000000-0000-4000-8000-000000000503"
},
{
value: `Employeur`,
tag_category_id: "00000000-0000-4000-8000-000000000501"
},
{ value: `Salarié`, tag_category_id: "00000000-0000-4000-8000-000000000501" },
{ value: `Mayotte`, tag_category_id: "00000000-0000-4000-8000-000000000502" },
{
value: `Alsace-Moselle`,
tag_category_id: "00000000-0000-4000-8000-000000000502"
},
{ value: `DOM`, tag_category_id: "00000000-0000-4000-8000-000000000502" },
{
value: `Temps plein`,
tag_category_id: "00000000-0000-4000-8000-000000000506"
},
{
value: `Temps partiel`,
tag_category_id: "00000000-0000-4000-8000-000000000506"
},
{
value: `Collectif`,
tag_category_id: "00000000-0000-4000-8000-000000000504"
},
{
value: `Individuel`,
tag_category_id: "00000000-0000-4000-8000-000000000504"
},
{ value: `Forfait`, tag_category_id: "00000000-0000-4000-8000-000000000504" }
];
exports.seed = async knex => {
global.spinner.start(`Generating tags categories...`);
await knex("api.tags_categories").insert(TAGS_CATEGORIES);
global.spinner.succeed(`Tags categories generated.`);
global.spinner.start(`Generating tags...`);
await knex("api.tags").insert(TAGS);
global.spinner.succeed(`Tags generated.`);
};
No preview for this file type
......@@ -13,7 +13,6 @@ services:
volumes:
- postgre-data:/var/lib/postgresql/data
- ./backups:/backups
- ./scripts/docker/db:/scripts
# https://postgrest.org/en/stable/install.html#containerized-postgrest-and-db-with-docker-compose
postgrest:
......
......@@ -8,7 +8,7 @@ Feature: Login
When I log into the application
Then I should see the title "Tableau de bord"
And I should see the subtitle "Global"
And I should see the subtitle "Par région"
And I should see the subtitle "Par unité régionale"
And I should see the subtitle "Par convention collective"
Scenario: Successfully login as a contributor
......@@ -21,5 +21,5 @@ Feature: Login
When I log into the application
Then I should see the title "Tableau de bord"
And I should see the subtitle "Global"
And I should see the subtitle "Par région"
And I should see the subtitle "Par unité régionale"
And I should see the subtitle "Par convention collective"
......@@ -11,7 +11,7 @@ if (NODE_ENV !== "production") {
const knexClient = knex({
client: "pg",
connection: DB_URI
connection: DB_URI,
});
async function logActions(proxyReq, req) {
......@@ -42,7 +42,7 @@ async function logActions(proxyReq, req) {
ip,
action: method.toLowerCase(),
url,
user_id
user_id,
};
await knexClient("api.logs").insert([log]);
......
......@@ -4,16 +4,20 @@ extends:
rules:
no-console: ["error", { allow: ["info", "error", "warn"] }]
jest/no-disabled-tests: off
react/jsx-sort-props: error
react/prop-types: off
overrides:
- files:
- "jest.setup.js"
- "*.test.js"
env:
jest: true
globals:
testRender: true
waitFor: true
- files:
- "./src/templates/**/*.js"
rules:
react/prop-types: error
......@@ -4,7 +4,7 @@ module.exports = {
displayName: pack.name,
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|svg|ttf|woff|woff2)$": "<rootDir>/tests/mappers/fileTransformer.js",
"\\.css$": "identity-obj-proxy"
"\\.css$": "identity-obj-proxy",
},