Module: Plutonium::ApiClient::Concerns::CreateApiClient

Extended by:
ActiveSupport::Concern
Includes:
Interaction::Concerns::Scoping
Defined in:
lib/plutonium/api_client/concerns/create_api_client.rb

Overview

CreateApiClient provides the core logic for creating API client accounts.

Include this in your CreateInteraction and implement the required methods.

Examples:

Basic usage

class ApiClient::CreateInteraction < Plutonium::Resource::Interaction
  include Plutonium::ApiClient::Concerns::CreateApiClient

  input :role, as: :select, choices: OrganizationApiClient.roles.keys

  def membership_class
    OrganizationApiClient
  end

  def role
    attributes[:role] || "read_only"
  end
end

Defined Under Namespace

Classes: CredentialsPage

Instance Method Summary collapse

Instance Method Details

#executeObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/plutonium/api_client/concerns/create_api_client.rb', line 37

def execute
  password = generate_secure_password

  rodauth_instance.(
    login: ,
    password: password
  )

  # Rodauth internal_request returns nil, so we need to find the account
  api_client = api_client_class.find_by!(login: )

  create_membership!(api_client) if entity_scoped_api_client?

  succeed(api_client).with_render_response(
    credentials_page_class.new(
      login: api_client.,
      password: password,
      parent: scoped_parent
    )
  )
rescue ActiveRecord::RecordNotFound => e
  failed(login: "Failed to create account: #{e.message}")
rescue => e
  failed(login: e.message)
end