Class: V0::OnsiteNotificationsController
Constant Summary
collapse
- BEARER_PATTERN =
/^Bearer /
ApplicationController::VERSION_STATUS
ExceptionHandling::SKIP_SENTRY_EXCEPTION_TYPES
Instance Attribute Summary
#current_user
Instance Method Summary
collapse
#clear_saved_form, #cors_preflight, #pagination_params, #render_job_id, #routing_error, #set_csrf_header
Methods included from Traceable
#set_trace_tags
#set_tags_and_extra_context, #tags_context, #user_context
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
#append_info_to_payload
#access_token, #access_token_authenticate, #authenticate, #authenticate_access_token, #bearer_token, #cookie_access_token, #handle_authenticate_error, #load_user, #load_user_object, #scrub_bearer_token, #validate_request_ip
Methods included from Headers
#set_app_info_headers
#render_errors, #report_mapped_exception, #report_original_exception, #skip_sentry_exception?, #skip_sentry_exception_types
#authenticate, #clear_session, #extend_session!, #load_user, #log_sso_info, #render_unauthorized, #reset_session, #set_api_cookie!, #set_current_user, #set_session_expiration_header, #set_session_object, #sign_in_service_exp_time, #sign_in_service_session, #sso_cookie_content, #sso_logging_info, #validate_inbound_login_params, #validate_session
#authenticate, #validate_audience!
Instance Method Details
#authenticate_jwt ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 62
def authenticate_jwt
bearer_token = get_bearer_token
raise authenticity_error if bearer_token.blank?
decoded_token = JWT.decode(bearer_token, public_key, true, { algorithm: 'ES256' })
raise authenticity_error unless token_valid? decoded_token
rescue JWT::DecodeError
raise authenticity_error
end
|
#authenticity_error ⇒ Object
47
48
49
|
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 47
def authenticity_error
Common::Exceptions::Forbidden.new(detail: 'Invalid Authenticity Token')
end
|
77
78
79
80
81
82
83
|
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 77
def
per_page = [:per_page].to_i
params[:per_page] = WillPaginate.per_page if per_page < 1
WillPaginate::PageNumber([:page])
rescue WillPaginate::InvalidPage
params[:page] = 1
end
|
#create ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 35
def create
onsite_notification = OnsiteNotification.new(
params.require(:onsite_notification).permit(:va_profile_id, :template_id)
)
raise Common::Exceptions::ValidationErrors, onsite_notification unless onsite_notification.save
render json: OnsiteNotificationSerializer.new(onsite_notification)
end
|
#get_bearer_token ⇒ Object
51
52
53
54
|
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 51
def get_bearer_token
= request.authorization
.gsub(BEARER_PATTERN, '') if &.match(BEARER_PATTERN)
end
|
#index ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 13
def index
notifications = OnsiteNotification
.for_user(current_user, include_dismissed: params[:include_dismissed])
.paginate(**)
options = { meta: (notifications) }
render json: OnsiteNotificationSerializer.new(notifications, options)
end
|
85
86
87
88
89
90
91
92
93
94
|
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 85
def (notifications)
{
pagination: {
current_page: notifications.current_page.to_i,
per_page: notifications.per_page,
total_pages: notifications.total_pages,
total_entries: notifications.total_entries
}
}
end
|
#public_key ⇒ Object
56
57
58
59
60
|
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 56
def public_key
OpenSSL::PKey::EC.new(
Base64.decode64(Settings.onsite_notifications.public_key)
)
end
|
#token_valid?(token) ⇒ Boolean
73
74
75
|
# File 'app/controllers/v0/onsite_notifications_controller.rb', line 73
def token_valid?(token)
token.first['user'] == 'va_notify' && token.first['iat'].present? && token.first['exp'].present?
end
|