Sha256: 360c4411f2e2cd504f6635f3077307bb2ce69a968e58f984b303b8f83c53412e

Contents?: true

Size: 769 Bytes

Versions: 7

Compression:

Stored size: 769 Bytes

Contents

# frozen_string_literal: true

module PagesCore
  class CreateUserService
    attr_reader :attributes, :invite

    def initialize(attributes, invite: nil)
      @attributes = attributes
      @invite = invite
    end

    class << self
      def call(attrs, invite: nil)
        new(attrs, invite:).call
      end
    end

    def call
      User.transaction do
        user = User.create(attributes.merge(invite_attributes))
        if user.valid?
          PagesCore::PubSub.publish(:create_user, user:, invite:)
          invite&.destroy
        end
        user
      end
    end

    private

    def invite_attributes
      return {} unless invite

      { role_names: invite.role_names,
        creator: invite.user,
        activated: true }
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pages_core-3.15.5 app/services/pages_core/create_user_service.rb
pages_core-3.15.4 app/services/pages_core/create_user_service.rb
pages_core-3.15.3 app/services/pages_core/create_user_service.rb
pages_core-3.15.2 app/services/pages_core/create_user_service.rb
pages_core-3.15.1 app/services/pages_core/create_user_service.rb
pages_core-3.14.0 app/services/pages_core/create_user_service.rb
pages_core-3.13.0 app/services/pages_core/create_user_service.rb