mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-06 09:51:24 +00:00
Extract params hash for api/v1/push/subscriptions#create
(#35475)
This commit is contained in:
parent
469304359a
commit
e54e96d61f
|
@ -16,16 +16,7 @@ class Api::V1::Push::SubscriptionsController < Api::BaseController
|
||||||
def create
|
def create
|
||||||
with_redis_lock("push_subscription:#{current_user.id}") do
|
with_redis_lock("push_subscription:#{current_user.id}") do
|
||||||
destroy_web_push_subscriptions!
|
destroy_web_push_subscriptions!
|
||||||
|
@push_subscription = Web::PushSubscription.create!(web_push_subscription_params)
|
||||||
@push_subscription = Web::PushSubscription.create!(
|
|
||||||
endpoint: subscription_params[:endpoint],
|
|
||||||
key_p256dh: subscription_params[:keys][:p256dh],
|
|
||||||
key_auth: subscription_params[:keys][:auth],
|
|
||||||
standard: subscription_params[:standard] || false,
|
|
||||||
data: data_params,
|
|
||||||
user_id: current_user.id,
|
|
||||||
access_token_id: doorkeeper_token.id
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||||
|
@ -55,6 +46,18 @@ class Api::V1::Push::SubscriptionsController < Api::BaseController
|
||||||
not_found if @push_subscription.nil?
|
not_found if @push_subscription.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def web_push_subscription_params
|
||||||
|
{
|
||||||
|
access_token_id: doorkeeper_token.id,
|
||||||
|
data: data_params,
|
||||||
|
endpoint: subscription_params[:endpoint],
|
||||||
|
key_auth: subscription_params[:keys][:auth],
|
||||||
|
key_p256dh: subscription_params[:keys][:p256dh],
|
||||||
|
standard: subscription_params[:standard] || false,
|
||||||
|
user_id: current_user.id,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def subscription_params
|
def subscription_params
|
||||||
params.expect(subscription: [:endpoint, :standard, keys: [:auth, :p256dh]])
|
params.expect(subscription: [:endpoint, :standard, keys: [:auth, :p256dh]])
|
||||||
end
|
end
|
||||||
|
|
|
@ -166,17 +166,30 @@ RSpec.describe 'API V1 Push Subscriptions' do
|
||||||
describe 'GET /api/v1/push/subscription' do
|
describe 'GET /api/v1/push/subscription' do
|
||||||
subject { get '/api/v1/push/subscription', headers: headers }
|
subject { get '/api/v1/push/subscription', headers: headers }
|
||||||
|
|
||||||
before { create_subscription_with_token }
|
context 'with a subscription' do
|
||||||
|
before { create_subscription_with_token }
|
||||||
|
|
||||||
it 'shows subscription details' do
|
it 'shows subscription details' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(response)
|
expect(response)
|
||||||
.to have_http_status(200)
|
.to have_http_status(200)
|
||||||
expect(response.content_type)
|
expect(response.content_type)
|
||||||
.to start_with('application/json')
|
.to start_with('application/json')
|
||||||
expect(response.parsed_body)
|
expect(response.parsed_body)
|
||||||
.to include(endpoint: endpoint)
|
.to include(endpoint: endpoint)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without a subscription' do
|
||||||
|
it 'returns not found' do
|
||||||
|
subject
|
||||||
|
|
||||||
|
expect(response)
|
||||||
|
.to have_http_status(404)
|
||||||
|
expect(response.content_type)
|
||||||
|
.to start_with('application/json')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user