Add an API for adding AndroidDeviceRegistrationTokens for a user

This commit is contained in:
redfast00 2019-05-08 22:28:09 +02:00
parent cf5c02626d
commit 2beefac8a5
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C
3 changed files with 11 additions and 3 deletions

View file

@ -1,8 +1,8 @@
class UsersController < ApplicationController class UsersController < ApplicationController
skip_before_action :verify_authenticity_token, only: :create skip_before_action :verify_authenticity_token, only: :create
before_action :authenticate_user!, except: :show before_action :authenticate_user!, except: [:show, :add_registration_token]
before_action :authenticate_user_or_client!, only: :show before_action :authenticate_user_or_client!, only: [:show, :add_registration_token]
load_and_authorize_resource find_by: :name load_and_authorize_resource find_by: :name
@ -23,4 +23,11 @@ class UsersController < ApplicationController
@user.generate_key! @user.generate_key!
redirect_to @user redirect_to @user
end end
def add_registration_token
token = JSON.parse(request.raw_post)["token"]
respond_to do |format|
format.json { render json: AndroidDeviceRegistrationToken.create(user: @user, token: token) }
end
end
end end

View file

@ -7,7 +7,7 @@ class UserAbility
can :manage, :all if user.penning? can :manage, :all if user.penning?
can :create, Request, creditor_id: user.id can :create, Request, creditor_id: user.id
can [:confirm, :decline], Request, debtor_id: user.id can [:confirm, :decline], Request, debtor_id: user.id
can [:read, :reset_key], User, id: user.id can [:read, :reset_key, :add_registration_token], User, id: user.id
can :manage, Notification, user_id: user.id can :manage, Notification, user_id: user.id
can :create, Transaction do |t| can :create, Transaction do |t|
t.debtor == user && t.amount <= Rails.application.config.maximum_amount t.debtor == user && t.amount <= Rails.application.config.maximum_amount

View file

@ -24,6 +24,7 @@ Rails.application.routes.draw do
end end
resources :transactions, only: [:index], shallow: true resources :transactions, only: [:index], shallow: true
post :reset_key, on: :member post :reset_key, on: :member
post :add_registration_token, on: :member
end end
get 'datatables/:id' => 'datatables#transactions_for_user', as: "user_transactions_datatable" get 'datatables/:id' => 'datatables#transactions_for_user', as: "user_transactions_datatable"