Sha256: 8031841862fe0b35c9b32215dba0622201944a2bbb8206fa1b04ea80a0f79283

Contents?: true

Size: 1.28 KB

Versions: 60

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 < Rectify::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

60 entries across 60 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.9 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.8 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.7 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.5 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.4 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.3 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.2 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.1 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.0 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.0.rc2 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.26.0.rc1 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.25.2 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.25.1 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.25.0 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.25.0.rc4 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.25.0.rc3 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.25.0.rc2 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.25.0.rc1 app/commands/decidim/admin/update_organization_tos_version.rb
decidim-admin-0.24.3 app/commands/decidim/admin/update_organization_tos_version.rb