mirror of
https://github.com/mastodon/mastodon.git
synced 2026-03-28 21:35:32 -05:00
Some checks failed
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Bundler Audit / security (push) Has been cancelled
68 lines
1.8 KiB
Ruby
68 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::V1::Push::SubscriptionsController < Api::BaseController
|
|
include Redisable
|
|
include Lockable
|
|
|
|
before_action -> { doorkeeper_authorize! :push }
|
|
before_action :require_user!
|
|
before_action :set_push_subscription, only: [:show, :update]
|
|
before_action :check_push_subscription, only: [:show, :update]
|
|
|
|
def show
|
|
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
|
end
|
|
|
|
def create
|
|
with_redis_lock("push_subscription:#{current_user.id}") do
|
|
destroy_web_push_subscriptions!
|
|
|
|
@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
|
|
|
|
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
|
end
|
|
|
|
def update
|
|
@push_subscription.update!(data: data_params)
|
|
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
|
end
|
|
|
|
def destroy
|
|
destroy_web_push_subscriptions!
|
|
render_empty
|
|
end
|
|
|
|
private
|
|
|
|
def destroy_web_push_subscriptions!
|
|
doorkeeper_token.web_push_subscriptions.destroy_all
|
|
end
|
|
|
|
def set_push_subscription
|
|
@push_subscription = doorkeeper_token.web_push_subscriptions.first
|
|
end
|
|
|
|
def check_push_subscription
|
|
not_found if @push_subscription.nil?
|
|
end
|
|
|
|
def subscription_params
|
|
params.expect(subscription: [:endpoint, :standard, keys: [:auth, :p256dh]])
|
|
end
|
|
|
|
def data_params
|
|
return {} if params[:data].blank?
|
|
|
|
params.expect(data: [:policy, alerts: Notification::TYPES])
|
|
end
|
|
end
|