Class: Decidim::System::UpdateOAuthApplication

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/system/update_oauth_application.rb

Overview

Updates the OAuth application given form data.

Instance Method Summary collapse

Constructor Details

#initialize(application, form, user) ⇒ UpdateOAuthApplication

Initializes the command.

application - The OAuthApplication to update. form - The form object containing the data to update. user - The user that updates the application.



12
13
14
15
16
# File 'app/commands/decidim/system/update_oauth_application.rb', line 12

def initialize(application, form, user)
  @application = application
  @form = form
  @user = user
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/commands/decidim/system/update_oauth_application.rb', line 18

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

  @application = Decidim.traceability.update!(
    @application,
    @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_attributesObject



33
34
35
36
37
38
39
40
41
42
43
# File 'app/commands/decidim/system/update_oauth_application.rb', line 33

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