Sha256: 3963a94b6bd308ca16ea79e4b99ab580ddc475a7cff0b95921ddaebc51067088

Contents?: true

Size: 1.35 KB

Versions: 19

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Decidim
  module System
    # Creates an OAuthApplication.
    class CreateOAuthApplication < Rectify::Command
      # Initializes the command.
      #
      # form - The source fo data for this OAuthApplication.
      def initialize(form)
        @form = form
      end

      def call
        return broadcast(:invalid) unless @form.valid?

        @application = Decidim.traceability.create!(
          OAuthApplication,
          @form.current_user,
          **oauth_application_attributes
        )

        broadcast(:ok, @application)
      rescue ActiveRecord::RecordInvalid
        @form.errors.add(:organization_logo, @application.errors[:organization_logo]) if @application.errors.include? :organization_logo
        broadcast(:invalid)
      end

      def oauth_application_attributes
        {
          organization: @form.current_organization,
          name: @form.name,
          decidim_organization_id: @form.decidim_organization_id,
          organization_name: @form.organization_name,
          organization_url: @form.organization_url,
          organization_logo: @form.organization_logo,
          redirect_uri: @form.redirect_uri,
          scopes: "public"
        }.tap do |attrs|
          attrs[:organization_logo] = @form.organization_logo if @form.organization_logo.present?
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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