From fc6dcc42842269d7e73e3a46900680b6aa851cbc Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Tue, 23 Nov 2021 13:59:20 +0100
Subject: [PATCH] close #70

---
 app/models/communication/website.rb           | 103 ++----------------
 app/models/communication/website/author.rb    |   9 +-
 app/models/communication/website/category.rb  |   9 +-
 app/models/communication/website/home.rb      |  16 +--
 .../communication/website/imported/website.rb |   4 +
 .../website/imported/with_rich_text.rb        |   2 +-
 app/models/communication/website/menu.rb      |   3 +-
 app/models/communication/website/page.rb      |  11 +-
 app/models/communication/website/post.rb      |  11 +-
 .../website/with_batch_publication.rb         |  64 +++++++++++
 .../communication/website/with_categories.rb  |  34 ++++++
 .../communication/website/with_media.rb       |  20 +---
 .../website/with_publishable_objects.rb       |  42 +++++++
 app/models/concerns/with_github.rb            |  16 +--
 app/models/concerns/with_jekyll.rb            |  14 +++
 .../concerns/with_publication_to_websites.rb  |  45 +-------
 app/models/education/program.rb               |   1 +
 app/models/education/school.rb                |  15 ++-
 app/models/education/teacher.rb               |   1 +
 app/models/research/researcher.rb             |   8 +-
 app/models/university/with_users.rb           |   2 +-
 .../admin/education/programs/jekyll.html.erb  |  37 +++----
 .../admin/education/teachers/jekyll.html.erb  |  13 +--
 23 files changed, 230 insertions(+), 250 deletions(-)
 create mode 100644 app/models/communication/website/with_batch_publication.rb
 create mode 100644 app/models/communication/website/with_categories.rb
 create mode 100644 app/models/communication/website/with_publishable_objects.rb
 create mode 100644 app/models/concerns/with_jekyll.rb

diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb
index 32f1ca6ce..8f02e7ae6 100644
--- a/app/models/communication/website.rb
+++ b/app/models/communication/website.rb
@@ -23,6 +23,10 @@
 #  fk_rails_...  (university_id => universities.id)
 #
 class Communication::Website < ApplicationRecord
+  include Communication::Website::WithBatchPublication
+  include Communication::Website::WithCategories
+  include Communication::Website::WithPublishableObjects
+
   belongs_to :university
   belongs_to :about, polymorphic: true, optional: true
   has_one :home,
@@ -52,7 +56,7 @@ class Communication::Website < ApplicationRecord
           dependent: :destroy
 
   after_create :create_home
-  after_save :send_infos_to_github
+  after_save :publish_about_object, if: :saved_change_to_about_id?
   after_save_commit :set_programs_categories!, if: -> (website) { website.about_type == 'Education::School' }
 
   def self.about_types
@@ -64,11 +68,7 @@ class Communication::Website < ApplicationRecord
   end
 
   def domain_url
-    "https://#{domain}"
-  end
-
-  def uploads_url
-    "#{domain_url}/wp-content/uploads"
+    @domain_url ||= "https://#{domain}"
   end
 
   def import!
@@ -93,96 +93,13 @@ class Communication::Website < ApplicationRecord
     all_pages
   end
 
-  def force_publish!
-    publish_authors!
-    publish_categories!
-    publish_pages!
-    publish_posts!
-  end
-  handle_asynchronously :force_publish!, queue: 'default'
-
-  def publish_authors!
-    publish_objects(Communication::Website::Author, authors)
-  end
-
-  def publish_categories!
-    publish_objects(Communication::Website::Category, categories)
-  end
-
-  def publish_pages!
-    publish_objects_with_blobs(Communication::Website::Page, pages)
-  end
-
-  def publish_posts!
-    publish_objects_with_blobs(Communication::Website::Post, posts)
-  end
-
-  def set_programs_categories!
-    programs_root_category = categories.where(is_programs_root: true).first_or_create(
-      name: 'Offre de formation',
-      slug: 'offre-de-formation',
-      is_programs_root: true,
-      university_id: university.id
-    )
-    create_programs_categories_level(programs_root_category, about.programs.root.ordered)
-  end
-
-  def send_infos_to_github
-    if self.about_type == "Education::School"
-      github = Github.with_site self
-      return unless github.valid?
-      github.publish  path: "_data/school.yml",
-                      data: about.to_yml,
-                      commit: "[School infos] Save"
-    end
-  end
-
   protected
 
-  def publish_objects(model, objects)
-    begin
-      had_callback = model.__callbacks[:save].find { |c| c.matches?(:after, :publish_to_github) }
-      model.skip_callback(:save, :after, :publish_to_github) if had_callback
-      github = Github.with_site self
-      return unless github.valid?
-      objects.each do |object|
-        github.add_to_batch path: object.github_path_generated,
-                            previous_path: object.github_path,
-                            data: object.to_jekyll
-        yield(github, object) if block_given?
-      end
-      github.commit_batch "[#{model.name.demodulize}] Batch update from import"
-    ensure
-      model.set_callback(:save, :after, :publish_to_github) if had_callback
-    end
-  end
-
-  def publish_objects_with_blobs(model, objects)
-    publish_objects(model, objects) { |github, object|
-      object.active_storage_blobs.each do |blob|
-        blob.analyze unless blob.analyzed?
-        github.add_to_batch path: object.blob_github_path_generated(blob),
-                            data: object.blob_to_jekyll(blob)
-      end
-    }
-  end
-
-  def create_programs_categories_level(parent_category, programs)
-    programs.each_with_index do |program, index|
-      program_category = categories.where(program_id: program.id).first_or_initialize(
-        name: program.name,
-        slug: program.name.parameterize,
-        university_id: university.id
-      )
-      program_category.parent = parent_category
-      program_category.position = index + 1
-      program_category.save
-      program_children = about.programs.where(parent_id: program.id).ordered
-      create_programs_categories_level(program_category, program_children)
-    end
-  end
-
   def create_home
     build_home(university_id: university_id).save
   end
+
+  def github
+    @github ||= Github.with_site self
+  end
 end
diff --git a/app/models/communication/website/author.rb b/app/models/communication/website/author.rb
index b381e4d1c..6a7dd3950 100644
--- a/app/models/communication/website/author.rb
+++ b/app/models/communication/website/author.rb
@@ -27,6 +27,7 @@
 #
 class Communication::Website::Author < ApplicationRecord
   include WithGithub
+  include WithJekyll
   include WithSlug
 
   has_rich_text :biography
@@ -51,14 +52,6 @@ class Communication::Website::Author < ApplicationRecord
     "_authors/#{slug}.html"
   end
 
-  def to_jekyll
-    ApplicationController.render(
-      template: 'admin/communication/website/authors/jekyll',
-      layout: false,
-      assigns: { author: self }
-    )
-  end
-
   protected
 
   def slug_unavailable?(slug)
diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb
index 9c36c1889..00d25b2b4 100644
--- a/app/models/communication/website/category.rb
+++ b/app/models/communication/website/category.rb
@@ -32,6 +32,7 @@
 #
 class Communication::Website::Category < ApplicationRecord
   include WithGithub
+  include WithJekyll
   include WithSlug
   include WithTree
 
@@ -81,14 +82,6 @@ class Communication::Website::Category < ApplicationRecord
     "_categories/#{slug}.html"
   end
 
-  def to_jekyll
-    ApplicationController.render(
-      template: 'admin/communication/website/categories/jekyll',
-      layout: false,
-      assigns: { category: self }
-    )
-  end
-
   protected
 
   def set_position
diff --git a/app/models/communication/website/home.rb b/app/models/communication/website/home.rb
index bc7ba4b93..61a8a09e1 100644
--- a/app/models/communication/website/home.rb
+++ b/app/models/communication/website/home.rb
@@ -20,8 +20,9 @@
 #  fk_rails_...  (university_id => universities.id)
 #
 class Communication::Website::Home < ApplicationRecord
-  include WithGithub
   include Communication::Website::WithMedia
+  include WithGithub
+  include WithJekyll
 
   belongs_to :university
   belongs_to :website, foreign_key: :communication_website_id
@@ -29,21 +30,12 @@ class Communication::Website::Home < ApplicationRecord
   has_rich_text :text
   has_one_attached_deletable :featured_image
 
-  def github_path_generated
-    '_pages/index.html'
-  end
-
   def to_s
     ''
   end
 
-  def to_jekyll
-    ApplicationController.render(
-      template: 'admin/communication/website/home/jekyll',
-      layout: false,
-      assigns: { home: self }
-    )
+  def github_path_generated
+    '_pages/index.html'
   end
 
-
 end
diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb
index e79457205..fa9da9b80 100644
--- a/app/models/communication/website/imported/website.rb
+++ b/app/models/communication/website/imported/website.rb
@@ -48,6 +48,10 @@ class Communication::Website::Imported::Website < ApplicationRecord
   end
   handle_asynchronously :run!, queue: 'default'
 
+  def uploads_url
+    @uploads_url ||= "#{website.domain_url}/wp-content/uploads"
+  end
+
   protected
 
   def wordpress
diff --git a/app/models/communication/website/imported/with_rich_text.rb b/app/models/communication/website/imported/with_rich_text.rb
index e7fdcf6bf..904e48690 100644
--- a/app/models/communication/website/imported/with_rich_text.rb
+++ b/app/models/communication/website/imported/with_rich_text.rb
@@ -11,7 +11,7 @@ module Communication::Website::Imported::WithRichText
   end
 
   def replace_tags_with_attachments(fragment, tag_name, attribute_name)
-    nodes = fragment.css("#{tag_name}[#{attribute_name}*=\"#{website.website.uploads_url}\"]")
+    nodes = fragment.css("#{tag_name}[#{attribute_name}*=\"#{website.uploads_url}\"]")
     nodes.each do |node|
       begin
         url = node.attr(attribute_name)
diff --git a/app/models/communication/website/menu.rb b/app/models/communication/website/menu.rb
index 4cd25c8f6..92217efe7 100644
--- a/app/models/communication/website/menu.rb
+++ b/app/models/communication/website/menu.rb
@@ -23,6 +23,7 @@
 #
 class Communication::Website::Menu < ApplicationRecord
   include WithGithub
+  # no WithJekyll include as this model has a custom jekyll
 
   belongs_to :university
   belongs_to :website, foreign_key: :communication_website_id
@@ -31,8 +32,6 @@ class Communication::Website::Menu < ApplicationRecord
   validates :title, :identifier, presence: true
   validates :identifier, uniqueness: { scope: :communication_website_id }
 
-  after_touch :publish_to_github
-
   scope :ordered, -> { order(created_at: :asc) }
 
   def to_s
diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb
index cc521d5c6..db511df47 100644
--- a/app/models/communication/website/page.rb
+++ b/app/models/communication/website/page.rb
@@ -37,8 +37,9 @@
 #
 
 class Communication::Website::Page < ApplicationRecord
-  include WithGithub
   include Communication::Website::WithMedia
+  include WithGithub
+  include WithJekyll
   include WithSlug
   include WithTree
 
@@ -75,14 +76,6 @@ class Communication::Website::Page < ApplicationRecord
     "_pages/#{path}/index.html".gsub('///', '/').gsub('//', '/')
   end
 
-  def to_jekyll
-    ApplicationController.render(
-      template: 'admin/communication/website/pages/jekyll',
-      layout: false,
-      assigns: { page: self }
-    )
-  end
-
   def list_of_other_pages
     website.list_of_pages.reject! { |p| p[:id] == id }
   end
diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb
index 532d310b0..645301943 100644
--- a/app/models/communication/website/post.rb
+++ b/app/models/communication/website/post.rb
@@ -30,8 +30,9 @@
 #  fk_rails_...  (university_id => universities.id)
 #
 class Communication::Website::Post < ApplicationRecord
-  include WithGithub
   include Communication::Website::WithMedia
+  include WithGithub
+  include WithJekyll
   include WithSlug
 
   has_rich_text :text
@@ -59,14 +60,6 @@ class Communication::Website::Post < ApplicationRecord
     "_posts/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html"
   end
 
-  def to_jekyll
-    ApplicationController.render(
-      template: 'admin/communication/website/posts/jekyll',
-      layout: false,
-      assigns: { post: self }
-    )
-  end
-
   def to_s
     "#{title}"
   end
diff --git a/app/models/communication/website/with_batch_publication.rb b/app/models/communication/website/with_batch_publication.rb
new file mode 100644
index 000000000..ee02ca4cb
--- /dev/null
+++ b/app/models/communication/website/with_batch_publication.rb
@@ -0,0 +1,64 @@
+module Communication::Website::WithBatchPublication
+  extend ActiveSupport::Concern
+
+  included do
+    def force_publish!
+      publish_authors!
+      publish_categories!
+      publish_pages!
+      publish_posts!
+    end
+    handle_asynchronously :force_publish!, queue: 'default'
+
+    def publish_authors!
+      publish_objects(Communication::Website::Author, authors)
+    end
+
+    def publish_categories!
+      publish_objects(Communication::Website::Category, categories)
+    end
+
+    def publish_pages!
+      publish_objects_with_blobs(Communication::Website::Page, pages)
+    end
+
+    def publish_posts!
+      publish_objects_with_blobs(Communication::Website::Post, posts)
+    end
+
+    protected
+
+    def publish_objects(model, objects)
+      begin
+        had_callback = model.__callbacks[:save].find { |c| c.matches?(:after, :publish_to_github) }
+        model.skip_callback(:save, :after, :publish_to_github) if had_callback
+        return unless github.valid?
+        objects.each do |object|
+          github.add_to_batch path: object.github_path_generated,
+                              previous_path: object.github_path,
+                              data: object.to_jekyll
+          yield(github, object) if block_given?
+        end
+        github.commit_batch "[#{model.name.demodulize}] Batch update from import"
+      ensure
+        model.set_callback(:save, :after, :publish_to_github) if had_callback
+      end
+    end
+
+    def publish_objects_with_blobs(model, objects)
+      publish_objects(model, objects) { |github, object|
+        object.active_storage_blobs.each do |blob|
+          blob.analyze unless blob.analyzed?
+          github_path = "_data/media/#{blob.id[0..1]}/#{blob.id}.yml"
+          data = ApplicationController.render(
+            template: 'active_storage/blobs/jekyll',
+            layout: false,
+            assigns: { blob: blob }
+          )
+          github.add_to_batch(path: github_path, data: data)
+        end
+      }
+    end
+  end
+
+end
diff --git a/app/models/communication/website/with_categories.rb b/app/models/communication/website/with_categories.rb
new file mode 100644
index 000000000..81e541901
--- /dev/null
+++ b/app/models/communication/website/with_categories.rb
@@ -0,0 +1,34 @@
+module Communication::Website::WithCategories
+  extend ActiveSupport::Concern
+
+  included do
+
+    def set_programs_categories!
+      programs_root_category = categories.where(is_programs_root: true).first_or_create(
+        name: 'Offre de formation',
+        slug: 'offre-de-formation',
+        is_programs_root: true,
+        university_id: university.id
+      )
+      create_programs_categories_level(programs_root_category, about.programs.root.ordered)
+    end
+
+    protected
+
+    def create_programs_categories_level(parent_category, programs)
+      programs.each_with_index do |program, index|
+        program_category = categories.where(program_id: program.id).first_or_initialize(
+          name: program.name,
+          slug: program.name.parameterize,
+          university_id: university.id
+        )
+        program_category.parent = parent_category
+        program_category.position = index + 1
+        program_category.save
+        program_children = about.programs.where(parent_id: program.id).ordered
+        create_programs_categories_level(program_category, program_children)
+      end
+    end
+    
+  end
+end
diff --git a/app/models/communication/website/with_media.rb b/app/models/communication/website/with_media.rb
index 5b7203e9a..808ec780a 100644
--- a/app/models/communication/website/with_media.rb
+++ b/app/models/communication/website/with_media.rb
@@ -10,27 +10,9 @@ module Communication::Website::WithMedia
     university.active_storage_blobs.where(id: blob_ids)
   end
 
-  def blob_github_path_generated(blob)
-    "_data/media/#{blob.id[0..1]}/#{blob.id}.yml"
-  end
-
-  def blob_to_jekyll(blob)
-    ApplicationController.render(
-      template: 'active_storage/blobs/jekyll',
-      layout: false,
-      assigns: { blob: blob }
-    )
-  end
-
   protected
 
   def publish_media_to_github
-    active_storage_blobs.each do |blob|
-      blob.analyze unless blob.analyzed?
-      github.publish(path: blob_github_path_generated(blob),
-                    commit: "[Medium] Save ##{blob.id}",
-                    data: blob_to_jekyll(blob))
-    end
+    active_storage_blobs.each { |blob| website.publish_blob(blob) }
   end
-  handle_asynchronously :publish_media_to_github, queue: 'default'
 end
diff --git a/app/models/communication/website/with_publishable_objects.rb b/app/models/communication/website/with_publishable_objects.rb
new file mode 100644
index 000000000..52347ce3a
--- /dev/null
+++ b/app/models/communication/website/with_publishable_objects.rb
@@ -0,0 +1,42 @@
+module Communication::Website::WithPublishableObjects
+  extend ActiveSupport::Concern
+
+  included do
+
+    def publish_about_object
+      # TODO: Handle Research::Journal then use the commented version.
+      # publish_object(about) unless about.nil?
+      publish_object(about) if about.is_a?(Education::School)
+    end
+
+    def publish_object(object)
+      # "object" can be an Education::Program, ...
+      return unless github.valid?
+      object_model_name = object.class.name.demodulize
+      if object.respond_to?(:github_path)
+        github_path = object.github_path
+      else
+        root_folder = "_#{object_model_name.pluralize.underscore}"
+        github_path = "#{root_folder}/#{object.id}.md"
+      end
+      github_commit_message = "[#{object_model_name}] Save #{object.to_s}"
+      github.publish(path: github_path, commit: github_commit_message, data: object.to_jekyll)
+    end
+    handle_asynchronously :publish_object, queue: 'default'
+
+    def publish_blob(blob)
+      return unless github.valid?
+      blob.analyze unless blob.analyzed?
+      github_path = "_data/media/#{blob.id[0..1]}/#{blob.id}.yml"
+      github_commit_message = "[Medium] Save ##{blob.id}"
+      data = ApplicationController.render(
+        template: 'active_storage/blobs/jekyll',
+        layout: false,
+        assigns: { blob: blob }
+      )
+      github.publish(path: github_path, commit: github_commit_message, data: data)
+    end
+    handle_asynchronously :publish_blob, queue: 'default'
+
+  end
+end
diff --git a/app/models/concerns/with_github.rb b/app/models/concerns/with_github.rb
index d3d0f0a36..cc67a3b6d 100644
--- a/app/models/concerns/with_github.rb
+++ b/app/models/concerns/with_github.rb
@@ -3,24 +3,24 @@ module WithGithub
 
   included do
     after_save_commit :publish_to_github
+    after_touch :publish_to_github
   end
 
   def force_publish!
     publish_to_github
   end
 
-  def github_content
-    @content ||= github.read_file_at github_path
-  end
-
   def github_frontmatter
-    @frontmatter ||= FrontMatterParser::Parser.new(:md).call(github_content)
-  rescue
-    FrontMatterParser::Parser.new(:md).call('')
+    @github_frontmatter ||= begin
+      github_content = github.read_file_at(github_path)
+      FrontMatterParser::Parser.new(:md).call(github_content)
+    rescue
+      FrontMatterParser::Parser.new(:md).call('')
+    end
   end
 
   def github_path_generated
-    '' # Needs override
+    raise NotImplementedError
   end
 
   protected
diff --git a/app/models/concerns/with_jekyll.rb b/app/models/concerns/with_jekyll.rb
new file mode 100644
index 000000000..722f28cfc
--- /dev/null
+++ b/app/models/concerns/with_jekyll.rb
@@ -0,0 +1,14 @@
+module WithJekyll
+  extend ActiveSupport::Concern
+
+  included do
+    def to_jekyll
+      ApplicationController.render(
+        template: "admin/#{self.class.name.underscore.pluralize}/jekyll",
+        layout: false,
+        assigns: { self.class.name.demodulize.underscore => self }
+      )
+    end
+  end
+
+end
diff --git a/app/models/concerns/with_publication_to_websites.rb b/app/models/concerns/with_publication_to_websites.rb
index 75d957038..f58d2d652 100644
--- a/app/models/concerns/with_publication_to_websites.rb
+++ b/app/models/concerns/with_publication_to_websites.rb
@@ -2,51 +2,16 @@ module WithPublicationToWebsites
   extend ActiveSupport::Concern
 
   included do
-    after_save_commit :publish_to_github
-  end
-
-  def publish_to_website(website)
-    github = Github.new website.access_token, website.repository
-    return unless github.valid?
-    github.publish  path: "_#{path_root}/#{ id }.md",
-                    data: to_jekyll,
-                    commit: "[#{element_name}] Save #{to_s}"
-  end
-
-  def github_frontmatter
-    @frontmatter ||= FrontMatterParser::Parser.new(:md).call(github_content)
-  rescue
-    FrontMatterParser::Parser.new(:md).call('')
+    after_save_commit :publish_to_every_websites
   end
 
   protected
 
-  def to_jekyll
-    ApplicationController.render(
-      template: "admin/#{path_relative}/jekyll",
-      layout: false,
-      assigns: { object: self }
-    )
-  end
-
-  def publish_to_github
-    websites.each { |website| publish_to_website(website) }
-  end
-
-  # return "Program"
-  def element_name
-    self.class.name.demodulize
-  end
-
-  # return "programs"
-  def path_root
-    element_name.pluralize.downcase
-  end
-
-  # return "education/programs"
-  def path_relative
-    self.class.name.underscore.pluralize
+  def publish_to_every_websites
+    websites.each { |website| website.publish_object(self) }
   end
 
+  # You can define a `github_path` method to re-define where to save the object markdown.
+  # Check Communication::Website#publish_object for the default value.
 
 end
diff --git a/app/models/education/program.rb b/app/models/education/program.rb
index 102cf96b2..9aeed4c77 100644
--- a/app/models/education/program.rb
+++ b/app/models/education/program.rb
@@ -25,6 +25,7 @@
 #  fk_rails_...  (university_id => universities.id)
 #
 class Education::Program < ApplicationRecord
+  include WithJekyll
   include WithPublicationToWebsites
   include WithTree
 
diff --git a/app/models/education/school.rb b/app/models/education/school.rb
index 394b8f47f..2496faa72 100644
--- a/app/models/education/school.rb
+++ b/app/models/education/school.rb
@@ -24,6 +24,8 @@
 #  fk_rails_...  (university_id => universities.id)
 #
 class Education::School < ApplicationRecord
+  include WithPublicationToWebsites
+
   belongs_to :university
   has_many :websites, class_name: 'Communication::Website', as: :about
   has_and_belongs_to_many :programs,
@@ -36,13 +38,15 @@ class Education::School < ApplicationRecord
 
   scope :ordered, -> { order(:name) }
 
-  after_save_commit :publish_to_github
-
   def to_s
     "#{name}"
   end
 
-  def to_yml
+  def github_path
+    "_data/school.yml"
+  end
+
+  def to_jekyll
     {
       name: name,
       address: address,
@@ -53,9 +57,4 @@ class Education::School < ApplicationRecord
     }.deep_stringify_keys.to_yaml.lines[1..-1].join
   end
 
-  private
-
-  def publish_to_github
-    websites.each(&:send_infos_to_github)
-  end
 end
diff --git a/app/models/education/teacher.rb b/app/models/education/teacher.rb
index 970d4a478..58510a60d 100644
--- a/app/models/education/teacher.rb
+++ b/app/models/education/teacher.rb
@@ -22,6 +22,7 @@
 #  fk_rails_...  (user_id => users.id)
 #
 class Education::Teacher < ApplicationRecord
+  include WithJekyll
   include WithPublicationToWebsites
   include WithSlug
 
diff --git a/app/models/research/researcher.rb b/app/models/research/researcher.rb
index dacee4ec3..a5ae0ab54 100644
--- a/app/models/research/researcher.rb
+++ b/app/models/research/researcher.rb
@@ -38,11 +38,7 @@ class Research::Researcher < ApplicationRecord
     "#{ first_name } #{ last_name }"
   end
 
-  protected
-
-  # overwrite from WithPublicationToWebsites
-  def path_root
-    'authors'
+  def github_path
+    "_authors/#{self.id}.md"
   end
-
 end
diff --git a/app/models/university/with_users.rb b/app/models/university/with_users.rb
index d66e08afe..ccc0ea64e 100644
--- a/app/models/university/with_users.rb
+++ b/app/models/university/with_users.rb
@@ -11,7 +11,7 @@ module University::WithUsers
     def synchronize_server_admin_users
       User.synchronize_server_admin_users(id)
     end
-    handle_asynchronously :synchronize_server_admin_users
+    handle_asynchronously :synchronize_server_admin_users, queue: 'default'
 
   end
 end
diff --git a/app/views/admin/education/programs/jekyll.html.erb b/app/views/admin/education/programs/jekyll.html.erb
index e833906bf..ef39a9092 100644
--- a/app/views/admin/education/programs/jekyll.html.erb
+++ b/app/views/admin/education/programs/jekyll.html.erb
@@ -1,32 +1,31 @@
 ---
-title: "<%= @object.name %>"
-identifier: "<%= @object.id %>"
-parent: "<%= @object.parent_id %>"
-continuing: <%= @object.continuing %>
-level: <%= @object.level %>
-ects: <%= @object.ects %>
-position: <%= @object.position %>
+title: "<%= @program.name %>"
+identifier: "<%= @program.id %>"
+parent: "<%= @program.parent_id %>"
+continuing: <%= @program.continuing %>
+level: <%= @program.level %>
+ects: <%= @program.ects %>
+position: <%= @program.position %>
 accessibility: >
-  <%= prepare_for_github @object.accessibility, @object.university %>
+  <%= prepare_for_github @program.accessibility, @program.university %>
 contacts: >
-  <%= prepare_for_github @object.contacts, @object.university %>
+  <%= prepare_for_github @program.contacts, @program.university %>
 duration: >
-  <%= prepare_for_github @object.duration, @object.university %>
+  <%= prepare_for_github @program.duration, @program.university %>
 evaluation: >
-  <%= prepare_for_github @object.evaluation, @object.university %>
+  <%= prepare_for_github @program.evaluation, @program.university %>
 objectives: >
-  <%= prepare_for_github @object.objectives, @object.university %>
+  <%= prepare_for_github @program.objectives, @program.university %>
 opportunities: >
-  <%= prepare_for_github @object.opportunities, @object.university %>
+  <%= prepare_for_github @program.opportunities, @program.university %>
 other: >
-  <%= prepare_for_github @object.other, @object.university %>
+  <%= prepare_for_github @program.other, @program.university %>
 pedagogy: >
-  <%= prepare_for_github @object.pedagogy, @object.university %>
+  <%= prepare_for_github @program.pedagogy, @program.university %>
 prerequisites: >
-  <%= prepare_for_github @object.prerequisites, @object.university %>
+  <%= prepare_for_github @program.prerequisites, @program.university %>
 pricing: >
-  <%= prepare_for_github @object.pricing, @object.university %>
+  <%= prepare_for_github @program.pricing, @program.university %>
 registration: >
-  <%= prepare_for_github @object.registration, @object.university %>
+  <%= prepare_for_github @program.registration, @program.university %>
 ---
-<%= @object.github_frontmatter.content.html_safe %>
diff --git a/app/views/admin/education/teachers/jekyll.html.erb b/app/views/admin/education/teachers/jekyll.html.erb
index f26e8d526..788dee4b2 100644
--- a/app/views/admin/education/teachers/jekyll.html.erb
+++ b/app/views/admin/education/teachers/jekyll.html.erb
@@ -1,10 +1,9 @@
 ---
-title: "<%= @object.to_s %>"
-identifier: "<%= @object.id %>"
-first_name: "<%= @object.first_name %>"
-last_name: "<%= @object.last_name %>"
-slug: "<%= @object.slug %>"
+title: "<%= @teacher.to_s %>"
+identifier: "<%= @teacher.id %>"
+first_name: "<%= @teacher.first_name %>"
+last_name: "<%= @teacher.last_name %>"
+slug: "<%= @teacher.slug %>"
 biography: >
-  <%= prepare_for_github @object.biography, @object.university %>
+  <%= prepare_for_github @teacher.biography, @teacher.university %>
 ---
-<%= @object.github_frontmatter.content.html_safe %>
-- 
GitLab