diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 18:09:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 18:09:37 +0300 |
commit | 2c89e169769ead722394a79ed67fcd08e96863dd (patch) | |
tree | 0dadb576846c484475b895f75fab41f71cdb952e /app/controllers/projects/alerting | |
parent | bd497e352ebd279536ae11855871162e82a3f88c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers/projects/alerting')
-rw-r--r-- | app/controllers/projects/alerting/notifications_controller.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/app/controllers/projects/alerting/notifications_controller.rb b/app/controllers/projects/alerting/notifications_controller.rb new file mode 100644 index 00000000000..1fe31863469 --- /dev/null +++ b/app/controllers/projects/alerting/notifications_controller.rb @@ -0,0 +1,47 @@ +# 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) + + head(response_status(result)) + 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 response_status(result) + return :ok if result.success? + + result.http_status + end + + def notification_payload + params.permit![:notification] + end + end + end +end |