From f2654ab206f422cbc655785a92351036ca4affb9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Fri, 17 Dec 2021 13:05:51 +0100
Subject: [PATCH] add published to programs

---
 app/controllers/admin/education/programs_controller.rb       | 2 +-
 app/models/education/program.rb                              | 2 ++
 app/views/admin/education/programs/_form.html.erb            | 1 +
 config/locales/communication/en.yml                          | 4 ++--
 config/locales/education/en.yml                              | 1 +
 config/locales/education/fr.yml                              | 1 +
 .../20211217115802_add_published_to_education_programs.rb    | 5 +++++
 db/schema.rb                                                 | 3 ++-
 8 files changed, 15 insertions(+), 4 deletions(-)
 create mode 100644 db/migrate/20211217115802_add_published_to_education_programs.rb

diff --git a/app/controllers/admin/education/programs_controller.rb b/app/controllers/admin/education/programs_controller.rb
index 87a98de74..ef52df18a 100644
--- a/app/controllers/admin/education/programs_controller.rb
+++ b/app/controllers/admin/education/programs_controller.rb
@@ -79,7 +79,7 @@ class Admin::Education::ProgramsController < Admin::Education::ApplicationContro
 
   def program_params
     params.require(:education_program).permit(
-      :name, :slug, :level, :capacity, :ects, :continuing, :description,
+      :name, :slug, :level, :capacity, :ects, :continuing, :description, :published,
       :prerequisites, :objectives, :duration, :registration, :pedagogy,
       :evaluation, :accessibility, :pricing, :contacts, :opportunities, :other,
       :parent_id, school_ids: [], teacher_ids: []
diff --git a/app/models/education/program.rb b/app/models/education/program.rb
index 9aaf187e9..1a5045501 100644
--- a/app/models/education/program.rb
+++ b/app/models/education/program.rb
@@ -11,6 +11,7 @@
 #  name          :string
 #  path          :string
 #  position      :integer          default(0)
+#  published     :boolean          default(FALSE)
 #  slug          :string
 #  created_at    :datetime         not null
 #  updated_at    :datetime         not null
@@ -81,6 +82,7 @@ class Education::Program < ApplicationRecord
   after_save :update_children_paths, if: :saved_change_to_path?
   after_save_commit :set_websites_categories, unless: :skip_websites_categories_callback
 
+  scope :published, -> { where(published: true) }
   scope :ordered, -> { order(:position) }
 
   def to_s
diff --git a/app/views/admin/education/programs/_form.html.erb b/app/views/admin/education/programs/_form.html.erb
index 710b7caab..cad98a94c 100644
--- a/app/views/admin/education/programs/_form.html.erb
+++ b/app/views/admin/education/programs/_form.html.erb
@@ -13,6 +13,7 @@
                         class: 'js-slug-input',
                         data: { source: '#education_program_name' }
                       } %>
+          <%= f.input :published %>
           <%= f.input :level, include_blank: false, label_method: -> (p) { I18n.t(p[1], scope: 'enums.education/program.level') } %>
           <%= f.input :capacity %>
           <%= f.input :ects %>
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index efc691bcf..0fc87e398 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -83,7 +83,7 @@ en:
         description: Description (SEO)
         featured_image: Featured image
         parent: Parent page
-        published: Published ?
+        published: Published?
         slug: Slug
         text: Text
         title: Title
@@ -95,7 +95,7 @@ en:
         description: Description (SEO)
         featured_image: Featured image
         pinned: Pinned?
-        published: Published ?
+        published: Published?
         published_at: Publication date
         slug: Slug
         text: Text
diff --git a/config/locales/education/en.yml b/config/locales/education/en.yml
index 1d8bf68c3..eb3f1b124 100644
--- a/config/locales/education/en.yml
+++ b/config/locales/education/en.yml
@@ -28,6 +28,7 @@ en:
         pedagogy: Méthodes mobilisées
         prerequisites: Prérequis
         pricing: Tarifs
+        published: Published?
         registration: Modalités et délais d’accès
         schools: Schools with this formation
         teachers: Teachers
diff --git a/config/locales/education/fr.yml b/config/locales/education/fr.yml
index 4e29fb328..cda0dc8fe 100644
--- a/config/locales/education/fr.yml
+++ b/config/locales/education/fr.yml
@@ -28,6 +28,7 @@ fr:
         pedagogy: Méthodes mobilisées
         prerequisites: Prérequis
         pricing: Tarifs
+        published: Publiée ?
         registration: Modalités et délais d’accès
         schools: Écoles proposant cette formation
         teachers: Enseignants·es
diff --git a/db/migrate/20211217115802_add_published_to_education_programs.rb b/db/migrate/20211217115802_add_published_to_education_programs.rb
new file mode 100644
index 000000000..740f1b29b
--- /dev/null
+++ b/db/migrate/20211217115802_add_published_to_education_programs.rb
@@ -0,0 +1,5 @@
+class AddPublishedToEducationPrograms < ActiveRecord::Migration[6.1]
+  def change
+    add_column :education_programs, :published, :boolean, default: false
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 69304184b..dd5a22ca6 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2021_12_17_115125) do
+ActiveRecord::Schema.define(version: 2021_12_17_115802) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -374,6 +374,7 @@ ActiveRecord::Schema.define(version: 2021_12_17_115125) do
     t.string "slug"
     t.string "path"
     t.text "description"
+    t.boolean "published", default: false
     t.index ["parent_id"], name: "index_education_programs_on_parent_id"
     t.index ["university_id"], name: "index_education_programs_on_university_id"
   end
-- 
GitLab