diff --git a/app/controllers/admin/communication/website/categories_controller.rb b/app/controllers/admin/communication/website/categories_controller.rb index bb07fd3bd97cb1121e7ccc9d890bc7008dd345cc..8e0892e10a63fceb612deaa57e662c3856498882 100644 --- a/app/controllers/admin/communication/website/categories_controller.rb +++ b/app/controllers/admin/communication/website/categories_controller.rb @@ -22,8 +22,7 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication skip_github_publication: true ) end - github = Github.with_website @website - github.send_batch_to_website(categories, message: '[Category] Reorder categories.') + categories.first.sync_with_git end def children @@ -54,7 +53,7 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication def create @category.website = @website - if @category.save + if @category.save_and_sync redirect_to admin_communication_website_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s) else breadcrumb @@ -63,7 +62,7 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication end def update - if @category.update(category_params) + if @category.update_and_sync(category_params) redirect_to admin_communication_website_category_path(@category), notice: t('admin.successfully_updated_html', model: @category.to_s) else breadcrumb @@ -73,7 +72,7 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication end def destroy - @category.destroy + @category.destroy_and_sync redirect_to admin_communication_website_categories_url, notice: t('admin.successfully_destroyed_html', model: @category.to_s) end diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index b0a3bae4e8c9a0a6652b52b895eb2825be4f29c5..8f294a62a6272d1ae20b016a01b5ecd379a5b9c4 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -37,25 +37,25 @@ class Communication::Website::Category < ApplicationRecord include WithSlug # We override slug_unavailable? method include WithTree - has_one :imported_category, - class_name: 'Communication::Website::Imported::Category', - dependent: :destroy - belongs_to :university - belongs_to :website, - foreign_key: :communication_website_id - belongs_to :parent, - class_name: 'Communication::Website::Category', - optional: true - belongs_to :program, - class_name: 'Education::Program', - optional: true - has_one :imported_category, - class_name: 'Communication::Website::Imported::Category', - dependent: :destroy - has_many :children, - class_name: 'Communication::Website::Category', - foreign_key: :parent_id, - dependent: :destroy + has_one :imported_category, + class_name: 'Communication::Website::Imported::Category', + dependent: :destroy + belongs_to :university + belongs_to :website, + foreign_key: :communication_website_id + belongs_to :parent, + class_name: 'Communication::Website::Category', + optional: true + belongs_to :program, + class_name: 'Education::Program', + optional: true + has_one :imported_category, + class_name: 'Communication::Website::Imported::Category', + dependent: :destroy + has_many :children, + class_name: 'Communication::Website::Category', + foreign_key: :parent_id, + dependent: :destroy has_and_belongs_to_many :posts, class_name: 'Communication::Website::Post', join_table: 'communication_website_categories_posts', @@ -83,6 +83,10 @@ class Communication::Website::Category < ApplicationRecord "content/categories/#{path}/_index.html".gsub(/\/+/, '/') end + def git_dependencies(identifier) + posts + end + def update_children_paths children.each do |child| child.update_column :path, child.generated_path