2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Projects
|
|
|
|
module Alerting
|
|
|
|
class NotificationsController < Projects::ApplicationController
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
skip_before_action :verify_authenticity_token
|
|
|
|
skip_before_action :project
|
|
|
|
|
|
|
|
prepend_before_action :repository, :project_without_auth
|
|
|
|
|
|
|
|
def create
|
|
|
|
token = extract_alert_manager_token(request)
|
|
|
|
result = notify_service.execute(token)
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
head result.http_status
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project_without_auth
|
|
|
|
@project ||= Project
|
|
|
|
.find_by_full_path("#{params[:namespace_id]}/#{params[:project_id]}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def extract_alert_manager_token(request)
|
|
|
|
Doorkeeper::OAuth::Token.from_bearer_authorization(request)
|
|
|
|
end
|
|
|
|
|
|
|
|
def notify_service
|
|
|
|
Projects::Alerting::NotifyService
|
|
|
|
.new(project, current_user, notification_payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
def notification_payload
|
|
|
|
params.permit![:notification]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|