diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-14 21:10:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-14 21:10:34 +0300 |
commit | 7d4b2ed7bf75d316577b718c71a9fdef19184539 (patch) | |
tree | d709e00c4f2ab60901749883f324f9069343037c /app/services/analytics | |
parent | 7172fb10313a9a7790f8e033b347e77df4987154 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/analytics')
-rw-r--r-- | app/services/analytics/cycle_analytics/stages/base_service.rb | 47 | ||||
-rw-r--r-- | app/services/analytics/cycle_analytics/stages/list_service.rb | 27 |
2 files changed, 74 insertions, 0 deletions
diff --git a/app/services/analytics/cycle_analytics/stages/base_service.rb b/app/services/analytics/cycle_analytics/stages/base_service.rb new file mode 100644 index 00000000000..b676eff0a0b --- /dev/null +++ b/app/services/analytics/cycle_analytics/stages/base_service.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Analytics + module CycleAnalytics + module Stages + class BaseService + include Gitlab::Allowable + + DEFAULT_VALUE_STREAM_NAME = 'default' + + def initialize(parent:, current_user:, params: {}) + @parent = parent + @current_user = current_user + @params = params + end + + def execute + raise NotImplementedError + end + + private + + attr_reader :parent, :current_user, :params + + def success(stage, http_status = :created) + ServiceResponse.success(payload: { stage: stage }, http_status: http_status) + end + + def forbidden + ServiceResponse.error(message: 'Forbidden', payload: {}, http_status: :forbidden) + end + + def build_default_stages + Gitlab::Analytics::CycleAnalytics::DefaultStages.all.map do |stage_params| + parent.cycle_analytics_stages.build(stage_params.merge(value_stream: value_stream)) + end + end + + def value_stream + @value_stream ||= params[:value_stream] + end + end + end + end +end + +Analytics::CycleAnalytics::Stages::BaseService.prepend_mod_with('Analytics::CycleAnalytics::Stages::BaseService') diff --git a/app/services/analytics/cycle_analytics/stages/list_service.rb b/app/services/analytics/cycle_analytics/stages/list_service.rb new file mode 100644 index 00000000000..a6b94ef8295 --- /dev/null +++ b/app/services/analytics/cycle_analytics/stages/list_service.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Analytics + module CycleAnalytics + module Stages + class ListService < Analytics::CycleAnalytics::Stages::BaseService + def execute + return forbidden unless allowed? + + success(build_default_stages) + end + + private + + def allowed? + can?(current_user, :read_cycle_analytics, parent) + end + + def success(stages) + ServiceResponse.success(payload: { stages: stages }) + end + end + end + end +end + +Analytics::CycleAnalytics::Stages::ListService.prepend_mod_with('Analytics::CycleAnalytics::Stages::ListService') |