diff --git a/.env b/.env new file mode 100644 index 0000000000000000000000000000000000000000..c2b273f9031a02acd5cacf1d1fcc57c302f27748 --- /dev/null +++ b/.env @@ -0,0 +1,12 @@ +HOSTNAME=elections.127.0.0.1.nip.io +ADMIN_GROUP=ADMINS +CLIENT_GROUP=VISUALIZER + +# Needed to user OAuth2 authentication : +REDIRECT_URL=https://${HOSTNAME}/OAuth2Callback +CLIENT_ID=__GET_ONE_FROM_YOUR_IDP__ +CLIENT_SECRET=__GET_ONE_FROM_YOUR_IDP__ +AUTH_URL=https://myidp.fr/IdPOAuth2/authorize/oidc-rec +TOKEN_URL=https://myidp.fr/IdPOAuth2/token/oidc-rec +USERINFO_URL=https://myidp.fr/IdPOAuth2/userinfo/oidc-rec +LOGOUT_URL=https://myidp.fr/auth/logout.jsp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..558d9e3aa4ade40944a0582fdd23a979c121ab2b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__debug_bin +data \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..d20084ff530176daf8c3e1cb83a3413fcd03bac0 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,52 @@ +# +# Ce fichier doit être adapté en fonction du projet en renseignant les variables SONAR_PROJECT_KEY et SONAR_TOKEN dans la configuration graphique du projet (https://forge.grandlyon.com/<CHEMIN_DE_VOTRE_PROJET>/settings/ci_cd) +# La variable SONAR_PROJET_KEY peut être trouvée sur https://sonarqube.forge.grandlyon.com/dashboard en ouvrant le projet et en copiant collant le champ en bas à droite (Project Key) +# +# La variable SONAR_TOKEN doit être générée par le responsable du projet depuis son interface sonar : https://sonarqube.forge.grandlyon.com/account/security/ +# + +image: docker:git + +services: + - docker:dind + +variables: + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "" + SONAR_URL: https://sonarqube.forge.grandlyon.com + +stages: + - sonar-analysis + - build + +sonarqube: + stage: sonar-analysis + image: skilldlabs/sonar-scanner:3.4.0 + script: + - > + sonar-scanner + -Dsonar.projectName=${CI_PROJECT_NAME} + -Dsonar.projectVersion=1.0 + -Dsonar.sourceEncoding=UTF-8 + -Dsonar.projectBaseDir=. + -Dsonar.host.url=${SONAR_URL} + -Dsonar.projectKey=${SONAR_PROJECT_KEY} + -Dsonar.login=${SONAR_TOKEN} + +build-master: + stage: build + script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + - DOCKER_BUILDKIT=1 docker build --pull -t "$CI_REGISTRY_IMAGE" . + - docker push "$CI_REGISTRY_IMAGE" + only: + - master + +build: + stage: build + script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + - DOCKER_BUILDKIT=1 docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" . + - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" + except: + - master diff --git a/internal/models/models.go b/internal/models/models.go index 419de5571257c8ffb5dffdbd9299416910ce881b..24bcd4fc1086862358bacab665703f928c9e4e23 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -39,7 +39,7 @@ type election struct { name string ballotType string areas []area - Rounds []Round + rounds []round } type area struct { @@ -102,7 +102,6 @@ type parameter struct { CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` DeletedAt *time.Time `json:"-"` - roundID round countBalnkAndNull bool showOnlyCompleted bool showMap bool @@ -113,7 +112,7 @@ type round struct { CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` DeletedAt *time.Time `json:"-"` - ElectionID uint + electionID uint parameter parameter name string date time.Time @@ -127,11 +126,11 @@ type deskRound struct { CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` DeletedAt *time.Time `json:"-"` - RoundID uint + roundID uint completed bool dateCompletion time.Time validated bool - votes []Vote + votes []vote } type candidateList struct { ID uint `gorm:"primary_key"` @@ -143,7 +142,7 @@ type candidateList struct { area area `gorm:"foreignkey:AreaRefer"` name string candidates []candidate - votes []Vote + votes []vote } type candidate struct { @@ -180,10 +179,19 @@ func NewDataHandler() *DataHandler { } db.LogMode(true) - // Add FK with SQLite doesn't work - // db.Model(&Operation{}).AddForeignKey("creditor", "bank_account(id)", "Set Null", "Set Null") - // Migrate the schema + db.AutoMigrate(&capturer{}) + db.AutoMigrate(&election{}) + db.AutoMigrate(&area{}) + db.AutoMigrate(§ion{}) + db.AutoMigrate(&desk{}) + db.AutoMigrate(&round{}) + db.AutoMigrate(&deskRound{}) + db.AutoMigrate(&party{}) + db.AutoMigrate(&candidateList{}) + db.AutoMigrate(&candidate{}) + db.AutoMigrate(&vote{}) + db.AutoMigrate(¶meter{}) return &DataHandler{db: db} }