Sha256: 78ddc447b7cddd6076ea04add7e3574d39ca61709e5b1b56d1b6dc9aa9d21ae4

Contents?: true

Size: 1.28 KB

Versions: 12

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with the business logic for updating the current
    # organization tos_version attribute.
    class UpdateOrganizationTosVersion < Decidim::Command
      # Public: Initializes the command.
      #
      # organization - The Organization that will be updated.
      # page - A static_page instance (slug = "terms-and-conditions").
      # form - A form object with the params.
      def initialize(organization, page, form)
        @organization = organization
        @page = page
        @form = form
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the form wasn't valid or not the TOS page.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) if @form.nil?
        return broadcast(:invalid) if @page.nil?
        return broadcast(:invalid) unless @page.slug == "terms-and-conditions"

        update_organization_tos_version
        broadcast(:ok)
      end

      private

      attr_reader :form

      def update_organization_tos_version
        Decidim.traceability.update!(
          @organization,
          @form.current_user,
          tos_version: @page.updated_at
        )
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-admin-0.27.9 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.8 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.7 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.6 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.5 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.4 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.3 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.2 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.1 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.0 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.0.rc2 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.27.0.rc1 app/commands/decidim/admin/update_organization_tos_version.rb