Sha256: 3cba8cdb7d4406e507802e42823a2743741d95ebcfbbc0538ea8ffd8e1c40d36

Contents?: true

Size: 1.02 KB

Versions: 23

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Decidim
  module BulletinBoard
    # The base class for all commands.
    class Command
      include Wisper::Publisher

      attr_reader :settings, :graphql

      def configure(settings, graphql)
        @settings = settings
        @graphql = graphql
      end

      def sign_message(message_id, message)
        JWT.encode(complete_message(message_id, message), settings.authority_private_key.keypair, "RS256")
      end

      def complete_message(message_id, message)
        message.merge({
                        iat: Time.now.to_i,
                        message_id: message_id
                      })
      end

      def build_message_id(unique_election_id, type_subtype, voter_id = nil)
        MessageIdentifier.format(unique_election_id, type_subtype, voter_id ? :voter : :authority, voter_id || settings.authority_slug)
      end

      def unique_election_id(election_id)
        MessageIdentifier.unique_election_id(settings.authority_slug, election_id)
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
decidim-bulletin_board-0.23.0 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.22.3 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.22.2 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.22.1 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.22.0 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.21.2 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.21.1 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.21.0 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.20.0 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.19.0 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.18.0 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.17.1 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.17.0 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.16.1 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.16.0 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.15.2 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.15.1 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.14.0 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.13.1 lib/decidim/bulletin_board/command.rb
decidim-bulletin_board-0.13.0 lib/decidim/bulletin_board/command.rb