Sha256: 0d73e1364a5046417c3535dea4df910b258208e646bb6db4713ae08dbbc91059

Contents?: true

Size: 1.08 KB

Versions: 12

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic to destroy a share token.
    class DestroyShareToken < Decidim::Command
      # Public: Initializes the command.
      #
      # share_token - The share_token to destroy
      # current_user - the user performing the action
      def initialize(share_token, current_user)
        @share_token = share_token
        @current_user = current_user
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the form wasn't valid and we couldn't proceed.
      #
      # Returns nothing.
      def call
        begin
          destroy_share_token
        rescue StandardError
          broadcast(:invalid)
        end
        broadcast(:ok)
      end

      private

      attr_reader :current_user

      def destroy_share_token
        Decidim.traceability.perform_action!(
          "delete",
          @share_token,
          current_user
        ) do
          @share_token.destroy!
        end
      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/destroy_share_token.rb
decidim-admin-0.27.8 app/commands/decidim/admin/destroy_share_token.rb
decidim-admin-0.27.7 app/commands/decidim/admin/destroy_share_token.rb
decidim-admin-0.27.6 app/commands/decidim/admin/destroy_share_token.rb
decidim-admin-0.27.5 app/commands/decidim/admin/destroy_share_token.rb
decidim-admin-0.27.4 app/commands/decidim/admin/destroy_share_token.rb
decidim-admin-0.27.3 app/commands/decidim/admin/destroy_share_token.rb
decidim-admin-0.27.2 app/commands/decidim/admin/destroy_share_token.rb
decidim-admin-0.27.1 app/commands/decidim/admin/destroy_share_token.rb
decidim-admin-0.27.0 app/commands/decidim/admin/destroy_share_token.rb
decidim-admin-0.27.0.rc2 app/commands/decidim/admin/destroy_share_token.rb
decidim-admin-0.27.0.rc1 app/commands/decidim/admin/destroy_share_token.rb