Sha256: 6aca82d63a6e1ff6f60e81b53da4b2b4d9976807e777d65cd1a6318d2bc15700

Contents?: true

Size: 1.39 KB

Versions: 28

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # Controller that allows managing the organization homepage
    class OrganizationHomepageController < Decidim::Admin::ApplicationController
      layout "decidim/admin/settings"

      helper_method :active_blocks, :inactive_blocks

      def edit
        enforce_permission_to :update, :organization, organization: current_organization
      end

      def update
        enforce_permission_to :update, :organization, organization: current_organization
        ReorderContentBlocks.call(current_organization, :homepage, params[:manifests]) do
          on(:ok) do
            head :ok
          end
          on(:invalid) do
            head :bad_request
          end
        end
      end

      private

      def content_blocks
        @content_blocks ||= Decidim::ContentBlock.for_scope(:homepage, organization: current_organization)
      end

      def active_blocks
        @active_blocks ||= content_blocks.published
      end

      def inactive_blocks
        @inactive_blocks ||= content_blocks.unpublished + unused_manifests
      end

      def used_manifests
        @used_manifests ||= content_blocks.map(&:manifest_name)
      end

      def unused_manifests
        @unused_manifests ||= Decidim.content_blocks.for(:homepage).reject do |manifest|
          used_manifests.include?(manifest.name.to_s)
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
decidim-admin-0.23.6 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.23.5 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.23.4 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.23.3 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.23.2 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.23.1 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.23.1.rc1 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.23.0 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.22.0 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.21.0 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.20.1 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.20.0 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.19.1 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.18.1 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.19.0 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.17.2 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.18.0 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.17.1 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.16.1 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.17.0 app/controllers/decidim/admin/organization_homepage_controller.rb