diff --git a/.vscode/launch.json b/.vscode/launch.json index 482aadd5b4393d648a6ce8d8c58f9e994d1429e5..3832a3860455d4d99bbf29fc8ad91a6ab9b94cf5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,7 +15,12 @@ "program": "${workspaceFolder}/main.go", "env": { "HTTP_PORT": "8080", - "DEBUG_MODE": "true" + "DEBUG_MODE": "true", + "API_TOKEN": "", + "EMAIL_SENDER_ADDRESS": "glcpro@alpha.grandlyon.com", + "EMAIL_SENDER_PASSWORD": "", + "EMAIL_SMTP_SERVER": "mail.alpha.grandlyon.com", + "EMAIL_SMTP_PORT": "587" }, "showLog": true } diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000000000000000000000000000000000000..6682a5d02257a2180ba5e041f64078a3cb64e071 --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +[ ] Remove references to localhost and ports +[ ] Tests +[ ] Remove useless fmt.Print diff --git a/configs/apicache.json b/configs/apicache.json index 1788a8d38b8e7032c62cf736cb10cdb64d7895d1..8333e253d1c13fb6d50e5bdc9c8d9a945e9b6464 100644 --- a/configs/apicache.json +++ b/configs/apicache.json @@ -1,263 +1,522 @@ { - "200046977": { - "etablissement": { - "siege_social": false, - "siret": "", - "naf": "", - "libelle_naf": "", - "date_mise_a_jour": 0, - "tranche_effectif_salarie_etablissement": { - "de": 0, - "a": 0, - "code": "", - "date_reference": "", - "intitule": "" - }, - "date_creation_etablissement": 0, - "region_implantation": { - "code": "", - "value": "" - }, - "commune_implantation": { - "code": "", - "value": "" - }, - "pays_implantation": { - "code": "", - "value": "" - }, - "diffusable_commercialement": false, - "enseigne": "", - "adresse": { - "l1": "", - "l2": "", - "l3": "", - "l4": "", - "l5": "", - "l6": "", - "l7": "", - "numero_voie": "", - "type_voie": "", - "nom_voie": "", - "complement_adresse": "", - "code_postal": "", - "localite": "", - "code_insee_localite": "", - "cedex": "" - }, - "etat_administratif": { - "value": "", - "date_fermeture": "" - } - }, - "entreprise": { - "siren": "200046977", - "capital_social": "", - "numero_tva_intracommunautaire": "FR03200046977", - "forme_juridique": "(Autre) Collectivité territoriale", - "forme_juridique_code": "7229", - "nom_commercial": "", - "procedure_collective": false, - "enseigne": "", - "libelle_naf_entreprise": "Administration publique générale", - "naf_entreprise": "8411Z", - "raison_sociale": "METROPOLE DE LYON", - "siret_siege_social": "20004697700019", - "code_effectif_entreprise": "52", - "date_creation": 1420066800, - "nom": "", - "prenom": "", - "date_radiation": "", - "categorie_entreprise": "GE", - "tranche_effectif_salarie_entreprise": { - "de": 5000, - "a": 9999, - "code": "52", - "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" - }, - "mandataires_sociaux": [], - "etat_administratif": { - "value": "A", - "date_cessation": "" - }, - "diffusable_commercialement": true - }, - "gateway_error": false - }, - "20004697700019": { - "etablissement": { - "siege_social": true, - "siret": "20004697700019", - "naf": "8411Z", - "libelle_naf": "Administration publique générale", - "date_mise_a_jour": 1598343294, - "tranche_effectif_salarie_etablissement": { - "de": 5000, - "a": 9999, - "code": "52", - "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" - }, - "date_creation_etablissement": 1420066800, - "region_implantation": { - "code": "84", - "value": "Auvergne-Rhône-Alpes" - }, - "commune_implantation": { - "code": "69383", - "value": "Lyon 3e Arrondissement" - }, - "pays_implantation": { - "code": "FR", - "value": "FRANCE" - }, - "diffusable_commercialement": true, - "enseigne": "", - "adresse": { - "l1": "METROPOLE DE LYON", - "l2": "", - "l3": "", - "l4": "20 RUE DU LAC", - "l5": "BP 3103", - "l6": "69003 LYON 3EME", - "l7": "FRANCE", - "numero_voie": "20", - "type_voie": "RUE", - "nom_voie": "DU LAC", - "complement_adresse": "", - "code_postal": "69003", - "localite": "LYON 3EME", - "code_insee_localite": "69383", - "cedex": "" - }, - "etat_administratif": { - "value": "A", - "date_fermeture": "" - } - }, - "entreprise": { - "siren": "", - "capital_social": "", - "numero_tva_intracommunautaire": "", - "forme_juridique": "", - "forme_juridique_code": "", - "nom_commercial": "", - "procedure_collective": false, - "enseigne": "", - "libelle_naf_entreprise": "", - "naf_entreprise": "", - "raison_sociale": "", - "siret_siege_social": "", - "code_effectif_entreprise": "", - "date_creation": 0, - "nom": "", - "prenom": "", - "date_radiation": "", - "categorie_entreprise": "", - "tranche_effectif_salarie_entreprise": { - "de": 0, - "a": 0, - "code": "", - "date_reference": "", - "intitule": "" - }, - "mandataires_sociaux": null, - "etat_administratif": { - "value": "", - "date_cessation": "" - }, - "diffusable_commercialement": false - }, - "gateway_error": false - }, - "000000001": { - "entreprise": { - "siren": "000000001", - "capital_social": "", - "numero_tva_intracommunautaire": "FR01", - "forme_juridique": "(Autre) Test", - "forme_juridique_code": "7229", - "nom_commercial": "", - "procedure_collective": false, - "enseigne": "", - "libelle_naf_entreprise": "Entreprise de test", - "naf_entreprise": "8411Z", - "raison_sociale": "THE TEST COMPANY", - "siret_siege_social": "00000000100001", - "code_effectif_entreprise": "52", - "date_creation": 1420066800, - "nom": "Angela Claire Louise", - "prenom": "DUBOIS", - "date_radiation": "", - "categorie_entreprise": "GE", - "tranche_effectif_salarie_entreprise": { - "de": 5000, - "a": 9999, - "code": "52", - "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" - }, - "mandataires_sociaux": [], - "etat_administratif": { - "value": "A", - "date_cessation": "" - }, - "diffusable_commercialement": true - }, - "gateway_error": false - }, - "00000000100001": { - "etablissement": { - "siege_social": true, - "siret": "00000000100001", - "naf": "8411Z", - "libelle_naf": "Entreprise de test", - "date_mise_a_jour": 1598343294, - "tranche_effectif_salarie_etablissement": { - "de": 5000, - "a": 9999, - "code": "52", - "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" - }, - "date_creation_etablissement": 1420066800, - "region_implantation": { - "code": "84", - "value": "Auvergne-Rhône-Alpes" - }, - "commune_implantation": { - "code": "69383", - "value": "Lyon 3e Arrondissement" - }, - "pays_implantation": { - "code": "FR", - "value": "FRANCE" - }, - "diffusable_commercialement": true, - "enseigne": "", - "adresse": { - "l1": "THE TEST COMPANY", - "l2": "", - "l3": "", - "l4": "2000 RUE DU LAC", - "l5": "BP 3120", - "l6": "69003 LYON 3EME", - "l7": "FRANCE", - "numero_voie": "2000", - "type_voie": "RUE", - "nom_voie": "DU LAC", - "complement_adresse": "", - "code_postal": "69003", - "localite": "LYON 3EME", - "code_insee_localite": "69383", - "cedex": "" - }, - "etat_administratif": { - "value": "A", - "date_fermeture": "" - } - }, - "gateway_error": false - } -} + "000000001": { + "etablissement": { + "siege_social": false, + "siret": "", + "naf": "", + "libelle_naf": "", + "date_mise_a_jour": 0, + "tranche_effectif_salarie_etablissement": { + "de": 0, + "a": 0, + "code": "", + "date_reference": "", + "intitule": "" + }, + "date_creation_etablissement": 0, + "region_implantation": { + "code": "", + "value": "" + }, + "commune_implantation": { + "code": "", + "value": "" + }, + "pays_implantation": { + "code": "", + "value": "" + }, + "diffusable_commercialement": false, + "enseigne": "", + "adresse": { + "l1": "", + "l2": "", + "l3": "", + "l4": "", + "l5": "", + "l6": "", + "l7": "", + "numero_voie": "", + "type_voie": "", + "nom_voie": "", + "complement_adresse": "", + "code_postal": "", + "localite": "", + "code_insee_localite": "", + "cedex": "" + }, + "etat_administratif": { + "value": "", + "date_fermeture": "" + } + }, + "entreprise": { + "siren": "000000001", + "capital_social": 15000, + "numero_tva_intracommunautaire": "----", + "forme_juridique": "Société à responsabilité limitée (sans autre indication)", + "forme_juridique_code": "5499", + "nom_commercial": "", + "procedure_collective": false, + "enseigne": "", + "libelle_naf_entreprise": "Entreprise de test", + "naf_entreprise": "5610C", + "raison_sociale": "THE TEST COMPANY", + "siret_siege_social": "00000000100001", + "code_effectif_entreprise": "02", + "date_creation": 1424041200, + "nom": "", + "prenom": "", + "date_radiation": "", + "categorie_entreprise": "PME", + "tranche_effectif_salarie_entreprise": { + "de": 3, + "a": 5, + "code": "02", + "date_reference": "2018", + "intitule": "3 à 5 salariés" + }, + "mandataires_sociaux": [ + { + "nom": "DUBOIS", + "prenom": "Angela Claire Louise", + "fonction": "GERANT", + "date_naissance": "1962-08-24", + "date_naissance_timestamp": 863992800, + "dirigeant": true, + "raison_sociale": "", + "identifiant": "", + "type": "PP" + } + ], + "etat_administratif": { + "value": "A", + "date_cessation": "" + }, + "diffusable_commercialement": true + }, + "gateway_error": false + }, + "00000000100001": { + "etablissement": { + "siege_social": true, + "siret": "00000000100001", + "naf": "8411Z", + "libelle_naf": "Entreprise de test", + "date_mise_a_jour": 1598343294, + "tranche_effectif_salarie_etablissement": { + "de": 5000, + "a": 9999, + "code": "52", + "date_reference": "2018", + "intitule": "5 000 à 9 999 salariés" + }, + "date_creation_etablissement": 1420066800, + "region_implantation": { + "code": "84", + "value": "Auvergne-Rhône-Alpes" + }, + "commune_implantation": { + "code": "69383", + "value": "Lyon 3e Arrondissement" + }, + "pays_implantation": { + "code": "FR", + "value": "FRANCE" + }, + "diffusable_commercialement": true, + "enseigne": "", + "adresse": { + "l1": "THE TEST COMPANY", + "l2": "", + "l3": "", + "l4": "2000 RUE DU LAC", + "l5": "BP 3120", + "l6": "69003 LYON 3EME", + "l7": "FRANCE", + "numero_voie": "2000", + "type_voie": "RUE", + "nom_voie": "DU LAC", + "complement_adresse": "", + "code_postal": "69003", + "localite": "LYON 3EME", + "code_insee_localite": "69383", + "cedex": "" + }, + "etat_administratif": { + "value": "A", + "date_fermeture": "" + } + }, + "entreprise": { + "siren": "", + "capital_social": 0, + "numero_tva_intracommunautaire": "", + "forme_juridique": "", + "forme_juridique_code": "", + "nom_commercial": "", + "procedure_collective": false, + "enseigne": "", + "libelle_naf_entreprise": "", + "naf_entreprise": "", + "raison_sociale": "", + "siret_siege_social": "", + "code_effectif_entreprise": "", + "date_creation": 0, + "nom": "", + "prenom": "", + "date_radiation": "", + "categorie_entreprise": "", + "tranche_effectif_salarie_entreprise": { + "de": 0, + "a": 0, + "code": "", + "date_reference": "", + "intitule": "" + }, + "mandataires_sociaux": null, + "etat_administratif": { + "value": "", + "date_cessation": "" + }, + "diffusable_commercialement": false + }, + "gateway_error": false + }, + "200046977": { + "etablissement": { + "siege_social": false, + "siret": "", + "naf": "", + "libelle_naf": "", + "date_mise_a_jour": 0, + "tranche_effectif_salarie_etablissement": { + "de": 0, + "a": 0, + "code": "", + "date_reference": "", + "intitule": "" + }, + "date_creation_etablissement": 0, + "region_implantation": { + "code": "", + "value": "" + }, + "commune_implantation": { + "code": "", + "value": "" + }, + "pays_implantation": { + "code": "", + "value": "" + }, + "diffusable_commercialement": false, + "enseigne": "", + "adresse": { + "l1": "", + "l2": "", + "l3": "", + "l4": "", + "l5": "", + "l6": "", + "l7": "", + "numero_voie": "", + "type_voie": "", + "nom_voie": "", + "complement_adresse": "", + "code_postal": "", + "localite": "", + "code_insee_localite": "", + "cedex": "" + }, + "etat_administratif": { + "value": "", + "date_fermeture": "" + } + }, + "entreprise": { + "siren": "200046977", + "capital_social": 0, + "numero_tva_intracommunautaire": "FR03200046977", + "forme_juridique": "(Autre) Collectivité territoriale", + "forme_juridique_code": "7229", + "nom_commercial": "", + "procedure_collective": false, + "enseigne": "", + "libelle_naf_entreprise": "Administration publique générale", + "naf_entreprise": "8411Z", + "raison_sociale": "METROPOLE DE LYON", + "siret_siege_social": "20004697700019", + "code_effectif_entreprise": "52", + "date_creation": 1420066800, + "nom": "", + "prenom": "", + "date_radiation": "", + "categorie_entreprise": "GE", + "tranche_effectif_salarie_entreprise": { + "de": 5000, + "a": 9999, + "code": "52", + "date_reference": "2018", + "intitule": "5 000 à 9 999 salariés" + }, + "mandataires_sociaux": [], + "etat_administratif": { + "value": "A", + "date_cessation": "" + }, + "diffusable_commercialement": true + }, + "gateway_error": false + }, + "20004697700019": { + "etablissement": { + "siege_social": true, + "siret": "20004697700019", + "naf": "8411Z", + "libelle_naf": "Administration publique générale", + "date_mise_a_jour": 1598343294, + "tranche_effectif_salarie_etablissement": { + "de": 5000, + "a": 9999, + "code": "52", + "date_reference": "2018", + "intitule": "5 000 à 9 999 salariés" + }, + "date_creation_etablissement": 1420066800, + "region_implantation": { + "code": "84", + "value": "Auvergne-Rhône-Alpes" + }, + "commune_implantation": { + "code": "69383", + "value": "Lyon 3e Arrondissement" + }, + "pays_implantation": { + "code": "FR", + "value": "FRANCE" + }, + "diffusable_commercialement": true, + "enseigne": "", + "adresse": { + "l1": "METROPOLE DE LYON", + "l2": "", + "l3": "", + "l4": "20 RUE DU LAC", + "l5": "BP 3103", + "l6": "69003 LYON 3EME", + "l7": "FRANCE", + "numero_voie": "20", + "type_voie": "RUE", + "nom_voie": "DU LAC", + "complement_adresse": "", + "code_postal": "69003", + "localite": "LYON 3EME", + "code_insee_localite": "69383", + "cedex": "" + }, + "etat_administratif": { + "value": "A", + "date_fermeture": "" + } + }, + "entreprise": { + "siren": "", + "capital_social": 0, + "numero_tva_intracommunautaire": "", + "forme_juridique": "", + "forme_juridique_code": "", + "nom_commercial": "", + "procedure_collective": false, + "enseigne": "", + "libelle_naf_entreprise": "", + "naf_entreprise": "", + "raison_sociale": "", + "siret_siege_social": "", + "code_effectif_entreprise": "", + "date_creation": 0, + "nom": "", + "prenom": "", + "date_radiation": "", + "categorie_entreprise": "", + "tranche_effectif_salarie_entreprise": { + "de": 0, + "a": 0, + "code": "", + "date_reference": "", + "intitule": "" + }, + "mandataires_sociaux": null, + "etat_administratif": { + "value": "", + "date_cessation": "" + }, + "diffusable_commercialement": false + }, + "gateway_error": false + }, + "350127460": { + "etablissement": { + "siege_social": false, + "siret": "", + "naf": "", + "libelle_naf": "", + "date_mise_a_jour": 0, + "tranche_effectif_salarie_etablissement": { + "de": 0, + "a": 0, + "code": "", + "date_reference": "", + "intitule": "" + }, + "date_creation_etablissement": 0, + "region_implantation": { + "code": "", + "value": "" + }, + "commune_implantation": { + "code": "", + "value": "" + }, + "pays_implantation": { + "code": "", + "value": "" + }, + "diffusable_commercialement": false, + "enseigne": "", + "adresse": { + "l1": "", + "l2": "", + "l3": "", + "l4": "", + "l5": "", + "l6": "", + "l7": "", + "numero_voie": "", + "type_voie": "", + "nom_voie": "", + "complement_adresse": "", + "code_postal": "", + "localite": "", + "code_insee_localite": "", + "cedex": "" + }, + "etat_administratif": { + "value": "", + "date_fermeture": "" + } + }, + "entreprise": { + "siren": "350127460", + "capital_social": 58500, + "numero_tva_intracommunautaire": "FR44350127460", + "forme_juridique": "SA à conseil d'administration (s.a.i.)", + "forme_juridique_code": "5599", + "nom_commercial": "", + "procedure_collective": false, + "enseigne": "", + "libelle_naf_entreprise": "Commerce de détail d'ordinateurs, d'unités périphériques et de logiciels en magasin spécialisé", + "naf_entreprise": "4741Z", + "raison_sociale": "FNAC PARIS", + "siret_siege_social": "35012746000284", + "code_effectif_entreprise": "42", + "date_creation": 604710000, + "nom": "", + "prenom": "", + "date_radiation": "", + "categorie_entreprise": "GE", + "tranche_effectif_salarie_entreprise": { + "de": 1000, + "a": 1999, + "code": "42", + "date_reference": "2018", + "intitule": "1 000 à 1 999 salariés" + }, + "mandataires_sociaux": [ + { + "nom": "GAZUIT", + "prenom": "FRANCOIS", + "fonction": "PRESIDENT DU CONSEIL D'ADMINISTRATION", + "date_naissance": "1963-08-31", + "date_naissance_timestamp": -200019600, + "dirigeant": true, + "raison_sociale": "", + "identifiant": "", + "type": "PP" + }, + { + "nom": "GAZUIT", + "prenom": "FRANCOIS", + "fonction": "DIRECTEUR GENERAL", + "date_naissance": "1963-08-31", + "date_naissance_timestamp": -200019600, + "dirigeant": true, + "raison_sociale": "", + "identifiant": "", + "type": "PP" + }, + { + "nom": "", + "prenom": "", + "fonction": "ADMINISTRATEUR", + "date_naissance": "", + "date_naissance_timestamp": 0, + "dirigeant": true, + "raison_sociale": "FNAC PERIPHERIE - SOCIETE PAR ACTIONS SIMPLIFIEE A ASSOCIE UNIQUE", + "identifiant": "434001954", + "type": "PM" + }, + { + "nom": "", + "prenom": "", + "fonction": "ADMINISTRATEUR", + "date_naissance": "", + "date_naissance_timestamp": 0, + "dirigeant": true, + "raison_sociale": "FNAC DARTY PARTICIPATIONS ET SERVICES - SOCIETE ANONYME", + "identifiant": "775661390", + "type": "PM" + }, + { + "nom": "DALI", + "prenom": "ABDELKRIM", + "fonction": "ADMINISTRATEUR", + "date_naissance": "1964-11-28", + "date_naissance_timestamp": -160707600, + "dirigeant": true, + "raison_sociale": "", + "identifiant": "", + "type": "PP" + }, + { + "nom": "GAZUIT", + "prenom": "FRANCOIS", + "fonction": "ADMINISTRATEUR", + "date_naissance": "1963-08-31", + "date_naissance_timestamp": -200019600, + "dirigeant": true, + "raison_sociale": "", + "identifiant": "", + "type": "PP" + }, + { + "nom": "", + "prenom": "", + "fonction": "COMMISSAIRE AUX COMPTES TITULAIRE", + "date_naissance": "", + "date_naissance_timestamp": 0, + "dirigeant": true, + "raison_sociale": "KPMG S.A - SOCIETE ANONYME", + "identifiant": "775726417", + "type": "PM" + } + ], + "etat_administratif": { + "value": "A", + "date_cessation": "" + }, + "diffusable_commercialement": true + }, + "gateway_error": false + } +} \ No newline at end of file diff --git a/internal/mockapientreprise/mockapientreprise.go b/internal/mockapientreprise/mockapientreprise.go deleted file mode 100644 index d3bf4c2327a93e73f3a6219d9d264a733bfa0669..0000000000000000000000000000000000000000 --- a/internal/mockapientreprise/mockapientreprise.go +++ /dev/null @@ -1,104 +0,0 @@ -// Package mockapientreprise provide mocks for development purposes (debug mode) -package mockapientreprise - -import ( - "net/http" -) - -// CreateMockOAuth2 creates a mock OAuth2 serve mux for development purposes -func CreateMock2() *http.ServeMux { - mux := http.NewServeMux() - // Returns userinfo back to the user - mux.HandleFunc("/v2/entreprise", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - w.Write([]byte(` - { - "entreprise": { - "siren": "200046977", - "capital_social": null, - "numero_tva_intracommunautaire": "FR03200046977", - "forme_juridique": "(Autre) Collectivité territoriale", - "forme_juridique_code": "7229", - "nom_commercial": "", - "procedure_collective": false, - "enseigne": null, - "libelle_naf_entreprise": "Administration publique générale", - "naf_entreprise": "8411Z", - "raison_sociale": "METROPOLE DE LYON", - "siret_siege_social": "20004697700019", - "code_effectif_entreprise": "52", - "date_creation": 1420066800, - "nom": null, - "prenom": null, - "date_radiation": null, - "categorie_entreprise": "GE", - "tranche_effectif_salarie_entreprise": { - "de": 5000, - "a": 9999, - "code": "52", - "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" - }, - "mandataires_sociaux": [], - "etat_administratif": { - "value": "A", - "date_cessation": null - }, - "diffusable_commercialement": true - }, - "etablissement_siege": { - "siege_social": true, - "siret": "20004697700019", - "naf": "8411Z", - "libelle_naf": "Administration publique générale", - "date_mise_a_jour": 1598343294, - "tranche_effectif_salarie_etablissement": { - "de": 5000, - "a": 9999, - "code": "52", - "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" - }, - "date_creation_etablissement": 1420066800, - "region_implantation": { - "code": "84", - "value": "Auvergne-Rhône-Alpes" - }, - "commune_implantation": { - "code": "69383", - "value": "Lyon 3e Arrondissement" - }, - "pays_implantation": { - "code": "FR", - "value": "FRANCE" - }, - "diffusable_commercialement": true, - "enseigne": null, - "adresse": { - "l1": "METROPOLE DE LYON", - "l2": null, - "l3": null, - "l4": "20 RUE DU LAC", - "l5": "BP 3103", - "l6": "69003 LYON 3EME", - "l7": "FRANCE", - "numero_voie": "20", - "type_voie": "RUE", - "nom_voie": "DU LAC", - "complement_adresse": null, - "code_postal": "69003", - "localite": "LYON 3EME", - "code_insee_localite": "69383", - "cedex": null - }, - "etat_administratif": { - "value": "A", - "date_fermeture": null - } - }, - "gateway_error": false - } - `)) - }) - return mux -} diff --git a/internal/rootmux/rootmux.go b/internal/rootmux/rootmux.go index 82aed8c065ed3c8803217397c19ac61715255b90..c24100da7d78a371d402e002f688279b0a4f52ba 100644 --- a/internal/rootmux/rootmux.go +++ b/internal/rootmux/rootmux.go @@ -5,8 +5,9 @@ import ( "net/http" "forge.grandlyon.com/npernoud/glcpro/pkg/common" + "forge.grandlyon.com/npernoud/glcpro/pkg/matcher" "forge.grandlyon.com/npernoud/glcpro/pkg/middlewares" - oidcserver "forge.grandlyon.com/npernoud/glcpro/pkg/oidc2server" + "forge.grandlyon.com/npernoud/glcpro/pkg/oidcserver" ) // CreateRootMux creates a RootMux @@ -19,6 +20,7 @@ func CreateRootMux(staticDir string) *http.ServeMux { }) mainMux.Handle("/api/", http.StripPrefix("/api", apiMux)) mainMux.Handle("/api/oidc/", middlewares.Cors(http.StripPrefix("/api/oidc", oidcserver.CreateOIDCServer()))) + mainMux.Handle("/api/matcher/", middlewares.Cors(http.StripPrefix("/api/matcher", matcher.CreateMatcherServer()))) // Serve static files falling back to serving index.html mainMux.Handle("/", middlewares.NoCache(http.FileServer(&common.FallBackWrapper{Assets: http.Dir(staticDir)}))) // Put it together into the main handler diff --git a/mailtemplate.html b/mailtemplate.html new file mode 100644 index 0000000000000000000000000000000000000000..35abb6a4e1300c8ec77a1e31cca5036f0c8305ca --- /dev/null +++ b/mailtemplate.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<html> + <body> + <h1>Demande de mandatement Grand Lyon Connect PRO</h1> + <p> + Bonjour {{.Mandate}} vous demande de l'habiliter pour agir au nom de + l'entreprise ou de l'établissement portant le numéro SIREN/SIRET + {{.Sirent}}. + </p> + <p>Pour valider cette demande, veuillez cliquer sur ce lien :</p> + <a href="localhost:8080/api/matcher/validate&code={{.Token}}">Valider</a> + <p> + Pour refuser cette demande, il suffit de ne rien faire et de supprimer ce + mail. + </p> + </body> +</html> diff --git a/pkg/apientreprise/apicache.json b/pkg/apientreprise/apicache.json deleted file mode 100644 index dd15c83da3147dee907756ec00ae38eb3f577eeb..0000000000000000000000000000000000000000 --- a/pkg/apientreprise/apicache.json +++ /dev/null @@ -1,263 +0,0 @@ -{ - "200046977": { - "etablissement": { - "siege_social": false, - "siret": "", - "naf": "", - "libelle_naf": "", - "date_mise_a_jour": 0, - "tranche_effectif_salarie_etablissement": { - "de": 0, - "a": 0, - "code": "", - "date_reference": "", - "intitule": "" - }, - "date_creation_etablissement": 0, - "region_implantation": { - "code": "", - "value": "" - }, - "commune_implantation": { - "code": "", - "value": "" - }, - "pays_implantation": { - "code": "", - "value": "" - }, - "diffusable_commercialement": false, - "enseigne": "", - "adresse": { - "l1": "", - "l2": "", - "l3": "", - "l4": "", - "l5": "", - "l6": "", - "l7": "", - "numero_voie": "", - "type_voie": "", - "nom_voie": "", - "complement_adresse": "", - "code_postal": "", - "localite": "", - "code_insee_localite": "", - "cedex": "" - }, - "etat_administratif": { - "value": "", - "date_fermeture": "" - } - }, - "entreprise": { - "siren": "200046977", - "capital_social": "", - "numero_tva_intracommunautaire": "FR03200046977", - "forme_juridique": "(Autre) Collectivité territoriale", - "forme_juridique_code": "7229", - "nom_commercial": "", - "procedure_collective": false, - "enseigne": "", - "libelle_naf_entreprise": "Administration publique générale", - "naf_entreprise": "8411Z", - "raison_sociale": "METROPOLE DE LYON", - "siret_siege_social": "20004697700019", - "code_effectif_entreprise": "52", - "date_creation": 1420066800, - "nom": "", - "prenom": "", - "date_radiation": "", - "categorie_entreprise": "GE", - "tranche_effectif_salarie_entreprise": { - "de": 5000, - "a": 9999, - "code": "52", - "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" - }, - "mandataires_sociaux": [], - "etat_administratif": { - "value": "A", - "date_cessation": "" - }, - "diffusable_commercialement": true - }, - "gateway_error": false - }, - "20004697700019": { - "etablissement": { - "siege_social": true, - "siret": "20004697700019", - "naf": "8411Z", - "libelle_naf": "Administration publique générale", - "date_mise_a_jour": 1598343294, - "tranche_effectif_salarie_etablissement": { - "de": 5000, - "a": 9999, - "code": "52", - "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" - }, - "date_creation_etablissement": 1420066800, - "region_implantation": { - "code": "84", - "value": "Auvergne-Rhône-Alpes" - }, - "commune_implantation": { - "code": "69383", - "value": "Lyon 3e Arrondissement" - }, - "pays_implantation": { - "code": "FR", - "value": "FRANCE" - }, - "diffusable_commercialement": true, - "enseigne": "", - "adresse": { - "l1": "METROPOLE DE LYON", - "l2": "", - "l3": "", - "l4": "20 RUE DU LAC", - "l5": "BP 3103", - "l6": "69003 LYON 3EME", - "l7": "FRANCE", - "numero_voie": "20", - "type_voie": "RUE", - "nom_voie": "DU LAC", - "complement_adresse": "", - "code_postal": "69003", - "localite": "LYON 3EME", - "code_insee_localite": "69383", - "cedex": "" - }, - "etat_administratif": { - "value": "A", - "date_fermeture": "" - } - }, - "entreprise": { - "siren": "", - "capital_social": "", - "numero_tva_intracommunautaire": "", - "forme_juridique": "", - "forme_juridique_code": "", - "nom_commercial": "", - "procedure_collective": false, - "enseigne": "", - "libelle_naf_entreprise": "", - "naf_entreprise": "", - "raison_sociale": "", - "siret_siege_social": "", - "code_effectif_entreprise": "", - "date_creation": 0, - "nom": "", - "prenom": "", - "date_radiation": "", - "categorie_entreprise": "", - "tranche_effectif_salarie_entreprise": { - "de": 0, - "a": 0, - "code": "", - "date_reference": "", - "intitule": "" - }, - "mandataires_sociaux": null, - "etat_administratif": { - "value": "", - "date_cessation": "" - }, - "diffusable_commercialement": false - }, - "gateway_error": false - }, - "000000001": { - "entreprise": { - "siren": "000000001", - "capital_social": "", - "numero_tva_intracommunautaire": "FR01", - "forme_juridique": "(Autre) Test", - "forme_juridique_code": "7229", - "nom_commercial": "", - "procedure_collective": false, - "enseigne": "", - "libelle_naf_entreprise": "Entreprise de test", - "naf_entreprise": "8411Z", - "raison_sociale": "THE TEST COMPANY", - "siret_siege_social": "00000000100001", - "code_effectif_entreprise": "52", - "date_creation": 1420066800, - "nom": "Yvan", - "prenom": "Duvent", - "date_radiation": "", - "categorie_entreprise": "GE", - "tranche_effectif_salarie_entreprise": { - "de": 5000, - "a": 9999, - "code": "52", - "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" - }, - "mandataires_sociaux": [], - "etat_administratif": { - "value": "A", - "date_cessation": "" - }, - "diffusable_commercialement": true - }, - "gateway_error": false - }, - "00000000100001": { - "etablissement": { - "siege_social": true, - "siret": "00000000100001", - "naf": "8411Z", - "libelle_naf": "Entreprise de test", - "date_mise_a_jour": 1598343294, - "tranche_effectif_salarie_etablissement": { - "de": 5000, - "a": 9999, - "code": "52", - "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" - }, - "date_creation_etablissement": 1420066800, - "region_implantation": { - "code": "84", - "value": "Auvergne-Rhône-Alpes" - }, - "commune_implantation": { - "code": "69383", - "value": "Lyon 3e Arrondissement" - }, - "pays_implantation": { - "code": "FR", - "value": "FRANCE" - }, - "diffusable_commercialement": true, - "enseigne": "", - "adresse": { - "l1": "THE TEST COMPANY", - "l2": "", - "l3": "", - "l4": "2000 RUE DU LAC", - "l5": "BP 3120", - "l6": "69003 LYON 3EME", - "l7": "FRANCE", - "numero_voie": "2000", - "type_voie": "RUE", - "nom_voie": "DU LAC", - "complement_adresse": "", - "code_postal": "69003", - "localite": "LYON 3EME", - "code_insee_localite": "69383", - "cedex": "" - }, - "etat_administratif": { - "value": "A", - "date_fermeture": "" - } - }, - "gateway_error": false - } -} diff --git a/pkg/apientreprise/apientreprise.go b/pkg/apientreprise/apientreprise.go index c05315cfac89a901a6b029d70464336f35f7d29f..a641b8135354db86ac23a20e3d58a7ca273ee12c 100644 --- a/pkg/apientreprise/apientreprise.go +++ b/pkg/apientreprise/apientreprise.go @@ -30,7 +30,7 @@ type APIResponse struct { type Entreprise struct { Siren string `json:"siren"` - CapitalSocial string `json:"capital_social"` + CapitalSocial int `json:"capital_social"` NumeroTvaIntracommunautaire string `json:"numero_tva_intracommunautaire"` FormeJuridique string `json:"forme_juridique"` FormeJuridiqueCode string `json:"forme_juridique_code"` @@ -54,8 +54,18 @@ type Entreprise struct { DateReference string `json:"date_reference"` Intitule string `json:"intitule"` } `json:"tranche_effectif_salarie_entreprise"` - MandatairesSociaux []string `json:"mandataires_sociaux"` - EtatAdministratif struct { + MandatairesSociaux []struct { + Nom string `json:"nom"` + Prenom string `json:"prenom"` + Fonction string `json:"fonction"` + DateNaissance string `json:"date_naissance"` + DateNaissanceTimestamp int `json:"date_naissance_timestamp"` + Dirigeant bool `json:"dirigeant"` + RaisonSociale string `json:"raison_sociale"` + Identifiant string `json:"identifiant"` + Type string `json:"type"` + } `json:"mandataires_sociaux"` + EtatAdministratif struct { Value string `json:"value"` DateCessation string `json:"date_cessation"` } `json:"etat_administratif"` diff --git a/pkg/apientreprise/apientreprise_test.go b/pkg/apientreprise/apientreprise_test.go index a8ea75df032e089c39b791f0fb542114249c4ee3..83e393a28730e18fdb44b7cd1a78cee6e6a6230c 100644 --- a/pkg/apientreprise/apientreprise_test.go +++ b/pkg/apientreprise/apientreprise_test.go @@ -7,33 +7,6 @@ import ( "testing" ) -func TestGetData2(t *testing.T) { - os.Setenv("DEBUG_MODE", "true") - iinit() - type args struct { - sirent string - } - tests := []struct { - name string - args args - wantErr bool - }{ - {"SIREN request with Métropole de Lyon SIREN", args{sirent: "200046977"}, false}, - {"SIRET request with Métropole de Lyon SIRET", args{sirent: "20004697700019"}, false}, - {"Not a sirent", args{sirent: "2000"}, true}, - {"Not a number", args{sirent: "i_am_not_even_a_number"}, true}, - {"SIREN request with test company", args{sirent: "000000001"}, false}, - {"SIRET request with test company", args{sirent: "00000000100001"}, false}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if _, _, err := GetData(tt.args.sirent); (err != nil) != tt.wantErr { - t.Errorf("GetData() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - func TestGetData(t *testing.T) { os.Setenv("DEBUG_MODE", "true") iinit() diff --git a/pkg/apientreprise/configs/apicache.json b/pkg/apientreprise/configs/apicache.json index 1788a8d38b8e7032c62cf736cb10cdb64d7895d1..bd674ef560e77523d84dd41225c5515b67e1d751 100644 --- a/pkg/apientreprise/configs/apicache.json +++ b/pkg/apientreprise/configs/apicache.json @@ -1,5 +1,5 @@ { - "200046977": { + "000000001": { "etablissement": { "siege_social": false, "siret": "", @@ -51,32 +51,44 @@ } }, "entreprise": { - "siren": "200046977", - "capital_social": "", - "numero_tva_intracommunautaire": "FR03200046977", - "forme_juridique": "(Autre) Collectivité territoriale", - "forme_juridique_code": "7229", + "siren": "000000001", + "capital_social": 15000, + "numero_tva_intracommunautaire": "----", + "forme_juridique": "Société à responsabilité limitée (sans autre indication)", + "forme_juridique_code": "5499", "nom_commercial": "", "procedure_collective": false, "enseigne": "", - "libelle_naf_entreprise": "Administration publique générale", - "naf_entreprise": "8411Z", - "raison_sociale": "METROPOLE DE LYON", - "siret_siege_social": "20004697700019", - "code_effectif_entreprise": "52", - "date_creation": 1420066800, + "libelle_naf_entreprise": "Entreprise de test", + "naf_entreprise": "5610C", + "raison_sociale": "THE TEST COMPANY", + "siret_siege_social": "00000000100001", + "code_effectif_entreprise": "02", + "date_creation": 1424041200, "nom": "", "prenom": "", "date_radiation": "", - "categorie_entreprise": "GE", + "categorie_entreprise": "PME", "tranche_effectif_salarie_entreprise": { - "de": 5000, - "a": 9999, - "code": "52", + "de": 3, + "a": 5, + "code": "02", "date_reference": "2018", - "intitule": "5 000 à 9 999 salariés" + "intitule": "3 à 5 salariés" }, - "mandataires_sociaux": [], + "mandataires_sociaux": [ + { + "nom": "Angela Claire Louise", + "prenom": "DUBOIS", + "fonction": "GERANT", + "date_naissance": "1962-08-24", + "date_naissance_timestamp": 863992800, + "dirigeant": true, + "raison_sociale": "", + "identifiant": "", + "type": "PP" + } + ], "etat_administratif": { "value": "A", "date_cessation": "" @@ -85,12 +97,12 @@ }, "gateway_error": false }, - "20004697700019": { + "00000000100001": { "etablissement": { "siege_social": true, - "siret": "20004697700019", + "siret": "00000000100001", "naf": "8411Z", - "libelle_naf": "Administration publique générale", + "libelle_naf": "Entreprise de test", "date_mise_a_jour": 1598343294, "tranche_effectif_salarie_etablissement": { "de": 5000, @@ -115,14 +127,14 @@ "diffusable_commercialement": true, "enseigne": "", "adresse": { - "l1": "METROPOLE DE LYON", + "l1": "THE TEST COMPANY", "l2": "", "l3": "", - "l4": "20 RUE DU LAC", - "l5": "BP 3103", + "l4": "2000 RUE DU LAC", + "l5": "BP 3120", "l6": "69003 LYON 3EME", "l7": "FRANCE", - "numero_voie": "20", + "numero_voie": "2000", "type_voie": "RUE", "nom_voie": "DU LAC", "complement_adresse": "", @@ -138,7 +150,7 @@ }, "entreprise": { "siren": "", - "capital_social": "", + "capital_social": 0, "numero_tva_intracommunautaire": "", "forme_juridique": "", "forme_juridique_code": "", @@ -171,24 +183,74 @@ }, "gateway_error": false }, - "000000001": { + "200046977": { + "etablissement": { + "siege_social": false, + "siret": "", + "naf": "", + "libelle_naf": "", + "date_mise_a_jour": 0, + "tranche_effectif_salarie_etablissement": { + "de": 0, + "a": 0, + "code": "", + "date_reference": "", + "intitule": "" + }, + "date_creation_etablissement": 0, + "region_implantation": { + "code": "", + "value": "" + }, + "commune_implantation": { + "code": "", + "value": "" + }, + "pays_implantation": { + "code": "", + "value": "" + }, + "diffusable_commercialement": false, + "enseigne": "", + "adresse": { + "l1": "", + "l2": "", + "l3": "", + "l4": "", + "l5": "", + "l6": "", + "l7": "", + "numero_voie": "", + "type_voie": "", + "nom_voie": "", + "complement_adresse": "", + "code_postal": "", + "localite": "", + "code_insee_localite": "", + "cedex": "" + }, + "etat_administratif": { + "value": "", + "date_fermeture": "" + } + }, "entreprise": { - "siren": "000000001", - "capital_social": "", - "numero_tva_intracommunautaire": "FR01", - "forme_juridique": "(Autre) Test", + "siren": "200046977", + "capital_social": 0, + "numero_tva_intracommunautaire": "FR03200046977", + "forme_juridique": "(Autre) Collectivité territoriale", "forme_juridique_code": "7229", "nom_commercial": "", "procedure_collective": false, "enseigne": "", - "libelle_naf_entreprise": "Entreprise de test", + "libelle_naf_entreprise": "Administration publique générale", "naf_entreprise": "8411Z", - "raison_sociale": "THE TEST COMPANY", - "siret_siege_social": "00000000100001", + "raison_sociale": "METROPOLE DE LYON", + "siret_siege_social": "20004697700019", "code_effectif_entreprise": "52", "date_creation": 1420066800, - "nom": "Angela Claire Louise", - "prenom": "DUBOIS", + "nom": "", + "prenom": "", "date_radiation": "", "categorie_entreprise": "GE", "tranche_effectif_salarie_entreprise": { @@ -207,12 +269,12 @@ }, "gateway_error": false }, - "00000000100001": { + "20004697700019": { "etablissement": { "siege_social": true, - "siret": "00000000100001", + "siret": "20004697700019", "naf": "8411Z", - "libelle_naf": "Entreprise de test", + "libelle_naf": "Administration publique générale", "date_mise_a_jour": 1598343294, "tranche_effectif_salarie_etablissement": { "de": 5000, @@ -237,14 +299,14 @@ "diffusable_commercialement": true, "enseigne": "", "adresse": { - "l1": "THE TEST COMPANY", + "l1": "METROPOLE DE LYON", "l2": "", "l3": "", - "l4": "2000 RUE DU LAC", - "l5": "BP 3120", + "l4": "20 RUE DU LAC", + "l5": "BP 3103", "l6": "69003 LYON 3EME", "l7": "FRANCE", - "numero_voie": "2000", + "numero_voie": "20", "type_voie": "RUE", "nom_voie": "DU LAC", "complement_adresse": "", @@ -258,6 +320,39 @@ "date_fermeture": "" } }, + "entreprise": { + "siren": "", + "capital_social": 0, + "numero_tva_intracommunautaire": "", + "forme_juridique": "", + "forme_juridique_code": "", + "nom_commercial": "", + "procedure_collective": false, + "enseigne": "", + "libelle_naf_entreprise": "", + "naf_entreprise": "", + "raison_sociale": "", + "siret_siege_social": "", + "code_effectif_entreprise": "", + "date_creation": 0, + "nom": "", + "prenom": "", + "date_radiation": "", + "categorie_entreprise": "", + "tranche_effectif_salarie_entreprise": { + "de": 0, + "a": 0, + "code": "", + "date_reference": "", + "intitule": "" + }, + "mandataires_sociaux": null, + "etat_administratif": { + "value": "", + "date_cessation": "" + }, + "diffusable_commercialement": false + }, "gateway_error": false } } diff --git a/pkg/matcher/mailtemplate.html b/pkg/matcher/mailtemplate.html new file mode 100644 index 0000000000000000000000000000000000000000..35abb6a4e1300c8ec77a1e31cca5036f0c8305ca --- /dev/null +++ b/pkg/matcher/mailtemplate.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<html> + <body> + <h1>Demande de mandatement Grand Lyon Connect PRO</h1> + <p> + Bonjour {{.Mandate}} vous demande de l'habiliter pour agir au nom de + l'entreprise ou de l'établissement portant le numéro SIREN/SIRET + {{.Sirent}}. + </p> + <p>Pour valider cette demande, veuillez cliquer sur ce lien :</p> + <a href="localhost:8080/api/matcher/validate&code={{.Token}}">Valider</a> + <p> + Pour refuser cette demande, il suffit de ne rien faire et de supprimer ce + mail. + </p> + </body> +</html> diff --git a/pkg/matcher/matcher.go b/pkg/matcher/matcher.go new file mode 100644 index 0000000000000000000000000000000000000000..657e7674364aec02395b8b130ba9744740ce860d --- /dev/null +++ b/pkg/matcher/matcher.go @@ -0,0 +1,120 @@ +package matcher + +import ( + "bytes" + "fmt" + "html/template" + "io/ioutil" + "net/http" + "net/smtp" + "regexp" + "time" + + "forge.grandlyon.com/npernoud/glcpro/pkg/common" + "forge.grandlyon.com/npernoud/glcpro/pkg/oidcserver" + "forge.grandlyon.com/npernoud/glcpro/pkg/tokens" +) + +var ( + emailSenderAddress = common.StringValueFromEnv("EMAIL_SENDER_ADDRESS", "") + emailSenderPassword = common.StringValueFromEnv("EMAIL_SENDER_PASSWORD", "") + emailSMTPServer = common.StringValueFromEnv("EMAIL_SMTP_SERVER", "") + emailSMTPPort = common.StringValueFromEnv("EMAIL_SMTP_PORT", "") + emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$") +) + +type MandateDemand struct { + AskerSub string + Sirent string +} + +// CreateMatcherServer creates the "matcher", being the server that handles the mandate requessts +func CreateMatcherServer() *http.ServeMux { + mux := http.NewServeMux() + mux.HandleFunc("/demand", func(w http.ResponseWriter, r *http.Request) { + + // Work out who the user is and for what sirent he wants a mandate for + rd := oidcserver.ClientRequestData{} + _, err := tokens.ExtractAndValidateToken(r, "ClientRequestData", &rd, false) + fmt.Printf("Request Data:%v\n", rd) + if err != nil { + http.Error(w, "could not get the initial client request data from cookie", http.StatusInternalServerError) + return + } + // Work out the email of the company CEO + email, err := ioutil.ReadAll(r.Body) + if err != nil || !isEmailValid(string(email)) { + http.Error(w, "email adress is invalid", http.StatusBadRequest) + return + } + + // Bundle all that into a token + m := MandateDemand{AskerSub: rd.Id.Sub, Sirent: rd.Sirent} + token, err := tokens.CreateToken(m, time.Now().Add(time.Hour*24*31)) + if err != nil { + http.Error(w, "could not create demand token", http.StatusBadRequest) + return + } + + // Send a mail to the CEO with the aforementionned token + err = sendMailToMandater(string(email), rd.Id.GivenName+" "+rd.Id.FamilyName, rd.Sirent, token) + if err != nil { + http.Error(w, "could not send email", http.StatusBadRequest) + return + } + + }) + + mux.HandleFunc("/validate", func(w http.ResponseWriter, r *http.Request) { + + // Unpack the token to work out who the mandate is for + + // Perform an France Connect authentication + + // Check that the France Connect user can create a mandate : he is the CEO of the company or has a transitive mandate + + // Create the mandate + + // TODO : Inform the original asket that is demand has been validated/rejected + + }) + return mux +} + +// isEmailValid checks if the email provided passes the required structure and length. +func isEmailValid(e string) bool { + if len(e) < 3 && len(e) > 254 { + return false + } + return emailRegex.MatchString(e) +} + +func sendMailToMandater(email string, mandate string, sirent string, token string) error { + // Receiver email address. + to := []string{ + email, + } + + // Authentication. + auth := smtp.PlainAuth("", emailSenderAddress, emailSenderPassword, emailSMTPServer) + + t, _ := template.ParseFiles("mailtemplate.html") + + var body bytes.Buffer + + mimeHeaders := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n" + body.Write([]byte(fmt.Sprintf("Subject: GLC PRO - Demande de validation de mandatement \n%s\n\n", mimeHeaders))) + + t.Execute(&body, struct { + Mandate string + Sirent string + Token string + }{ + Mandate: mandate, + Sirent: sirent, + Token: token, + }) + + // Sending email. + return smtp.SendMail(emailSMTPServer+":"+emailSMTPPort, auth, emailSenderAddress, to, body.Bytes()) +} diff --git a/pkg/matcher/matcher_test.go b/pkg/matcher/matcher_test.go new file mode 100644 index 0000000000000000000000000000000000000000..647f4c31200e5f553ce8812fabb8866dec753665 --- /dev/null +++ b/pkg/matcher/matcher_test.go @@ -0,0 +1,26 @@ +package matcher + +import "testing" + +func Test_sendMailToMandater(t *testing.T) { + type args struct { + email string + mandate string + sirent string + token string + } + tests := []struct { + name string + args args + wantErr bool + }{ + {"should work", args{"nicolas@alpha.grandlyon.com", "Mandataire", "Sirent", "TheToken"}, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := sendMailToMandater(tt.args.email, tt.args.mandate, tt.args.sirent, tt.args.token); (err != nil) != tt.wantErr { + t.Errorf("sendMailToMandater() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/pkg/matcher/test.sh b/pkg/matcher/test.sh new file mode 100755 index 0000000000000000000000000000000000000000..391faadfe8881a4a1795f72c49f105be1c67d418 --- /dev/null +++ b/pkg/matcher/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export EMAIL_SENDER_ADDRESS=glcpro@alpha.grandlyon.com +export EMAIL_SENDER_PASSWORD=*** +export EMAIL_SMTP_SERVER=mail.alpha.grandlyon.com +export EMAIL_SMTP_PORT=587 +go test . diff --git a/pkg/oidc2server/oidcserver.go b/pkg/oidcserver/oidcserver.go similarity index 90% rename from pkg/oidc2server/oidcserver.go rename to pkg/oidcserver/oidcserver.go index fc394f631eaf5fc441557d2d13d577ffacdcd070..9a07bc5da3649ad8bd4438e69149d413e3bf707a 100644 --- a/pkg/oidc2server/oidcserver.go +++ b/pkg/oidcserver/oidcserver.go @@ -17,10 +17,11 @@ import ( "forge.grandlyon.com/npernoud/glcpro/pkg/tokens" ) -type clientRequestData struct { +type ClientRequestData struct { RedirectURI string State string Sirent string + Id FCIdentity } type GLCId struct { @@ -41,7 +42,7 @@ type FCIdentity struct { // CreateOIDCServer creates a Open ID Connect Server as proxy to France Connect func CreateOIDCServer() *http.ServeMux { - rd := clientRequestData{} + rd := ClientRequestData{} mux := http.NewServeMux() // Returns authorization code back to the user mux.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) { @@ -73,12 +74,10 @@ func CreateOIDCServer() *http.ServeMux { http.Error(w, "only authorisation code flow (response_type=code) is implemented at the moment", http.StatusNotImplemented) return } - // Create a code which is an opaque token containing some data which will be transformed into a JWT on call to /token - /// TODO : --replace by a proxy to france connect--done--, a screen with the SIRET/SIREN input, a call to API Entreprise and wrap everything (identity and company) into the opaque token // Store the client data in a cookie rd.State = query.Get("state") rd.Sirent = query.Get("sirent") - tokens.CreateCookie(rd, "localhost", "clientRequestData", 600*time.Second, w) // TODO : 60 seconds + tokens.CreateCookie(rd, "localhost", "ClientRequestData", 60*time.Second, w) // Redirect to France Connect with the callback as parameter // TODO : France Connect parameters as env variables @@ -150,9 +149,9 @@ func CreateOIDCServer() *http.ServeMux { i := FCIdentity{} json.Unmarshal(rBodyFC, &i) - // Get back the redirect url from the cookie - rd := clientRequestData{} - _, err = tokens.ExtractAndValidateToken(r, "clientRequestData", &rd, false) + // Get the redirect url from the cookie + rd := ClientRequestData{} + _, err = tokens.ExtractAndValidateToken(r, "ClientRequestData", &rd, false) fmt.Printf("Request Data:%v\n", rd) if err != nil { http.Error(w, "could not get the initial client request data from cookie", http.StatusInternalServerError) @@ -168,7 +167,15 @@ func CreateOIDCServer() *http.ServeMux { // Match the fetched company to the user company // TODO : Check if there is a mandate - if e.Nom != i.FamilyName || e.Prenom != i.GivenName { // If not redirect to the matcher to ask for a mandate + // TODO : Iterate on all MandatairesSociaux and clean the big if + if len(e.MandatairesSociaux) < 1 { + http.Error(w, "there is no Mandataires Sociaux for this SIREN/T", http.StatusOK) + return + } + if e.MandatairesSociaux[0].Nom != i.FamilyName || e.MandatairesSociaux[0].Prenom != i.GivenName || e.MandatairesSociaux[0].DateNaissance != i.Birthdate { // If not redirect to the matcher to ask for a mandate + // Add the asker identity to the request data + rd.Id = i + tokens.CreateCookie(rd, "localhost", "ClientRequestData", 60*time.Second, w) http.Redirect(w, req, "/matcher", http.StatusFound) return } diff --git a/pkg/oidc2server/oidcserver_test.go b/pkg/oidcserver/oidcserver_test.go similarity index 100% rename from pkg/oidc2server/oidcserver_test.go rename to pkg/oidcserver/oidcserver_test.go diff --git a/web/components/auth/auth.js b/web/components/auth/auth.js index d75472914f92feac7489ee9ee0c4758afa0cdc36..02e51976a001ab8fb5429b3d2ec90eeb6f01dc25 100644 --- a/web/components/auth/auth.js +++ b/web/components/auth/auth.js @@ -12,7 +12,7 @@ class Auth { <h1>Bienvenue sur GLC Pro</h1> <p>Veuillez saisir le numéro de l'entreprise ou l'établissement pour lequel vous souhaitez faire une demande :</p> <p>Pour obtenir une entreprise ou un établissement de test dont la dirigeante correspond au compte de test FC d'Angela Claire Louise DUBOIS, utiliser le SIREN 000000001.</p> - <p>Pour essayer avec une autre entreprise, prendre par exemple la Métropole de Lyon : 200046977</p> + <p>Pour essayer avec une autre entreprise, prendre par exemple la Fnac : 350127460</p> <input type="text" id="auth-sirent" value="000000001"></input> <button id="auth-do">OK</button> `; diff --git a/web/components/matcher/matcher.js b/web/components/matcher/matcher.js index d44126843ed85b2988a5d54afb9e470579f0d630..2616f705a71690527c9a72503e601ecb842da66b 100644 --- a/web/components/matcher/matcher.js +++ b/web/components/matcher/matcher.js @@ -17,11 +17,29 @@ class Matcher { <p> Voulez vous qu'une demande de mandatement soit envoyée au dirigeant ? </p> + <input type="text" id="matcher-email" value="npernoud@grandlyon.com"></input> <button id="matcher-do">OK</button> <button id="matcher-cancel">Annuler</button> `; - document.getElementById(`matcher-do`).addEventListener("click", () => { - alert("Un mail viens d'être envoyé au dirigeant !"); - }); + document + .getElementById(`matcher-do`) + .addEventListener("click", async () => { + try { + const response = await fetch( + `http://localhost:8080/api/matcher/demand`, + { + method: "POST", + credentials: "include", + body: document.getElementById(`matcher-email`).value, + } + ); + if (response.status !== 200) { + throw new Error(`Could not send mail (status ${response.status})`); + } + alert("Mail envoyé avec succès"); + } catch (e) { + console.error(e); + } + }); } }