Sha256: bdaf729bad523e958fb458f3b293ca7bceac5cb9d6a022edf6fe22b76f239e2d

Contents?: true

Size: 1.6 KB

Versions: 13

Compression:

Stored size: 1.6 KB

Contents

require 'api_me'

module TokenAuthenticateMe
  module Concerns
    module Controllers
      module Invitable
        extend ActiveSupport::Concern

        include TokenAuthenticateMe::Concerns::Controllers::TokenAuthenticateable
        include ApiMe

        included do |_base|
          skip_before_action :authenticate, only: [:show]

          def create
            @object = model_klass.new(object_params)
            authorize @object
            @object.save!(object_params)

            TokenAuthenticateMeMailer.invite_email(
              @objec5,
              request.base_url
            ).deliver_later
            render status: 201, json: @object, serializer: serializer_klass
          rescue ActiveRecord::RecordInvalid => e
            handle_errors(e)
          end

          def accept
            @object = model_klass.find(params[:id])

            if @object.accepted.nil?
              ActiveRecord::Base.transaction do
                @object.accept!(current_user)
                @object.update!(accepted: true)
              end

              render status: 204, nothing: true
            else
              render json: { message: 'The request has already been processed' }, status: 422
            end
          end

          def decline
            @object = model_klass.find(params[:id])

            if @object.accepted.nil?
              @object.update!(accepted: false)
              render status: 204, nothing: true
            else
              render json: { message: 'The request has already been processed' }, status: 422
            end
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
token_authenticate_me-0.9.2 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.9.1 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.9.0 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.8.0 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.7.0 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.6.0 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.5.7 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.5.6 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.5.5 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.5.4 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.5.3 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.5.2 lib/token_authenticate_me/concerns/controllers/invitable.rb
token_authenticate_me-0.5.1 lib/token_authenticate_me/concerns/controllers/invitable.rb