-
Notifications
You must be signed in to change notification settings - Fork 445
Expand file tree
/
Copy pathpushes_controller.rb
More file actions
47 lines (36 loc) · 1.38 KB
/
pushes_controller.rb
File metadata and controls
47 lines (36 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true
class Api::V2::PushesController < Api::V1::PushesController
before_action :force_json_format
before_action :set_push, only: %i[show preview audit destroy notify_by_email]
def notify_by_email
authenticate_user!
if @push.user != current_user
render json: {error: I18n._("That push doesn't belong to you.")}, status: :forbidden
return
end
permitted_notify_by_email_params = params.permit(:recipients, :locale)
assign_notify_by_email_params(@push, permitted_notify_by_email_params, required: true)
if @push.valid?
log_creation_email_send(@push)
render json: {message: "Recipient(s) are added to the queue to be sent."}, status: :created
else
render json: @push.errors, status: :unprocessable_entity
end
end
private
def force_json_format
request.format = :json
end
def push_params
permitted = params.require(:push).permit(:name, :kind, :expire_after_days, :expire_after_views,
:deletable_by_viewer, :retrieval_step, :payload, :note, :passphrase, notify_by_email: [:recipients, :locale], files: [])
# For v2 requests, file uploads imply a file push unless kind is explicit.
if permitted[:kind].blank? && permitted[:files].present?
permitted[:kind] = "file"
end
permitted
rescue => e
Rails.logger.error("Error in push_params: #{e.message}")
raise e
end
end