diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-27 21:07:53 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-27 21:07:53 +0000 |
commit | f50b93c373428d624cc2cabe98e4022dce846e67 (patch) | |
tree | 0349e25d3d106aabd6b520afa96ebd35578ab38b /app | |
parent | e20baee820ea2c76ee16980a98e8080f255d9035 (diff) | |
download | gitlab-ce-f50b93c373428d624cc2cabe98e4022dce846e67.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
4 files changed, 159 insertions, 5 deletions
diff --git a/app/assets/javascripts/clusters/components/ingress_modsecurity_settings.vue b/app/assets/javascripts/clusters/components/ingress_modsecurity_settings.vue index 6b9a926143d..e4bc00fc102 100644 --- a/app/assets/javascripts/clusters/components/ingress_modsecurity_settings.vue +++ b/app/assets/javascripts/clusters/components/ingress_modsecurity_settings.vue @@ -93,7 +93,10 @@ export default { return [UPDATING].includes(this.ingress.status); }, saveButtonDisabled() { - return [UNINSTALLING, UPDATING, INSTALLING].includes(this.ingress.status); + return ( + [UNINSTALLING, UPDATING, INSTALLING].includes(this.ingress.status) || + this.ingress.updateAvailable + ); }, saveButtonLabel() { return this.saving ? __('Saving') : __('Save changes'); @@ -105,13 +108,14 @@ export default { * neither getting installed nor updated. */ showButtons() { - return ( - this.saving || (this.hasValueChanged && [INSTALLED, UPDATED].includes(this.ingress.status)) - ); + return this.saving || this.valuesChangedByUser; }, modSecurityModeName() { return this.modes[this.ingress.modsecurity_mode].name; }, + valuesChangedByUser() { + return this.hasValueChanged && [INSTALLED, UPDATED].includes(this.ingress.status); + }, }, methods: { updateApplication() { diff --git a/app/assets/javascripts/clusters/stores/clusters_store.js b/app/assets/javascripts/clusters/stores/clusters_store.js index d3382fcf9fe..8685e3decc5 100644 --- a/app/assets/javascripts/clusters/stores/clusters_store.js +++ b/app/assets/javascripts/clusters/stores/clusters_store.js @@ -59,6 +59,7 @@ export default class ClusterStore { isEditingModSecurityEnabled: false, isEditingModSecurityMode: false, updateFailed: false, + updateAvailable: false, }, cert_manager: { ...applicationInitialState, @@ -213,6 +214,7 @@ export default class ClusterStore { if (appId === INGRESS) { this.state.applications.ingress.externalIp = serverAppEntry.external_ip; this.state.applications.ingress.externalHostname = serverAppEntry.external_hostname; + this.state.applications.ingress.updateAvailable = updateAvailable; if (!this.state.applications.ingress.isEditingModSecurityEnabled) { this.state.applications.ingress.modsecurity_enabled = serverAppEntry.modsecurity_enabled; } diff --git a/app/controllers/projects/merge_requests/diffs_controller.rb b/app/controllers/projects/merge_requests/diffs_controller.rb index 51128ac1be4..79598c0aaff 100644 --- a/app/controllers/projects/merge_requests/diffs_controller.rb +++ b/app/controllers/projects/merge_requests/diffs_controller.rb @@ -98,7 +98,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic @merge_request.merge_request_diff end - return unless @merge_request_diff + return unless @merge_request_diff&.id @comparable_diffs = @merge_request_diffs.select { |diff| diff.id < @merge_request_diff.id } diff --git a/app/controllers/projects/prometheus/alerts_controller.rb b/app/controllers/projects/prometheus/alerts_controller.rb new file mode 100644 index 00000000000..8c74c730de9 --- /dev/null +++ b/app/controllers/projects/prometheus/alerts_controller.rb @@ -0,0 +1,148 @@ +# frozen_string_literal: true + +module Projects + module Prometheus + class AlertsController < Projects::ApplicationController + include MetricsDashboard + + respond_to :json + + protect_from_forgery except: [:notify] + + skip_before_action :project, only: [:notify] + + prepend_before_action :repository, :project_without_auth, only: [:notify] + + before_action :authorize_read_prometheus_alerts!, except: [:notify] + before_action :alert, only: [:update, :show, :destroy, :metrics_dashboard] + + def index + render json: serialize_as_json(alerts) + end + + def show + render json: serialize_as_json(alert) + end + + def notify + token = extract_alert_manager_token(request) + + if notify_service.execute(token) + head :ok + else + head :unprocessable_entity + end + end + + def create + @alert = create_service.execute + + if @alert.persisted? + schedule_prometheus_update! + + render json: serialize_as_json(@alert) + else + head :no_content + end + end + + def update + if update_service.execute(alert) + schedule_prometheus_update! + + render json: serialize_as_json(alert) + else + head :no_content + end + end + + def destroy + if destroy_service.execute(alert) + schedule_prometheus_update! + + head :ok + else + head :no_content + end + end + + private + + def alerts_params + params.permit(:operator, :threshold, :environment_id, :prometheus_metric_id) + end + + def notify_service + Projects::Prometheus::Alerts::NotifyService + .new(project, current_user, params.permit!) + end + + def create_service + Projects::Prometheus::Alerts::CreateService + .new(project, current_user, alerts_params) + end + + def update_service + Projects::Prometheus::Alerts::UpdateService + .new(project, current_user, alerts_params) + end + + def destroy_service + Projects::Prometheus::Alerts::DestroyService + .new(project, current_user, nil) + end + + def schedule_prometheus_update! + ::Clusters::Applications::ScheduleUpdateService.new(application, project).execute + end + + def serialize_as_json(alert_obj) + serializer.represent(alert_obj) + end + + def serializer + PrometheusAlertSerializer + .new(project: project, current_user: current_user) + end + + def alerts + alerts_finder.execute + end + + def alert + @alert ||= alerts_finder(metric: params[:id]).execute.first || render_404 + end + + def alerts_finder(opts = {}) + Projects::Prometheus::AlertsFinder.new({ + project: project, + environment: params[:environment_id] + }.reverse_merge(opts)) + end + + def application + @application ||= alert.environment.cluster_prometheus_adapter + end + + def extract_alert_manager_token(request) + Doorkeeper::OAuth::Token.from_bearer_authorization(request) + end + + def project_without_auth + @project ||= Project + .find_by_full_path("#{params[:namespace_id]}/#{params[:project_id]}") + end + + def prometheus_alerts + project.prometheus_alerts.for_environment(params[:environment_id]) + end + + def metrics_dashboard_params + { + embedded: true, + prometheus_alert_id: alert.id + } + end + end + end +end |