Class: Decidim::System::CreateOAuthApplication
- Inherits:
-
Command
- Object
- Command
- Decidim::System::CreateOAuthApplication
- Defined in:
- app/commands/decidim/system/create_oauth_application.rb
Overview
Creates an OAuthApplication.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(form) ⇒ CreateOAuthApplication
constructor
Initializes the command.
- #oauth_application_attributes ⇒ Object
Constructor Details
#initialize(form) ⇒ CreateOAuthApplication
Initializes the command.
form - The source fo data for this OAuthApplication.
10 11 12 |
# File 'app/commands/decidim/system/create_oauth_application.rb', line 10 def initialize(form) @form = form end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/commands/decidim/system/create_oauth_application.rb', line 14 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 |
#oauth_application_attributes ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/commands/decidim/system/create_oauth_application.rb', line 29 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 |