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.16.0 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.15.2 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.15.1 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.15.0 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.14.4 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.14.3 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.14.2 app/controllers/decidim/admin/organization_homepage_controller.rb
decidim-admin-0.14.1 app/controllers/decidim/admin/organization_homepage_controller.rb