WIP create invites via API

This commit is contained in:
Basti 2019-03-09 09:18:53 +07:00
parent 582b1423c8
commit 48822cc0b1
No known key found for this signature in database
GPG Key ID: BE4634D632D39B67
3 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,18 @@
# frozen_string_literal: true
class Api::V1::InvitesController < Api::BaseController
before_action -> { doorkeeper_authorize! :write, :'write:accounts' }
before_action :require_user!
respond_to :json
def create
@invite = Invite.new(max_uses: 1)
@invite.user = current_user
@invite.save!
render json: @invite, serializer: REST::InviteSerializer
end
end

View File

@ -0,0 +1,21 @@
# frozen_string_literal: true
class REST::InviteSerializer < ActiveModel::Serializer
attributes :id, :code, :expires_at, :max_uses
def id
object.id.to_s
end
def code
object.code
end
def expires_at
object.expires_at
end
def max_uses
object.max_uses
end
end

View File

@ -297,6 +297,7 @@ Rails.application.routes.draw do
resources :reports, only: [:create]
resources :filters, only: [:index, :create, :show, :update, :destroy]
resources :endorsements, only: [:index]
resources :invites, only: [:create]
namespace :apps do
get :verify_credentials, to: 'credentials#show'